Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
TimeoutQueue::Event Class Referenceabstract

Base class for scheduled events. More...

#include <timeoutQueue.H>

Inheritance diagram for TimeoutQueue::Event:
[legend]
Collaboration diagram for TimeoutQueue::Event:
[legend]

Public Types

enum  Execution_Status {
  Out_Queue , In_Queue , Canceled , Executing ,
  Executed , To_Delete , Deleted
}
 Possible states of an event in its lifecycle. More...
 
using CompletionCallback = std::function< void(Event *, Execution_Status)>
 Optional callback invoked after an event completes, is canceled, or is deleted.
 
using EventId = uint64_t
 Type for unique event identifiers.
 

Public Member Functions

 ~Event () noexcept override
 
Execution_Status get_execution_status () const
 
Time getAbsoluteTime () const
 
void set_for_deletion ()
 
EventId get_id () const
 Get the unique event ID (auto-generated on construction)
 
const std::string & get_name () const
 Get the event name (for debugging)
 
void set_name (const std::string &name)
 Set the event name.
 
void set_completion_callback (CompletionCallback cb)
 Set the completion callback (called after EventFct completes or the event is canceled)
 
virtual void EventFct ()=0
 Event handler function to be overridden.
 

Static Public Attributes

static constexpr EventId InvalidId = 0
 Invalid/null event ID.
 

Protected Member Functions

 Event (const Time &t, std::string name="")
 
 Event (const long sec, const long nsec, std::string name="")
 

Private Member Functions

Timetime_key ()
 
const Timetime_key () const
 
void set_trigger_time (const Time _t)
 
void set_execution_status (Execution_Status status)
 
void invoke_completion_callback ()
 

Private Attributes

EventId event_id
 
std::atomic< Execution_Statusexecution_status
 
std::string event_name
 
CompletionCallback on_completed
 

Static Private Attributes

static std::atomic< EventIdnextId {0}
 

Friends

class TimeoutQueue
 

Detailed Description

Base class for scheduled events.

Derive from this class and override EventFct() to create custom events that can be scheduled in the TimeoutQueue. *

Definition at line 152 of file timeoutQueue.H.

Member Typedef Documentation

◆ CompletionCallback

Optional callback invoked after an event completes, is canceled, or is deleted.

Note
When the callback receives Deleted status, the event has already been destroyed by the queue and the pointer parameter is nullptr. The callback must not attempt to dereference it.

Definition at line 179 of file timeoutQueue.H.

◆ EventId

Type for unique event identifiers.

Definition at line 182 of file timeoutQueue.H.

Member Enumeration Documentation

◆ Execution_Status

Possible states of an event in its lifecycle.

Enumerator
Out_Queue 

Not currently in any queue.

In_Queue 

Scheduled and waiting for trigger time.

Canceled 

Removed from queue before execution.

Executing 

Currently executing EventFct()

Executed 

Completed execution.

To_Delete 

Marked for cleanup.

Deleted 

Memory freed.

Definition at line 162 of file timeoutQueue.H.

Constructor & Destructor Documentation

◆ Event() [1/2]

TimeoutQueue::Event::Event ( const Time t,
std::string  name = "" 
)
inlineprotected

Definition at line 216 of file timeoutQueue.H.

References Aleph::maps(), NSEC, and time_key().

◆ Event() [2/2]

TimeoutQueue::Event::Event ( const long  sec,
const long  nsec,
std::string  name = "" 
)
inlineprotected

Definition at line 223 of file timeoutQueue.H.

References Aleph::maps(), NSEC, sec(), and time_key().

◆ ~Event()

TimeoutQueue::Event::~Event ( )
inlineoverridenoexcept

Definition at line 233 of file timeoutQueue.H.

References ah_warning, event_id, event_name, execution_status, In_Queue, and Aleph::maps().

Member Function Documentation

◆ EventFct()

virtual void TimeoutQueue::Event::EventFct ( )
pure virtual

Event handler function to be overridden.

This pure virtual function is called when the event's trigger time arrives. Override this in derived classes to implement custom event behavior. *

