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

243 lines
4.4 KiB
C++

#include "lifecycle.hpp"
namespace station {
Node::Node(Port& port, int owner, int subscriptions)
: port_(port), owner_(owner), subscriptions_(subscriptions), state_(0),
device_(-1), shutdown_calls_(0), cleanup_calls_(0), tickets_(subscriptions, -1)
{
}
int Node::owner() const
{
return owner_;
}
View Node::view() const
{
View result;
result.owner = owner_;
result.state = state_;
result.subscriptions = subscriptions_;
result.device = device_;
result.shutdown_calls = shutdown_calls_;
result.cleanup_calls = cleanup_calls_;
result.tickets = tickets_;
return result;
}
int Node::configure()
{
if (state_ != 0)
{
return -16;
}
device_ = port_.acquire(owner_, 0, 0);
if (device_ < 0)
{
device_ = -1;
return -5;
}
for (int index = 0; index < subscriptions_; ++index)
{
const int ticket = port_.acquire(owner_, 1, index);
if (ticket < 0)
{
release_subscriptions();
release_device();
return -5;
}
tickets_[index] = ticket;
}
state_ = 1;
return 0;
}
int Node::activate()
{
if (state_ != 1)
{
return -16;
}
for (int ticket : tickets_)
{
port_.enable(ticket, true);
}
state_ = 2;
return 0;
}
int Node::deactivate()
{
if (state_ != 2)
{
return -16;
}
disable_subscriptions();
state_ = 1;
return 0;
}
void Node::release_subscriptions()
{
for (auto at = tickets_.rbegin(); at != tickets_.rend(); ++at)
{
if (*at >= 0)
{
port_.release(*at);
*at = -1;
}
}
}
void Node::release_device()
{
if (device_ >= 0)
{
port_.release(device_);
device_ = -1;
}
}
void Node::disable_subscriptions()
{
for (int ticket : tickets_)
{
if (ticket >= 0)
{
port_.enable(ticket, false);
}
}
}
int Node::cleanup()
{
if (state_ != 1)
{
return -16;
}
release_subscriptions();
release_device();
++cleanup_calls_;
state_ = 0;
return 0;
}
void Node::terminal_callback()
{
++shutdown_calls_;
port_.terminal(owner_, state_);
disable_subscriptions();
if (state_ == 2)
{
release_subscriptions();
}
release_device();
}
int Node::shutdown()
{
if (state_ == 3)
{
return 0;
}
terminal_callback();
state_ = 3;
return 0;
}
Station::Station(Port& port)
: port_(port)
{
}
bool Station::valid_slot(int slot) const
{
return slot >= 0 && slot < static_cast<int>(nodes_.size());
}
int Station::locate(int slot) const
{
if (!valid_slot(slot))
{
return -22;
}
if (!nodes_[slot])
{
return -2;
}
return 0;
}
int Station::create(int slot, int owner, int subscriptions)
{
if (!valid_slot(slot) || owner < 1 || owner > 1000000 || subscriptions < 0 || subscriptions > 6)
{
return -22;
}
if (nodes_[slot])
{
return -17;
}
for (const auto& node : nodes_)
{
if (node && node->owner() == owner)
{
return -17;
}
}
nodes_[slot] = std::make_unique<Node>(port_, owner, subscriptions);
return 0;
}
int Station::configure(int slot)
{
const int status = locate(slot);
if (status != 0)
{
return status;
}
return nodes_[slot]->configure();
}
int Station::activate(int slot)
{
const int status = locate(slot);
if (status != 0)
{
return status;
}
return nodes_[slot]->activate();
}
int Station::deactivate(int slot)
{
const int status = locate(slot);
if (status != 0)
{
return status;
}
return nodes_[slot]->deactivate();
}
int Station::cleanup(int slot)
{
const int status = locate(slot);
if (status != 0)
{
return status;
}
return nodes_[slot]->cleanup();
}
int Station::shutdown(int slot)
{
const int status = locate(slot);
if (status != 0)
{
return status;
}
return nodes_[slot]->shutdown();
}
int Station::stop(int slot)
{
const int status = locate(slot);
if (status != 0)
{
return status;
}
nodes_[slot]->shutdown();
nodes_[slot].reset();
return 0;
}
int Station::inspect(int slot, View& result) const
{
const int status = locate(slot);
if (status != 0)
{
return status;
}
result = nodes_[slot]->view();
return 0;
}
}