amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

224 lines
4.8 KiB
C++

#include "lifecycle.hpp"
namespace station {
Port::Port()
: attempts_(0), next_(100), serial_(0), deliveries_(0), failure_(0)
{
}
void Port::record(int code, int ticket, int owner, int kind, int index, int value)
{
++serial_;
Event event;
event.serial = serial_;
event.code = code;
event.ticket = ticket;
event.owner = owner;
event.kind = kind;
event.index = index;
event.value = value;
events_.push_back(event);
}
int Port::acquire(int owner, int kind, int index)
{
if (owner < 1 || owner > 1000000 || kind < 0 || kind > 1 || index < 0 || index > 5)
{
return -22;
}
if (kind == 0 && index != 0)
{
return -22;
}
++attempts_;
if (failure_ == attempts_)
{
failure_ = 0;
record(4, -1, owner, kind, index, -5);
return -5;
}
const int ticket = next_;
++next_;
Ticket entry;
entry.id = ticket;
entry.owner = owner;
entry.kind = kind;
entry.index = index;
entry.enabled = 0;
entries_.emplace(ticket, entry);
record(1, ticket, owner, kind, index, 0);
return ticket;
}
int Port::release(int ticket)
{
auto found = entries_.find(ticket);
if (found == entries_.end())
{
return -2;
}
const Ticket value = found->second;
record(2, value.id, value.owner, value.kind, value.index, value.enabled);
entries_.erase(found);
return 0;
}
int Port::enable(int ticket, bool enabled)
{
auto found = entries_.find(ticket);
if (found == entries_.end())
{
return -2;
}
Ticket& value = found->second;
if (value.kind != 1)
{
return -22;
}
const int next_value = enabled ? 1 : 0;
if (value.enabled != next_value)
{
value.enabled = next_value;
record(3, value.id, value.owner, value.kind, value.index, next_value);
}
return 0;
}
int Port::publish(int owner, int index, int payload)
{
if (owner < 1 || owner > 1000000 || index < 0 || index > 5 || payload < 0 || payload > 1000000)
{
return -22;
}
for (const auto& pair : entries_)
{
const Ticket& entry = pair.second;
if (entry.owner != owner || entry.kind != 1 || entry.index != index || !entry.enabled)
{
continue;
}
record(5, entry.id, entry.owner, entry.kind, entry.index, payload);
++deliveries_;
return 1;
}
return 0;
}
void Port::terminal(int owner, int prior_state)
{
record(6, -1, owner, -1, -1, prior_state);
}
int Port::inject_failure(int attempt)
{
if (attempt < 0)
{
return -22;
}
failure_ = attempt;
return 0;
}
int Port::statistics(int owner, std::vector<int>& result) const
{
if (owner < 1 || owner > 1000000)
{
return -22;
}
int devices = 0;
int subscriptions = 0;
int enabled = 0;
int acquisitions = 0;
int releases = 0;
int failures = 0;
int deliveries = 0;
for (const auto& pair : entries_)
{
const Ticket& entry = pair.second;
if (entry.owner != owner)
{
continue;
}
if (entry.kind == 0)
{
++devices;
}
else
{
++subscriptions;
enabled += entry.enabled;
}
}
for (const Event& event : events_)
{
if (event.owner != owner)
{
continue;
}
switch (event.code)
{
case 1:
++acquisitions;
break;
case 2:
++releases;
break;
case 4:
++failures;
break;
case 5:
++deliveries;
break;
default:
break;
}
}
result = {devices, subscriptions, enabled, acquisitions, releases, failures, deliveries};
return 0;
}
int Port::history(int owner, int after, std::vector<Event>& result) const
{
if (owner < 0 || owner > 1000000 || after < 0 || after > serial_)
{
return -22;
}
std::vector<Event> selected;
for (const Event& event : events_)
{
if (event.serial <= after)
{
continue;
}
if (owner != 0 && event.owner != owner)
{
continue;
}
selected.push_back(event);
}
result = std::move(selected);
return 0;
}
int Port::attempts() const
{
return attempts_;
}
int Port::next_ticket() const
{
return next_;
}
int Port::serial() const
{
return serial_;
}
int Port::deliveries() const
{
return deliveries_;
}
std::vector<Ticket> Port::entries() const
{
std::vector<Ticket> result;
result.reserve(entries_.size());
for (const auto& pair : entries_)
{
result.push_back(pair.second);
}
return result;
}
const std::vector<Event>& Port::events() const
{
return events_;
}
}