|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Base class for scheduled events. More...
#include <timeoutQueue.H>
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 | |
| Time & | time_key () |
| const Time & | time_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_Status > | execution_status |
| std::string | event_name |
| CompletionCallback | on_completed |
Static Private Attributes | |
| static std::atomic< EventId > | nextId {0} |
Friends | |
| class | TimeoutQueue |
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.
| using TimeoutQueue::Event::CompletionCallback = std::function<void(Event *, Execution_Status)> |
Optional callback invoked after an event completes, is canceled, or is deleted.
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.
Type for unique event identifiers.
Definition at line 182 of file timeoutQueue.H.
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.
Definition at line 216 of file timeoutQueue.H.
References Aleph::maps(), NSEC, and time_key().
|
inlineprotected |
Definition at line 223 of file timeoutQueue.H.
References Aleph::maps(), NSEC, sec(), and time_key().
|
inlineoverridenoexcept |
Definition at line 233 of file timeoutQueue.H.
References ah_warning, event_id, event_name, execution_status, In_Queue, and Aleph::maps().
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.
|
inline |
Definition at line 246 of file timeoutQueue.H.
References execution_status.
Referenced by print_status().
|
inline |
Get the unique event ID (auto-generated on construction)
Definition at line 253 of file timeoutQueue.H.
References event_id.
|
inline |
Get the event name (for debugging)
Definition at line 256 of file timeoutQueue.H.
References event_name.
|
inline |
Definition at line 248 of file timeoutQueue.H.
References time_key().
|
inlineprivate |
Definition at line 209 of file timeoutQueue.H.
References execution_status, and on_completed.
|
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().
|
inlineprivate |
Definition at line 204 of file timeoutQueue.H.
References execution_status.
|
inline |
Definition at line 250 of file timeoutQueue.H.
References execution_status, and To_Delete.
Definition at line 198 of file timeoutQueue.H.
References Aleph::maps(), NSEC, and time_key().
|
inlineprivate |
Definition at line 195 of file timeoutQueue.H.
Referenced by Event(), Event(), getAbsoluteTime(), and set_trigger_time().
Definition at line 196 of file timeoutQueue.H.
|
friend |
Definition at line 154 of file timeoutQueue.H.
|
private |
Definition at line 190 of file timeoutQueue.H.
|
private |
Definition at line 192 of file timeoutQueue.H.
Referenced by ~Event(), get_name(), and set_name().
|
private |
Definition at line 191 of file timeoutQueue.H.
Referenced by ~Event(), get_execution_status(), invoke_completion_callback(), set_execution_status(), and set_for_deletion().
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().
|
staticprivate |
Definition at line 39 of file timeoutQueue.H.
|
private |
Definition at line 193 of file timeoutQueue.H.
Referenced by TimeoutQueue::clear_all(), invoke_completion_callback(), set_completion_callback(), and TimeoutQueue::triggerEvent().