Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy > Class Template Reference

Non-allocating base class for synchronous or thread-agnostic services. Provides event producing (posting to main EventBus) and event consuming (receiving events into dedicated incoming bus). Does NOT own a thread. Zero heap allocations, zero vtables/RTTI. More...

#include <Service.hpp>

+ Inheritance diagram for corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >:
+ Collaboration diagram for corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >:

Public Types

using EventVariant = EventVariantType
 
using IncomingBus = BasicEventBus< EventVariant, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >
 

Public Member Functions

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.
 
Serviceoperator= (const Service &)=delete
 
Serviceoperator= (Service &&) noexcept=default
 
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.
 
 Service ()=default
 
 Service (const Service &)=delete
 
 Service (Service &&) noexcept=default
 
 Service (ServiceContextT< EventVariant > context)
 
void setContext (ServiceContextT< EventVariant > context) noexcept
 
EventSinkT< EventVariantsink () noexcept
 Get an EventSink handle targeting this service's incoming event queue.
 
 ~Service ()=default
 

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 EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
class corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >

Non-allocating base class for synchronous or thread-agnostic services. Provides event producing (posting to main EventBus) and event consuming (receiving events into dedicated incoming bus). Does NOT own a thread. Zero heap allocations, zero vtables/RTTI.

Template Parameters
EventVariantTypeSupported event variant type list.
QueuePolicyStrategy for queueing incoming events (bounded lock-free MPSC).
SignalPolicyStrategy for signaling (CallbackSignalPolicy default).
StoragePolicyStrategy for compile-time handler capacity and delegate storage.
OverflowPolicyStrategy for queue overflow handling.

Member Typedef Documentation

◆ EventVariant

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 >::EventVariant = EventVariantType

◆ 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>

Constructor & Destructor Documentation

◆ Service() [1/4]

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

◆ Service() [2/4]

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

◆ ~Service()

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

◆ Service() [3/4]

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

◆ Service() [4/4]

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

Member Function Documentation

◆ 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
inlineprotectednoexcept

◆ 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 ( )
inlineprotectednoexcept
+ 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
inlineprotectednoexcept

◆ 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 ( )
inlineprotectednoexcept
+ 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
inlinenoexcept

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)
inline

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

+ Here is the call graph for this function:

◆ operator=() [1/2]

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

◆ operator=() [2/2]

template<typename EventVariantType = DefaultEvents, typename QueuePolicy = BoundedMpscQueuePolicy<EventVariantType, 1024>, typename SignalPolicy = CallbackSignalPolicy, typename StoragePolicy = DefaultStoragePolicy, typename OverflowPolicy = DropNewestOverflowPolicy>
Service & corium::Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy >::operator= ( Service< EventVariantType, QueuePolicy, SignalPolicy, StoragePolicy, OverflowPolicy > &&  )
defaultnoexcept

◆ 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
inlineprotected

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
inlineprotected

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 ( )
inline

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 ( )
inline

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)
inline

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)
inline

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

◆ 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
inlineprotected

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)
inlinenoexcept
+ 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 ( )
inlinenoexcept

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

+ Here is the call graph for this function:

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