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>
86 lines
2.2 KiB
C++
86 lines
2.2 KiB
C++
#ifndef PANEL_INPUT_HPP
|
|
#define PANEL_INPUT_HPP
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
namespace panel {
|
|
enum class Phase {
|
|
Empty = 0,
|
|
Allocated = 1,
|
|
Registered = 2
|
|
};
|
|
struct Capability {
|
|
int type;
|
|
int code;
|
|
int lower;
|
|
int upper;
|
|
};
|
|
struct Event {
|
|
int type;
|
|
int code;
|
|
int value;
|
|
};
|
|
struct Frame {
|
|
std::uint64_t serial;
|
|
int slot;
|
|
std::uint64_t generation;
|
|
std::vector<Event> events;
|
|
};
|
|
struct Slot {
|
|
Phase phase = Phase::Empty;
|
|
std::uint64_t generation = 0;
|
|
std::string name;
|
|
std::vector<Capability> capabilities;
|
|
std::vector<int> values;
|
|
std::vector<Event> pending;
|
|
};
|
|
struct Counters {
|
|
std::uint64_t allocations = 0;
|
|
std::uint64_t releases = 0;
|
|
std::uint64_t configurations = 0;
|
|
std::uint64_t registrations = 0;
|
|
std::uint64_t unregistrations = 0;
|
|
std::uint64_t reports = 0;
|
|
std::uint64_t frames = 0;
|
|
std::uint64_t committed_events = 0;
|
|
};
|
|
struct Reading {
|
|
int rc;
|
|
int value;
|
|
};
|
|
bool valid_slot(int slot);
|
|
bool valid_name(const std::string& name);
|
|
bool capability_valid(const Capability& cap);
|
|
int normalize_capabilities(const std::vector<Capability>& input,
|
|
std::vector<Capability>& output);
|
|
class Service {
|
|
public:
|
|
Service();
|
|
void reset();
|
|
int allocate(int slot, const std::string& name);
|
|
int replace_capabilities(int slot, const std::vector<Capability>& caps);
|
|
int attach(int slot, int fail);
|
|
int detach(int slot);
|
|
int release(int slot);
|
|
int report(int slot, int type, int code, int value);
|
|
int sync(int slot);
|
|
Reading read(int slot, int type, int code) const;
|
|
const Capability* capability(int slot, int type, int code) const;
|
|
const Slot* inspect(int slot) const;
|
|
const std::array<Slot, 4>& slots() const;
|
|
const std::vector<Frame>& ledger() const;
|
|
const Counters& counters() const;
|
|
private:
|
|
std::array<Slot, 4> slots_;
|
|
std::vector<Frame> ledger_;
|
|
Counters counters_;
|
|
std::size_t find_index(const Slot& slot, int type, int code) const;
|
|
bool event_required(const Capability& cap, int current, int incoming) const;
|
|
void clear_live(Slot& slot);
|
|
void publish(int slot);
|
|
};
|
|
}
|
|
#endif
|