Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy > Class Template Reference

Multi-threaded background safety service executing periodic heartbeat supervision. Automatically verifies monitored task deadlines and dispatches WatchdogTimeoutEvent to the main event bus on violations. More...

#include <WatchdogService.hpp>

+ Inheritance diagram for corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >:
+ Collaboration diagram for corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >:

Public Types

using Base = Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >
 
using EventVariant = typename Base::EventVariant
 
using IncomingBus = BasicEventBus< EventVariant, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >
 
using KickCallbackFn = typename SupervisorType::KickCallbackFn
 
using SupervisorType = WatchdogSupervisor< MaxServices, ClockPolicy >
 

Public Member Functions

void beat (uint32_t serviceId) noexcept
 Submit a heartbeat for a monitored service.
 
void join () noexcept
 Join background std::jthread cleanly.
 
EventSinkT< EventVariantmainSink () const noexcept
 Get an EventSink handle targeting the main application event queue.
 
template<typename Handler >
bool on (Handler &&handler)
 Register an event handler for incoming events with automatic event type deduction.
 
bool processOne ()
 Process a single incoming event from the service queue.
 
std::size_t pump ()
 Pump all pending incoming events from the queue until empty.
 
std::size_t pump (std::size_t maxEvents)
 Pump up to maxEvents pending incoming events from the queue.
 
template<typename EventType , typename Handler >
bool registerHandler (Handler &&handler)
 Register an event handler for incoming events with explicit event type parameter.
 
bool registerService (uint32_t serviceId, uint64_t timeoutNs) noexcept
 Register a service for supervision with maximum timeout in nanoseconds.
 
void run (const std::stop_token &stopToken)
 Background worker loop executing periodic health supervision.
 
void setContext (ServiceContextT< EventVariant > context) noexcept
 
void setWatchdogKickCallback (KickCallbackFn kickFn, void *userData=nullptr) noexcept
 Set callback to refresh the physical hardware watchdog (e.g. STM32 IWDG).
 
EventSinkT< EventVariantsink () noexcept
 Get an EventSink handle targeting this service's incoming event queue.
 
template<typename Derived >
void startThread (Derived *derived)
 Start execution loop on dedicated std::jthread.
 
void stop () noexcept
 Request cancellation on worker std::jthread.
 
const SupervisorTypesupervisor () const noexcept
 
SupervisorTypesupervisor () noexcept
 Access underlying WatchdogSupervisor.
 
template<typename Rep , typename Period >
std::size_t waitAndPump (const std::stop_token &stopToken, const std::chrono::duration< Rep, Period > &timeout)
 Wait for incoming events or timeout, then pump all available incoming events. Safe for use inside worker thread run(std::stop_token).
 
 WatchdogService (std::chrono::milliseconds checkInterval=std::chrono::milliseconds(20))
 

Protected Member Functions

const ServiceContextT< EventVariant > & context () const noexcept
 
ServiceContextT< EventVariant > & context () noexcept
 
const IncomingBusincomingBus () const noexcept
 
IncomingBusincomingBus () noexcept
 
template<typename EventType >
void post (EventType &&event, EventPriority priority=EventPriority::Normal) const
 Post an event into the main application event queue.
 
template<typename EventType >
void postHighPriority (EventType &&event) const
 Post a high-priority event into the main application event queue.
 
template<typename TargetService , typename EventType >
bool sendToService (EventType &&event, EventPriority priority=EventPriority::Normal) const
 Post an event directly to another registered service.
 

Detailed Description

template<typename EventVariant = DefaultEvents, std::size_t MaxServices = 16, typename ClockPolicy = ChronoClockPolicy>
class corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >

Multi-threaded background safety service executing periodic heartbeat supervision. Automatically verifies monitored task deadlines and dispatches WatchdogTimeoutEvent to the main event bus on violations.

Template Parameters
EventVariantSupported event variant list type.
MaxServicesMaximum number of monitored services (default 16).
ClockPolicyClock source strategy (defaults to ChronoClockPolicy).

Member Typedef Documentation

◆ Base

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
using corium::BackgroundService< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::Base = Service<EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy>
inherited

◆ EventVariant

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
using corium::BackgroundService< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::EventVariant = typename Base::EventVariant
inherited

◆ IncomingBus

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
using corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::IncomingBus = BasicEventBus<EventVariant, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy>
inherited

◆ KickCallbackFn

template<typename EventVariant = DefaultEvents, std::size_t MaxServices = 16, typename ClockPolicy = ChronoClockPolicy>
using corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >::KickCallbackFn = typename SupervisorType::KickCallbackFn

◆ SupervisorType

template<typename EventVariant = DefaultEvents, std::size_t MaxServices = 16, typename ClockPolicy = ChronoClockPolicy>
using corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >::SupervisorType = WatchdogSupervisor<MaxServices, ClockPolicy>

Constructor & Destructor Documentation

◆ WatchdogService()

template<typename EventVariant = DefaultEvents, std::size_t MaxServices = 16, typename ClockPolicy = ChronoClockPolicy>
corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >::WatchdogService ( std::chrono::milliseconds  checkInterval = std::chrono::milliseconds(20))
inlineexplicit

Member Function Documentation

◆ beat()

template<typename EventVariant = DefaultEvents, std::size_t MaxServices = 16, typename ClockPolicy = ChronoClockPolicy>
void corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >::beat ( uint32_t  serviceId)
inlinenoexcept

Submit a heartbeat for a monitored service.

+ Here is the call graph for this function:

◆ context() [1/2]

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
const ServiceContextT< EventVariant > & corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::context ( ) const
inlineprotectednoexceptinherited

