sptk2 logo
SPTK Home Page
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
sptk::Timer Class Reference

#include <Timer.h>

Classes

class  EventData
 
struct  EventId
 

Public Types

using Event = std::shared_ptr< EventData >
 

Public Member Functions

 Timer ()=default
 
 Timer (const Timer &other)=delete
 
virtual ~Timer ()
 
Event fireAt (const DateTime &timestamp, const EventData::Callback &eventCallback)
 
Event repeat (std::chrono::milliseconds interval, const EventData::Callback &eventCallback, int repeatCount=-1)
 
void cancel (const Event &event)
 
void cancel ()
 

Protected Member Functions

void unlink (const Event &event)
 Remove event from this timer.
 

Detailed Description

Generic timer class. Can fire one time off and repeatable events

Member Typedef Documentation

◆ Event

using sptk::Timer::Event = std::shared_ptr<EventData>

Type definition for timer event

Constructor & Destructor Documentation

◆ Timer() [1/2]

sptk::Timer::Timer ( )
default

Constructor

◆ Timer() [2/2]

sptk::Timer::Timer ( const Timer other)
delete

Copy constructor

Parameters
otherTimer to copy from

◆ ~Timer()

virtual sptk::Timer::~Timer ( )
virtual

Destructor. Cancel all events scheduled by this timer.

Member Function Documentation

◆ cancel() [1/2]

void sptk::Timer::cancel ( )

Cancel all events

◆ cancel() [2/2]

void sptk::Timer::cancel ( const Event event)

Cancel event

Parameters
eventEvent handle, returned by event scheduling method.

◆ fireAt()

Event sptk::Timer::fireAt ( const DateTime timestamp,
const EventData::Callback eventCallback 
)

Schedule single event.

Parameters
timestampFire at timestamp
eventCallbackEvent callback.
Returns
event handle, that may be used to cancel this event.

◆ repeat()

Event sptk::Timer::repeat ( std::chrono::milliseconds  interval,
const EventData::Callback eventCallback,
int  repeatCount = -1 
)

Schedule repeatable event. The first event is scheduled at current time + interval.

Parameters
intervalEvent repeat interval.
eventCallbackEvent callback.
repeatCountRepeat count, -1 means no limit
Returns
event handle, that may be used to cancel this event.

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

Fri Oct 14 2022 09:58:46: SPTK 5.4.1