46 lines
1.8 KiB
C++
46 lines
1.8 KiB
C++
#pragma once
|
|
#include "diagnostics.hpp"
|
|
#include <chrono>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace kpn {
|
|
|
|
// Called when a node's function throws. Return true to skip the failed
|
|
// invocation and keep running, false to stop the node.
|
|
using NodeErrorHandler = std::function<bool(std::string_view node_name, std::exception_ptr)>;
|
|
|
|
// Lightweight timestamp-only callback fired on per-node events.
|
|
// The node name is known at registration time so it is not included here.
|
|
using NodeEventCallback = std::function<void(std::chrono::steady_clock::time_point)>;
|
|
|
|
// Event types reported to the network-level aggregate callback.
|
|
enum class NodeEvent { Overflow, Closed };
|
|
|
|
// ── INode — type-erased interface for Network / watchdog ─────────────────────
|
|
|
|
struct INode {
|
|
virtual ~INode() = default;
|
|
virtual void start() = 0;
|
|
virtual void stop() = 0;
|
|
virtual bool running() const = 0;
|
|
virtual const NodeStats& stats() const = 0;
|
|
virtual NodeSnapshot node_snapshot(const std::string& name, double elapsed_s) const = 0;
|
|
virtual void set_name(std::string name) = 0;
|
|
|
|
// Network-injected callbacks (slot 1 of each node's callback array).
|
|
// Default no-ops; overridden by PoolNode, PoolObjectNode, InterruptNode.
|
|
virtual void set_network_overflow_callback(NodeEventCallback) {}
|
|
virtual void set_network_closed_callback(NodeEventCallback) {}
|
|
|
|
// halt(): alias for stop() — immediate, discards in-flight work.
|
|
virtual void halt() { stop(); }
|
|
|
|
// shutdown(): graceful drain before stopping. Base implementation falls
|
|
// back to stop(). Network and StaticNetwork override with topo-ordered drain.
|
|
virtual void shutdown() { stop(); }
|
|
};
|
|
|
|
} // namespace kpn
|