SW Task Event Loop Framework v1.0.0
High-performance C++ asynchronous event loop framework with timer management and promise-based programming
|
RAII timer wrapper with boost-style API and move semantics. More...
#include <Timer.h>
Public Member Functions | |
Timer (TimerId id, std::weak_ptr< SLLooper > looper) | |
Constructor - creates timer handle. | |
Timer (const Timer &)=delete | |
Copy constructor - deleted (move-only semantics) | |
Timer & | operator= (const Timer &)=delete |
Copy assignment - deleted (move-only semantics) | |
Timer (Timer &&other) noexcept | |
Move constructor - transfers timer ownership. | |
Timer & | operator= (Timer &&other) noexcept |
Move assignment - transfers timer ownership. | |
~Timer () | |
Destructor - automatic timer cleanup. | |
void | cancel () |
Cancel the timer. | |
bool | isActive () const |
Check if timer is currently active. | |
TimerId | getId () const |
Get unique timer identifier. | |
void | restart (uint64_t delay_ms) |
Restart timer with new delay (one-shot timers only) | |
Friends | |
class | SLLooper |
Friend class declaration for internal access. | |
RAII timer wrapper with boost-style API and move semantics.
Timer provides a safe, RAII-based interface for managing kernel timers. Key characteristics:
The Timer class acts as a handle to an underlying kernel timer managed by TimerManager. It ensures proper cleanup and provides safe access to timer operations even when the timer is moved between objects.
Constructor - creates timer handle.
id | Unique timer identifier from TimerManager |
looper | Weak reference to parent SLLooper instance |
Creates a Timer handle that manages the lifecycle of a kernel timer. The weak_ptr prevents circular dependencies with the parent SLLooper.
|
delete |
Copy constructor - deleted (move-only semantics)
Timer objects cannot be copied to ensure unique ownership of the underlying kernel timer resource.
|
noexcept |
Move constructor - transfers timer ownership.
other | Timer object to move from |
Safely transfers ownership of the underlying timer:
swt::Timer::~Timer | ( | ) |
void swt::Timer::cancel | ( | ) |
Cancel the timer.
Cancels the underlying kernel timer and prevents future callback execution. Safe to call multiple times - subsequent calls are no-ops.
Definition at line 59 of file Timer.cpp.
Referenced by ~Timer().
|
inline |
Get unique timer identifier.
Returns the unique identifier assigned by TimerManager. Useful for debugging and logging purposes.
bool swt::Timer::isActive | ( | ) | const |
Check if timer is currently active.
Returns timer status by checking both local cancellation flag and TimerManager's internal state. A timer is considered active if:
Definition at line 75 of file Timer.cpp.
Referenced by swt::SLLooper::addPeriodicTimer(), and swt::SLLooper::addTimer().
Copy assignment - deleted (move-only semantics)
Timer objects cannot be copy-assigned to ensure unique ownership.
Move assignment - transfers timer ownership.
other | Timer object to move from |
Cancels current timer (if any) and transfers ownership from other timer. Handles self-assignment safely.
void swt::Timer::restart | ( | uint64_t | delay_ms | ) |
Restart timer with new delay (one-shot timers only)
delay_ms | New delay in milliseconds before timer expiration |
Restarts the timer with a new delay value while maintaining all other timer properties (callback, periodic flag, etc.). Resets the cancellation flag to allow the timer to fire again.
|
friend |