From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27, 11 canonical families), 38 skipped for scope or duplication. Each task has at least one independent contract-edge defect, boundary types rotate, and public docs state trap clauses as plain contract prose. Claude reviewed 63/63 USABLE against current digests. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#include "input.hpp"
|
|
namespace panel {
|
|
int Service::report(int slot, int type, int code, int value)
|
|
{
|
|
if (!valid_slot(slot)) {
|
|
return -1;
|
|
}
|
|
Slot& target = slots_[static_cast<std::size_t>(slot)];
|
|
if (target.phase != Phase::Registered) {
|
|
return -2;
|
|
}
|
|
std::size_t index = find_index(target, type, code);
|
|
if (index == target.capabilities.size()) {
|
|
return -3;
|
|
}
|
|
const Capability& cap = target.capabilities[index];
|
|
if (cap.type == 1) {
|
|
if (value < 0 || value > 2) {
|
|
return -1;
|
|
}
|
|
} else {
|
|
if (value < cap.lower || value > cap.upper) {
|
|
return -1;
|
|
}
|
|
}
|
|
int current = target.values[index];
|
|
bool append = event_required(cap, current, value);
|
|
if (!append) {
|
|
return 0;
|
|
}
|
|
if (value == 2) {
|
|
for (const auto& old : target.pending) {
|
|
if (old.type == type && old.code == code && old.value == 2) return 0;
|
|
}
|
|
}
|
|
if (target.pending.size() >= 64) {
|
|
return -4;
|
|
}
|
|
Event event{type, code, value};
|
|
target.pending.push_back(event);
|
|
if (cap.type != 1 || value != 2) {
|
|
target.values[index] = value;
|
|
}
|
|
counters_.reports += 1;
|
|
return 0;
|
|
}
|
|
}
|