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>
103 lines
2.5 KiB
C++
103 lines
2.5 KiB
C++
#include "watch.hpp"
|
|
#include <algorithm>
|
|
namespace watch {
|
|
Service::Service(Port& port)
|
|
: port_(port), current_(-1)
|
|
{
|
|
}
|
|
Service::~Service()
|
|
{
|
|
stop();
|
|
}
|
|
std::vector<Request> Service::normalize(const std::vector<Request>& requests)
|
|
{
|
|
std::vector<Request> result;
|
|
for (const Request& request : requests) {
|
|
auto found = std::find_if(result.begin(), result.end(),
|
|
[&request](const Request& item) { return item.key == request.key; });
|
|
if (found == result.end()) {
|
|
result.push_back(request);
|
|
} else {
|
|
found->mask = request.mask;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
void Service::release(int fd, const std::vector<int>& watches)
|
|
{
|
|
for (int wd : watches) {
|
|
port_.remove(fd, wd);
|
|
}
|
|
port_.close(fd);
|
|
}
|
|
int Service::prepare(const std::vector<Request>& requests,
|
|
int& descriptor, std::vector<int>& watches)
|
|
{
|
|
descriptor = port_.open();
|
|
if (descriptor < 0) {
|
|
return descriptor;
|
|
}
|
|
for (const Request& request : requests) {
|
|
const int wd = port_.add(descriptor, request.key, request.mask);
|
|
if (wd < 0) {
|
|
for (int added : watches) {
|
|
port_.remove(descriptor, added);
|
|
}
|
|
port_.close(descriptor);
|
|
return wd;
|
|
}
|
|
if (std::find(watches.begin(), watches.end(), wd) == watches.end()) {
|
|
watches.push_back(wd);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
int Service::reload(const std::vector<Request>& requests)
|
|
{
|
|
if (requests.size() > 16) {
|
|
return invalid;
|
|
}
|
|
int prepared = -1;
|
|
std::vector<int> prepared_watches;
|
|
const int status = prepare(requests, prepared, prepared_watches);
|
|
if (status < 0) {
|
|
return status;
|
|
}
|
|
if (current_ >= 0) {
|
|
release(current_, current_watches_);
|
|
}
|
|
current_ = prepared;
|
|
current_watches_.swap(prepared_watches);
|
|
configuration_ = normalize(requests);
|
|
return 0;
|
|
}
|
|
int Service::stop()
|
|
{
|
|
if (current_ >= 0) {
|
|
port_.close(current_);
|
|
}
|
|
current_ = -1;
|
|
current_watches_.clear();
|
|
configuration_.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;
|
|
current_watches_.clear();
|
|
configuration_.clear();
|
|
}
|
|
}
|