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>
109 lines
3.5 KiB
C++
109 lines
3.5 KiB
C++
#include "lifecycle.hpp"
|
|
namespace replay {
|
|
Node::Node(int owner):owner_(owner) {}
|
|
std::int64_t Node::initial_checksum(const Profile& p) const {
|
|
const std::array<int,4> value{{p.seed,p.rate,p.channels,p.recorder}};
|
|
const std::array<int,4> factor{{31,7,101,13}};
|
|
std::int64_t sum=0;
|
|
for (std::size_t i=0;i<value.size();++i) sum+=value[i]*factor[i];
|
|
return sum%65521;
|
|
}
|
|
void Node::rollback(DevicePort& port,std::vector<int>& ledger,int) {
|
|
while (!ledger.empty()) {
|
|
port.close(owner_,ledger.back());
|
|
ledger.pop_back();
|
|
}
|
|
}
|
|
Callback Node::on_configure(DevicePort& port,const Profile& p) {
|
|
NodeView next=data_;
|
|
std::vector<int> ledger;
|
|
bool complete=true;
|
|
port.begin_attempt(p.fail_at);
|
|
const int needed=p.channels+p.recorder;
|
|
for (int stage=0;stage<=needed && complete;++stage) {
|
|
if (stage==needed) {
|
|
complete=port.prime();
|
|
} else {
|
|
int handle=port.open(owner_,stage<p.channels?stage:10);
|
|
complete=handle>=0;
|
|
if (complete) ledger.push_back(handle);
|
|
}
|
|
}
|
|
if (!complete) {
|
|
rollback(port,ledger,-1);
|
|
return Callback::Failure;
|
|
}
|
|
next.channels.assign(ledger.begin(),ledger.begin()+p.channels);
|
|
next.recorder=p.recorder?ledger.back():-1;
|
|
next.profile=p;
|
|
next.samples=0;
|
|
next.total=0;
|
|
next.checksum=initial_checksum(p);
|
|
next.ready=true;
|
|
data_=std::move(next);
|
|
return Callback::Success;
|
|
}
|
|
Result Node::configure(DevicePort& port,const Profile& p) {
|
|
Result rc=Result::BadState;
|
|
if (data_.state==State::Unconfigured) {
|
|
rc=Result::InvalidProfile;
|
|
if (p.valid()) {
|
|
const bool accepted=on_configure(port,p)==Callback::Success;
|
|
if (accepted) {
|
|
data_.state=State::Inactive;
|
|
data_.generation+=1;
|
|
data_.configured+=1;
|
|
rc=Result::Ok;
|
|
} else {
|
|
data_.rejected+=1;
|
|
rc=Result::Rejected;
|
|
}
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
Result Node::activate() {
|
|
bool allowed=data_.ready && data_.state==State::Inactive;
|
|
if (allowed) data_.state=State::Active;
|
|
return allowed?Result::Ok:Result::BadState;
|
|
}
|
|
Result Node::deactivate() {
|
|
bool allowed=data_.state==State::Active;
|
|
if (allowed) data_.state=State::Inactive;
|
|
return allowed?Result::Ok:Result::BadState;
|
|
}
|
|
void Node::clear_configuration() {
|
|
NodeView empty;
|
|
empty.generation=data_.generation;
|
|
empty.configured=data_.configured;
|
|
empty.rejected=data_.rejected;
|
|
data_=std::move(empty);
|
|
}
|
|
Result Node::cleanup(DevicePort& port) {
|
|
if (data_.state!=State::Inactive) return Result::BadState;
|
|
std::vector<int> ledger=data_.channels;
|
|
if (data_.recorder>=0) ledger.push_back(data_.recorder);
|
|
rollback(port,ledger,-1);
|
|
clear_configuration();
|
|
return Result::Ok;
|
|
}
|
|
Result Node::tick(DevicePort& port,int value) {
|
|
if (!(data_.ready && data_.state==State::Active)) return Result::BadState;
|
|
std::vector<std::int64_t> readings;
|
|
for (std::size_t i=0;i<data_.channels.size();++i) {
|
|
readings.push_back(port.read(owner_,data_.channels[i],static_cast<int>(i),value,data_.profile));
|
|
}
|
|
std::int64_t sum=0;
|
|
for (std::int64_t reading:readings) sum+=reading;
|
|
data_.samples+=1;
|
|
data_.total+=sum;
|
|
data_.checksum=((data_.checksum*33+sum)%65521+65521)%65521;
|
|
if (data_.profile.recorder) port.write(owner_,data_.recorder,sum);
|
|
return Result::Ok;
|
|
}
|
|
NodeView Node::view() const {
|
|
NodeView copy=data_;
|
|
return copy;
|
|
}
|
|
}
|