6#include <nlohmann/json.hpp>
69 std::function<std::optional<nlohmann::json>()>
render;
87 using PublishFn = std::function<void(std::string topic, std::string json)>;
121 void run(std::stop_token stopToken);
124 static std::string envelope(
const nlohmann::json& data);
127 std::chrono::steady_clock::time_point nextDeadline()
const;
130 std::vector<Source> sources_;
131 std::vector<std::uint64_t> lastSeen_;
132 std::vector<std::chrono::steady_clock::time_point> nextDue_;
135 std::jthread thread_;
Polls a fixed set of sources and broadcasts a notification when one of them changes.
Definition notification_bus.h:56
NotificationBus(const NotificationBus &)=delete
NotificationBus(NotificationBus &&)=delete
void setPublish(PublishFn publish)
Sets where finished messages go. Call before start.
Definition notification_bus.cc:17
void start()
Starts the poll thread.
Definition notification_bus.cc:21
~NotificationBus()
Requests the stop and joins.
Definition notification_bus.cc:15
NotificationBus & operator=(const NotificationBus &)=delete
std::function< void(std::string topic, std::string json)> PublishFn
Receives a finished message and the topic to put it on. Wired to WebSocketServer::publish at the root...
Definition notification_bus.h:87
NotificationBus & operator=(NotificationBus &&)=delete
void addSource(Source source)
Registers a source. Call before start.
Definition notification_bus.cc:19
void stop()
Stops the poll thread and joins it. Returns immediately if it is not running, and does not wait out t...
Definition notification_bus.cc:37
Definition bus_health_source.h:7
constexpr std::string_view kNotificationTopic
The one topic every notification is published to.
Definition notification_bus.h:22
One feature's contribution: when to speak, and what to say.
Definition notification_bus.h:59
std::function< std::optional< nlohmann::json >()> render
Definition notification_bus.h:69
std::function< std::uint64_t()> revision
Definition notification_bus.h:62
std::chrono::milliseconds interval
Definition notification_bus.h:81