Implemented in SimpleEvent, NumberedEvent, CancellableEvent, ReschedulableEvent, PeriodicEvent, CallbackEvent, TestEvent, SignalingEvent, TimingEvent, and ReschedulingEvent.

Referenced by TEST(), and TEST().

◆ get_execution_status()

Execution_Status TimeoutQueue::Event::get_execution_status ( ) const
inline

Definition at line 246 of file timeoutQueue.H.

References execution_status.

Referenced by print_status().

◆ get_id()

EventId TimeoutQueue::Event::get_id ( ) const
inline

Get the unique event ID (auto-generated on construction)

Definition at line 253 of file timeoutQueue.H.

References event_id.

◆ get_name()

const std::string & TimeoutQueue::Event::get_name ( ) const
inline

Get the event name (for debugging)

Definition at line 256 of file timeoutQueue.H.

References event_name.

◆ getAbsoluteTime()

Time TimeoutQueue::Event::getAbsoluteTime ( ) const
inline

Definition at line 248 of file timeoutQueue.H.

References time_key().

◆ invoke_completion_callback()

void TimeoutQueue::Event::invoke_completion_callback ( )
inlineprivate

Definition at line 209 of file timeoutQueue.H.

References execution_status, and on_completed.

◆ set_completion_callback()

void TimeoutQueue::Event::set_completion_callback ( CompletionCallback  cb)
inline

Set the completion callback (called after EventFct completes or the event is canceled)

Definition at line 262 of file timeoutQueue.H.

References Aleph::maps(), and on_completed.

Referenced by TEST().

◆ set_execution_status()

void TimeoutQueue::Event::set_execution_status ( Execution_Status  status)
inlineprivate

Definition at line 204 of file timeoutQueue.H.

References execution_status.

◆ set_for_deletion()

void TimeoutQueue::Event::set_for_deletion ( )
inline

Definition at line 250 of file timeoutQueue.H.

References execution_status, and To_Delete.

◆ set_name()

void TimeoutQueue::Event::set_name ( const std::string &  name)
inline

Set the event name.

Definition at line 259 of file timeoutQueue.H.

References event_name.

◆ set_trigger_time()

void TimeoutQueue::Event::set_trigger_time ( const Time  _t)
inlineprivate

Definition at line 198 of file timeoutQueue.H.

References Aleph::maps(), NSEC, and time_key().

◆ time_key() [1/2]

Time & TimeoutQueue::Event::time_key ( )
inlineprivate

Definition at line 195 of file timeoutQueue.H.

Referenced by Event(), Event(), getAbsoluteTime(), and set_trigger_time().

◆ time_key() [2/2]

const Time & TimeoutQueue::Event::time_key ( ) const
inlineprivate

Definition at line 196 of file timeoutQueue.H.

Friends And Related Symbol Documentation

◆ TimeoutQueue

Definition at line 154 of file timeoutQueue.H.

Member Data Documentation

◆ event_id

EventId TimeoutQueue::Event::event_id
private

Definition at line 190 of file timeoutQueue.H.

Referenced by ~Event(), and get_id().

◆ event_name

std::string TimeoutQueue::Event::event_name
private

Definition at line 192 of file timeoutQueue.H.

Referenced by ~Event(), get_name(), and set_name().

◆ execution_status

std::atomic<Execution_Status> TimeoutQueue::Event::execution_status
private

◆ InvalidId

constexpr EventId TimeoutQueue::Event::InvalidId = 0
staticconstexpr

Invalid/null event ID.

Definition at line 185 of file timeoutQueue.H.

Referenced by TimeoutQueue::cancel_by_id(), TimeoutQueue::find_by_id(), TEST(), TEST(), and TEST().

◆ nextId

std::atomic< TimeoutQueue::Event::EventId > TimeoutQueue::Event::nextId {0}
staticprivate

Definition at line 39 of file timeoutQueue.H.

◆ on_completed

CompletionCallback TimeoutQueue::Event::on_completed
private

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