◆ context() [2/2]

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
ServiceContextT< EventVariant > & corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::context ( )
inlineprotectednoexceptinherited
+ Here is the caller graph for this function:

◆ incomingBus() [1/2]

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
const IncomingBus & corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::incomingBus ( ) const
inlineprotectednoexceptinherited

◆ incomingBus() [2/2]

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
IncomingBus & corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::incomingBus ( )
inlineprotectednoexceptinherited
+ Here is the caller graph for this function:

◆ join()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
void corium::BackgroundService< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::join ( )
inlinenoexceptinherited

Join background std::jthread cleanly.

+ Here is the caller graph for this function:

◆ mainSink()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
EventSinkT< EventVariant > corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::mainSink ( ) const
inlinenoexceptinherited

Get an EventSink handle targeting the main application event queue.

+ Here is the caller graph for this function:

◆ on()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
template<typename Handler >
bool corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::on ( Handler &&  handler)
inlineinherited

Register an event handler for incoming events with automatic event type deduction.

+ Here is the call graph for this function:

◆ post()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
template<typename EventType >
void corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::post ( EventType &&  event,
EventPriority  priority = EventPriority::Normal 
) const
inlineprotectedinherited

Post an event into the main application event queue.

◆ postHighPriority()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
template<typename EventType >
void corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::postHighPriority ( EventType &&  event) const
inlineprotectedinherited

Post a high-priority event into the main application event queue.

+ Here is the caller graph for this function:

◆ processOne()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
bool corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::processOne ( )
inlineinherited

Process a single incoming event from the service queue.

Returns
true if an event was popped and dispatched; false if queue was empty.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pump() [1/2]

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
std::size_t corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::pump ( )
inlineinherited

Pump all pending incoming events from the queue until empty.

Returns
Number of events processed.
+ Here is the call graph for this function:

◆ pump() [2/2]

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
std::size_t corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::pump ( std::size_t  maxEvents)
inlineinherited

Pump up to maxEvents pending incoming events from the queue.

Parameters
maxEventsMaximum number of events to process.
Returns
Number of events processed.
+ Here is the call graph for this function:

◆ registerHandler()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
template<typename EventType , typename Handler >
bool corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::registerHandler ( Handler &&  handler)
inlineinherited

Register an event handler for incoming events with explicit event type parameter.

◆ registerService()

template<typename EventVariant = DefaultEvents, std::size_t MaxServices = 16, typename ClockPolicy = ChronoClockPolicy>
bool corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >::registerService ( uint32_t  serviceId,
uint64_t  timeoutNs 
)
inlinenoexcept

Register a service for supervision with maximum timeout in nanoseconds.

+ Here is the call graph for this function:

◆ run()

template<typename EventVariant = DefaultEvents, std::size_t MaxServices = 16, typename ClockPolicy = ChronoClockPolicy>
void corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >::run ( const std::stop_token &  stopToken)
inline

Background worker loop executing periodic health supervision.

+ Here is the call graph for this function:

◆ sendToService()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
template<typename TargetService , typename EventType >
bool corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::sendToService ( EventType &&  event,
EventPriority  priority = EventPriority::Normal 
) const
inlineprotectedinherited

Post an event directly to another registered service.

◆ setContext()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
void corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::setContext ( ServiceContextT< EventVariant context)
inlinenoexceptinherited
+ Here is the call graph for this function:

◆ setWatchdogKickCallback()

template<typename EventVariant = DefaultEvents, std::size_t MaxServices = 16, typename ClockPolicy = ChronoClockPolicy>
void corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >::setWatchdogKickCallback ( KickCallbackFn  kickFn,
void *  userData = nullptr 
)
inlinenoexcept

Set callback to refresh the physical hardware watchdog (e.g. STM32 IWDG).

+ Here is the call graph for this function:

◆ sink()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
EventSinkT< EventVariant > corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::sink ( )
inlinenoexceptinherited

Get an EventSink handle targeting this service's incoming event queue.

+ Here is the call graph for this function:

◆ startThread()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
template<typename Derived >
void corium::BackgroundService< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::startThread ( Derived *  derived)
inlineinherited

Start execution loop on dedicated std::jthread.

+ Here is the call graph for this function:

◆ stop()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
void corium::BackgroundService< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::stop ( )
inlinenoexceptinherited

Request cancellation on worker std::jthread.

+ Here is the caller graph for this function:

◆ supervisor() [1/2]

template<typename EventVariant = DefaultEvents, std::size_t MaxServices = 16, typename ClockPolicy = ChronoClockPolicy>
const SupervisorType & corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >::supervisor ( ) const
inlinenoexcept

◆ supervisor() [2/2]

template<typename EventVariant = DefaultEvents, std::size_t MaxServices = 16, typename ClockPolicy = ChronoClockPolicy>
SupervisorType & corium::safety::WatchdogService< EventVariant, MaxServices, ClockPolicy >::supervisor ( )
inlinenoexcept

Access underlying WatchdogSupervisor.

◆ waitAndPump()

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
template<typename Rep , typename Period >
std::size_t corium::BackgroundService< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::waitAndPump ( const std::stop_token &  stopToken,
const std::chrono::duration< Rep, Period > &  timeout 
)
inlineinherited

Wait for incoming events or timeout, then pump all available incoming events. Safe for use inside worker thread run(std::stop_token).

Template Parameters
RepDuration representation type.
PeriodDuration period type.
Parameters
stopTokenstd::stop_token from run(stopToken).
timeoutMaximum duration to wait if queue is empty.
Returns
Number of events processed.
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: