Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
WatchdogService.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include <chrono>
10#include <cstddef>
11#include <cstdint>
12#include <stop_token>
13#include <thread>
14
18
19namespace corium::safety {
20
27template <
28 typename EventVariant = DefaultEvents,
29 std::size_t MaxServices = 16,
30 typename ClockPolicy = ChronoClockPolicy
31>
32class WatchdogService : public BackgroundService<EventVariant> {
33public:
36
37 explicit WatchdogService(std::chrono::milliseconds checkInterval = std::chrono::milliseconds(20))
38 : _checkInterval(checkInterval)
39 {}
40
42 void setWatchdogKickCallback(KickCallbackFn kickFn, void* userData = nullptr) noexcept
43 {
44 _supervisor.setWatchdogKickCallback(kickFn, userData);
45 }
46
48 bool registerService(uint32_t serviceId, uint64_t timeoutNs) noexcept
49 {
50 return _supervisor.registerService(serviceId, timeoutNs);
51 }
52
54 void beat(uint32_t serviceId) noexcept
55 {
56 _supervisor.beat(serviceId);
57 }
58
60 [[nodiscard]] SupervisorType& supervisor() noexcept
61 {
62 return _supervisor;
63 }
64
65 [[nodiscard]] const SupervisorType& supervisor() const noexcept
66 {
67 return _supervisor;
68 }
69
71 void run(const std::stop_token& stopToken)
72 {
73 while (!stopToken.stop_requested()) {
74 std::this_thread::sleep_for(_checkInterval);
75 _supervisor.supervise(this->context().mainSink());
76 }
77 }
78
79private:
80 std::chrono::milliseconds _checkInterval;
81 SupervisorType _supervisor;
82};
83
84} // namespace corium::safety
Managed worker thread using C++20 std::jthread and std::stop_token.
Hardware and simulated clock policies (Chrono, Manual, Tick, EspTimer, FreeRTOS).
Multi-task SLA deadline monitor controlling hardware watchdog refresh.
Multi-threaded background worker service owning a dedicated std::jthread. Integrates incoming event q...
Definition BackgroundService.hpp:35
EventSinkT< EventVariant > mainSink() const noexcept
Get an EventSink handle targeting the main application event queue.
Definition Service.hpp:68
ServiceContextT< EventVariant > & context() noexcept
Definition Service.hpp:118
Multi-threaded background safety service executing periodic heartbeat supervision....
Definition WatchdogService.hpp:32
WatchdogSupervisor< MaxServices, ClockPolicy > SupervisorType
Definition WatchdogService.hpp:34
void setWatchdogKickCallback(KickCallbackFn kickFn, void *userData=nullptr) noexcept
Set callback to refresh the physical hardware watchdog (e.g. STM32 IWDG).
Definition WatchdogService.hpp:42
void beat(uint32_t serviceId) noexcept
Submit a heartbeat for a monitored service.
Definition WatchdogService.hpp:54
WatchdogService(std::chrono::milliseconds checkInterval=std::chrono::milliseconds(20))
Definition WatchdogService.hpp:37
void run(const std::stop_token &stopToken)
Background worker loop executing periodic health supervision.
Definition WatchdogService.hpp:71
SupervisorType & supervisor() noexcept
Access underlying WatchdogSupervisor.
Definition WatchdogService.hpp:60
typename SupervisorType::KickCallbackFn KickCallbackFn
Definition WatchdogService.hpp:35
const SupervisorType & supervisor() const noexcept
Definition WatchdogService.hpp:65
bool registerService(uint32_t serviceId, uint64_t timeoutNs) noexcept
Register a service for supervision with maximum timeout in nanoseconds.
Definition WatchdogService.hpp:48
Dedicated safety supervisor monitoring subsystem heartbeats and controlling watchdog refresh....
Definition WatchdogSupervisor.hpp:31
void beat(uint32_t serviceId) noexcept
Submit a heartbeat for a monitored service.
Definition WatchdogSupervisor.hpp:66
bool supervise(const EventSinkType &sink) noexcept
Perform a supervisor check iteration. Kicks the hardware watchdog if healthy; suppresses the kick and...
Definition WatchdogSupervisor.hpp:77
void(*)(void *userData) KickCallbackFn
Definition WatchdogSupervisor.hpp:33
bool registerService(uint32_t serviceId, uint64_t timeoutNs) noexcept
Register a service for supervision.
Definition WatchdogSupervisor.hpp:59
void setWatchdogKickCallback(KickCallbackFn kickFn, void *userData=nullptr) noexcept
Configure the physical hardware/software watchdog kick callback.
Definition WatchdogSupervisor.hpp:40
Definition CircuitBreaker.hpp:13
std::variant< QuitEvent, TickEvent, UpdateEvent, ErrorEvent, SignalEvent > DefaultEvents
Default variant list of core Corium events.
Definition Events.hpp:62