#ifndef PROBE_HPP #define PROBE_HPP #include #include #include namespace probe { constexpr int DeviceLimit = 32; constexpr std::int64_t ClockLimit = 1000000; constexpr int EvidenceLimit = 65535; constexpr int LifetimeLimit = 1000; enum Code { Offline = 0, Ready = 1, Busy = 2, Fault = 3 }; enum Verdict { Missing = -1, Unavailable = 0, Accepted = 1, Occupied = 2, Broken = 3, EvidenceMismatch = 4, Expired = 5, Invalid = 6 }; struct Query { int id = 0; int strict = 0; int evidence = 0; }; struct Record { int id = 0; int code = Offline; int evidence = 0; std::int64_t stamp = 0; int lifetime = 0; int revision = 0; int checks = 0; int accepted = 0; int rejected = 0; int last = Missing; }; struct Snapshot { bool exists = false; Record record; }; struct Totals { int live = 0; int offline = 0; int ready = 0; int busy = 0; int fault = 0; int fresh = 0; int checks = 0; int accepted = 0; int rejected = 0; int revisions = 0; std::int64_t fingerprint = 0; }; bool valid_id(int id); bool valid_code(int code); bool valid_evidence(int evidence); bool valid_lifetime(int lifetime); bool valid_query(const Query& query); bool is_fresh(const Record& record, std::int64_t now); int classify(Record& record); bool evidence_matches(Query& query, const Record& record); int decide(Record& record, Query& query, std::int64_t now); std::vector snapshot_fields(const Snapshot& snapshot); std::vector total_fields(const Totals& totals); std::int64_t record_fingerprint(const Record& record); class Registry { public: explicit Registry(std::int64_t initial = 0); bool reset(std::int64_t initial); bool set(int id, int code, int evidence, int lifetime); bool advance(std::int64_t amount); bool drop(int id); int ask(Query& query); Snapshot view(int id) const; Totals totals() const; std::int64_t now() const; std::vector ids() const; std::vector snapshots() const; private: std::array records_; std::array present_; std::int64_t now_; Record* find(int id); const Record* find(int id) const; void account(Record& record, int verdict); }; } #endif