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>
62 lines
1.7 KiB
C++
62 lines
1.7 KiB
C++
#include "watch.hpp"
|
|
#include <map>
|
|
namespace watch {
|
|
namespace {
|
|
struct Lease {
|
|
Port& port;
|
|
int fd;
|
|
~Lease() { if (fd >= 0) port.close(fd); }
|
|
int take() { int value = fd; fd = -1; return value; }
|
|
};
|
|
}
|
|
Service::Service(Port& port) : port_(port), current_(-1) {}
|
|
Service::~Service() { stop(); }
|
|
std::vector<Request> Service::normalize(const std::vector<Request>& requests)
|
|
{
|
|
std::map<int, unsigned> latest;
|
|
std::vector<int> order;
|
|
for (const auto& request : requests) {
|
|
if (!latest.count(request.key)) order.push_back(request.key);
|
|
latest[request.key] = request.mask;
|
|
}
|
|
std::vector<Request> result;
|
|
for (int key : order) result.push_back(Request{key, latest.at(key)});
|
|
return result;
|
|
}
|
|
int Service::reload(const std::vector<Request>& requests)
|
|
{
|
|
if (requests.size() > 16) return invalid;
|
|
Lease next{port_, port_.open()};
|
|
if (next.fd < 0) return next.fd;
|
|
for (const auto& request : requests) {
|
|
const int rc = port_.add(next.fd, request.key, request.mask);
|
|
if (rc < 0) return rc;
|
|
}
|
|
const auto normalized = normalize(requests);
|
|
stop();
|
|
current_ = next.take();
|
|
configuration_ = normalized;
|
|
return 0;
|
|
}
|
|
int Service::stop()
|
|
{
|
|
Lease previous{port_, current_};
|
|
current_ = -1;
|
|
configuration_.clear();
|
|
current_watches_.clear();
|
|
return 0;
|
|
}
|
|
int Service::read(std::size_t capacity, std::vector<Event>& output)
|
|
{
|
|
return port_.read(current_, capacity, output);
|
|
}
|
|
int Service::active() const { return current_; }
|
|
std::vector<Request> Service::configuration() const { return configuration_; }
|
|
void Service::forget()
|
|
{
|
|
current_ = -1;
|
|
configuration_.clear();
|
|
current_watches_.clear();
|
|
}
|
|
}
|