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>
229 lines
5.9 KiB
C++
229 lines
5.9 KiB
C++
#include "lifecycle.hpp"
|
|
#include <iostream>
|
|
#include <limits>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
std::vector<std::string> words(const std::string& line)
|
|
{
|
|
std::vector<std::string> result;
|
|
std::string token;
|
|
for (char value : line)
|
|
{
|
|
if (value == ' ' || value == '\t' || value == '\r')
|
|
{
|
|
if (!token.empty())
|
|
{
|
|
result.push_back(token);
|
|
token.clear();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
token.push_back(value);
|
|
}
|
|
}
|
|
if (!token.empty())
|
|
{
|
|
result.push_back(token);
|
|
}
|
|
return result;
|
|
}
|
|
bool number(const std::string& text, int& result)
|
|
{
|
|
std::size_t at = 0;
|
|
bool negative = false;
|
|
if (!text.empty() && (text[0] == '+' || text[0] == '-'))
|
|
{
|
|
negative = text[0] == '-';
|
|
++at;
|
|
}
|
|
if (at == text.size())
|
|
{
|
|
return false;
|
|
}
|
|
std::uint64_t value = 0;
|
|
const std::uint64_t limit = negative ? 2147483648ULL : 2147483647ULL;
|
|
for (; at < text.size(); ++at)
|
|
{
|
|
const char digit = text[at];
|
|
if (digit < '0' || digit > '9')
|
|
{
|
|
return false;
|
|
}
|
|
value = value * 10 + static_cast<unsigned>(digit - '0');
|
|
if (value > limit)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
result = negative ? static_cast<int>(-static_cast<std::int64_t>(value)) : static_cast<int>(value);
|
|
return true;
|
|
}
|
|
void print(const std::vector<int>& values)
|
|
{
|
|
std::cout << '[';
|
|
bool first = true;
|
|
for (int value : values)
|
|
{
|
|
if (!first)
|
|
{
|
|
std::cout << ',';
|
|
}
|
|
first = false;
|
|
std::cout << value;
|
|
}
|
|
std::cout << "]\n";
|
|
}
|
|
void print_view(const station::Station& station, int slot)
|
|
{
|
|
station::View value;
|
|
const int status = station.inspect(slot, value);
|
|
if (status != 0)
|
|
{
|
|
print({status});
|
|
return;
|
|
}
|
|
std::vector<int> row{0, value.owner, value.state, value.subscriptions, value.device,
|
|
value.shutdown_calls, value.cleanup_calls};
|
|
row.insert(row.end(), value.tickets.begin(), value.tickets.end());
|
|
print(row);
|
|
}
|
|
void print_port(const station::Port& port)
|
|
{
|
|
const auto entries = port.entries();
|
|
std::vector<int> row{port.attempts(), port.next_ticket(), port.serial(),
|
|
port.deliveries(), static_cast<int>(entries.size())};
|
|
for (const auto& entry : entries)
|
|
{
|
|
row.push_back(entry.id);
|
|
row.push_back(entry.owner);
|
|
row.push_back(entry.kind);
|
|
row.push_back(entry.index);
|
|
row.push_back(entry.enabled);
|
|
}
|
|
print(row);
|
|
}
|
|
void print_events(const station::Port& port)
|
|
{
|
|
const auto& events = port.events();
|
|
std::vector<int> row{static_cast<int>(events.size())};
|
|
for (const auto& event : events)
|
|
{
|
|
row.push_back(event.serial);
|
|
row.push_back(event.code);
|
|
row.push_back(event.ticket);
|
|
row.push_back(event.owner);
|
|
row.push_back(event.kind);
|
|
row.push_back(event.index);
|
|
row.push_back(event.value);
|
|
}
|
|
print(row);
|
|
}
|
|
bool execute(station::Station& station, station::Port& port, const std::vector<std::string>& tokens)
|
|
{
|
|
const std::string& op = tokens[0];
|
|
std::vector<int> args;
|
|
for (std::size_t at = 1; at < tokens.size(); ++at)
|
|
{
|
|
int value;
|
|
if (!number(tokens[at], value))
|
|
{
|
|
return false;
|
|
}
|
|
args.push_back(value);
|
|
}
|
|
int status;
|
|
if (op == "NEW" && args.size() == 3)
|
|
{
|
|
status = station.create(args[0], args[1], args[2]);
|
|
}
|
|
else if (op == "FAIL" && args.size() == 1)
|
|
{
|
|
status = port.inject_failure(args[0]);
|
|
}
|
|
else if (op == "PUBLISH" && args.size() == 3)
|
|
{
|
|
status = port.publish(args[0], args[1], args[2]);
|
|
}
|
|
else if (op == "STATS" && args.size() == 1)
|
|
{
|
|
std::vector<int> values;
|
|
const int rc = port.statistics(args[0], values);
|
|
values.insert(values.begin(), rc);
|
|
print(values);
|
|
return true;
|
|
}
|
|
else if (op == "HISTORY" && args.size() == 2)
|
|
{
|
|
std::vector<station::Event> events;
|
|
const int rc = port.history(args[0], args[1], events);
|
|
std::vector<int> values{rc};
|
|
if (rc == 0)
|
|
{
|
|
values.push_back(static_cast<int>(events.size()));
|
|
for (const auto& event : events)
|
|
{
|
|
values.insert(values.end(), {event.serial, event.code, event.ticket,
|
|
event.owner, event.kind, event.index, event.value});
|
|
}
|
|
}
|
|
print(values);
|
|
return true;
|
|
}
|
|
else if (op == "PORT" && args.empty())
|
|
{
|
|
print_port(port);
|
|
return true;
|
|
}
|
|
else if (op == "EVENTS" && args.empty())
|
|
{
|
|
print_events(port);
|
|
return true;
|
|
}
|
|
else if (op == "VIEW" && args.size() == 1)
|
|
{
|
|
print_view(station, args[0]);
|
|
return true;
|
|
}
|
|
else if (args.size() == 1)
|
|
{
|
|
const int slot = args[0];
|
|
if (op == "CONFIG") status = station.configure(slot);
|
|
else if (op == "ACTIVATE") status = station.activate(slot);
|
|
else if (op == "DEACTIVATE") status = station.deactivate(slot);
|
|
else if (op == "CLEANUP") status = station.cleanup(slot);
|
|
else if (op == "SHUTDOWN") status = station.shutdown(slot);
|
|
else if (op == "STOP") status = station.stop(slot);
|
|
else return false;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
print({status});
|
|
return true;
|
|
}
|
|
}
|
|
int main()
|
|
{
|
|
station::Port port;
|
|
station::Station station(port);
|
|
std::string line;
|
|
while (std::getline(std::cin, line))
|
|
{
|
|
const auto tokens = words(line);
|
|
if (tokens.empty() || tokens[0][0] == '#')
|
|
{
|
|
continue;
|
|
}
|
|
if (!execute(station, port, tokens))
|
|
{
|
|
return 2;
|
|
}
|
|
}
|
|
return std::cin.bad() ? 2 : 0;
|
|
}
|