Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::service::v1::TimerableService Class Reference

Timerable Service. More...

#include <TimerableService_V1.h>

Inheritance diagram for sese::service::v1::TimerableService:
sese::service::TcpTransporter

Public Member Functions

 ~TimerableService () override
 
bool init () override
 
void dispatch (uint32_t timeout) override
 
virtual void onTimeout (TimeoutEvent *timeout_event)
 
TimeoutEventcreateTimeoutEvent (int fd, void *data, uint64_t seconds)
 
void setTimeoutEvent (TimeoutEvent *timeout_event, uint64_t seconds)
 
TimeoutEventgetTimeoutEventByFd (int fd)
 
void cancelTimeoutEvent (TimeoutEvent *timeout_event)
 
void freeTimeoutEvent (TimeoutEvent *timeout_event)
 

Private Attributes

uint64_t startTimestamp {0}
 
std::map< int, TimeoutEvent * > timeoutMap
 
std::list< TimeoutEvent * > timeoutTable [60] {}
 

Detailed Description

Timerable Service.

Constructor & Destructor Documentation

◆ ~TimerableService()

TimerableService::~TimerableService ( )
override

References timeoutMap.

Member Function Documentation

◆ cancelTimeoutEvent()

void TimerableService::cancelTimeoutEvent ( TimeoutEvent * timeout_event)

Cancel the current timeout event

Parameters
timeout_eventTimeout event structure

References sese::service::v1::TimeoutEvent::exceptTimestamp, startTimestamp, and timeoutTable.

◆ createTimeoutEvent()

TimeoutEvent * TimerableService::createTimeoutEvent ( int fd,
void * data,
uint64_t seconds )

Create a timeout event

Note
Each file descriptor can correspond to only one timeout event.

Repeating the file descriptor will cause the original timeout event to be overwritten.

Typically, file descriptors refer to socket file descriptors.

For custom timeout events unrelated to sockets,

the file descriptor can be set to a negative number less than -1.

The timeout service does not care about the sign of the file descriptor.

Parameters
fdFile descriptor
dataExtra data
secondsTimeout in seconds
Returns
Timeout event structure

References sese::service::v2::TimeoutEvent::data, startTimestamp, timeoutMap, and timeoutTable.

◆ dispatch()

void TimerableService::dispatch ( uint32_t timeout)
override

◆ freeTimeoutEvent()

void TimerableService::freeTimeoutEvent ( TimeoutEvent * timeout_event)

Release the current timeout event structure

Parameters
timeout_eventTimeout event structure

References sese::service::v1::TimeoutEvent::exceptTimestamp, sese::service::v1::TimeoutEvent::fd, startTimestamp, timeoutMap, and timeoutTable.

◆ getTimeoutEventByFd()

TimeoutEvent * TimerableService::getTimeoutEventByFd ( int fd)

Get the timeout event structure by file descriptor

Parameters
fdFile descriptor
Return values
nullptrThe corresponding timeout event does not exist
Returns
The corresponding timeout event structure

References timeoutMap.

◆ init()

bool TimerableService::init ( )
override

References startTimestamp.

◆ onTimeout()

void TimerableService::onTimeout ( TimeoutEvent * timeout_event)
virtual

Triggered when a timeout event occurs

Parameters
timeout_eventTimeout event

Reimplemented in sese::service::TcpTransporter.

Referenced by dispatch().

◆ setTimeoutEvent()

void TimerableService::setTimeoutEvent ( TimeoutEvent * timeout_event,
uint64_t seconds )

Reset the current timeout event, the original event will be canceled and overwritten

See also
createTimoutEvent
Parameters
timeout_eventTimeout event structure
secondsTimeout in seconds

References sese::service::v1::TimeoutEvent::exceptTimestamp, startTimestamp, and timeoutTable.

Member Data Documentation

◆ startTimestamp

uint64_t sese::service::v1::TimerableService::startTimestamp {0}
private

◆ timeoutMap

std::map<int, TimeoutEvent *> sese::service::v1::TimerableService::timeoutMap
private

◆ timeoutTable

std::list<TimeoutEvent *> sese::service::v1::TimerableService::timeoutTable[60] {}
private

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