One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
130 lines
3.0 KiB
C++
130 lines
3.0 KiB
C++
#ifndef SAMPLING_HPP
|
|
#define SAMPLING_HPP
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <exception>
|
|
#include <stdexcept>
|
|
#include <system_error>
|
|
#include <vector>
|
|
namespace sampling {
|
|
enum class Fault {
|
|
None = 0,
|
|
Permission = 1,
|
|
Missing = 2,
|
|
Busy = 3,
|
|
Io = 4,
|
|
Cancel = 5,
|
|
Unexpected = 6
|
|
};
|
|
enum class Status {
|
|
Data = 0,
|
|
Empty = 1,
|
|
DeviceError = 2
|
|
};
|
|
struct Request {
|
|
int device = 0;
|
|
int length = 0;
|
|
int limit = 0;
|
|
int transform = 0;
|
|
Fault open_fault = Fault::None;
|
|
int read_at = 0;
|
|
Fault read_fault = Fault::None;
|
|
int decode_at = 0;
|
|
Fault decode_fault = Fault::None;
|
|
int token = 0;
|
|
};
|
|
struct Sample {
|
|
Status status = Status::Empty;
|
|
int error = 0;
|
|
int first = -1;
|
|
int checksum = 0;
|
|
int count = 0;
|
|
};
|
|
class Cancellation : public std::exception {
|
|
public:
|
|
explicit Cancellation(int token) noexcept;
|
|
int token() const noexcept;
|
|
const char* what() const noexcept override;
|
|
private:
|
|
int token_;
|
|
};
|
|
class Unexpected : public std::runtime_error {
|
|
public:
|
|
explicit Unexpected(int token);
|
|
int token() const noexcept;
|
|
private:
|
|
int token_;
|
|
};
|
|
struct Counters {
|
|
int opens = 0;
|
|
int closes = 0;
|
|
int reads = 0;
|
|
int decodes = 0;
|
|
int errors = 0;
|
|
int active = 0;
|
|
int peak = 0;
|
|
int invalid_close = 0;
|
|
int last_closed = -1;
|
|
};
|
|
struct Event {
|
|
int kind;
|
|
int device;
|
|
int value;
|
|
};
|
|
class DeviceBank {
|
|
public:
|
|
DeviceBank();
|
|
void configure(const Request& request);
|
|
int open(int device);
|
|
int read(int handle);
|
|
int decode(int byte, int index, const Request& request);
|
|
void close(int handle) noexcept;
|
|
const Counters& counters() const noexcept;
|
|
const std::vector<Event>& events() const noexcept;
|
|
std::array<int, 4> busy_devices() const noexcept;
|
|
int source_byte(int index) const noexcept;
|
|
private:
|
|
struct Lease {
|
|
bool live = false;
|
|
int device = -1;
|
|
int offset = 0;
|
|
};
|
|
Request request_;
|
|
std::array<Lease, 64> leases_;
|
|
std::array<int, 4> busy_;
|
|
Counters counters_;
|
|
std::vector<Event> events_;
|
|
int next_handle_;
|
|
Lease& resolve(int handle);
|
|
void inject(Fault fault, int stage);
|
|
void record(int kind, int device, int value);
|
|
};
|
|
class Session {
|
|
public:
|
|
Session(DeviceBank& bank, int device);
|
|
Session(const Session&) = delete;
|
|
Session& operator=(const Session&) = delete;
|
|
~Session() noexcept;
|
|
int read();
|
|
void finish() noexcept;
|
|
bool active() const noexcept;
|
|
private:
|
|
DeviceBank& bank_;
|
|
int handle_;
|
|
};
|
|
struct Accumulator {
|
|
int first = -1;
|
|
int checksum = 0;
|
|
int count = 0;
|
|
void append(int byte) noexcept;
|
|
Sample result() const noexcept;
|
|
};
|
|
Sample collect(DeviceBank& bank, const Request& request);
|
|
Sample dispatch(DeviceBank& bank, const Request& request);
|
|
int device_errno(Fault fault) noexcept;
|
|
int transformed_byte(int value, int transform) noexcept;
|
|
bool valid_request(const Request& request) noexcept;
|
|
}
|
|
#endif
|