cumbia 1.x
general purpose multi threaded library
Loading...
Searching...
No Matches
CuTimerService Class Reference

The CuTimerService class provides access to cumbia timers. It is normally used internally by the library. More...

#include <cutimerservice.h>

Inheritance diagram for CuTimerService:

Public Member Functions

 CuTimerService ()
 Class constructor Initializes timerMaxCount to 25. More...
 
 ~CuTimerService ()
 
CuTimerregisterListener (CuTimerListener *timer_listener, int timeout, CuEventLoopService *loop_service=nullptr, const std::string &tmrname=std::string())
 Register a new CuTimerListener with a given timeout. Reuse existing timers if possible. Listeners shall be notified in the event loop thread if the method is called with a non null reference to CuEventLoopService, in the CuTimer's thread otherwise. More...
 
void unregisterListener (CuTimerListener *th, int timeout)
 Unregister a listener with the given timeout from the service. More...
 
CuTimerchangeTimeout (CuTimerListener *th, int from_timeo, int to_timeo)
 Changes the timeout of the timer that serves the given listener. More...
 
void restart (CuTimer *t)
 restart the timer t with interval millis More...
 
void start (CuTimer *t)
 start the timer More...
 
std::string getName () const
 Returns the name of the service. More...
 
CuServices::Type getType () const
 CuTimerService::getType returns the service type. More...
 
- Public Member Functions inherited from CuServiceI
virtual ~CuServiceI ()
 
virtual std::string getName () const =0
 return the name of the service More...
 
virtual CuServices::Type getType () const =0
 return the type of the service More...
 

Detailed Description

The CuTimerService class provides access to cumbia timers. It is normally used internally by the library.

CuTimerService implements CuServiceI in order to provide access to CuTimer objects. They are not directly available to clients. Use registerListener to either get a timer. Timers are shared across all listeners registered with the same timeout. unregisterListener is called when a timer is no more needed. CuTimer is single shot: CuTimerService::restart shall be called to restart the timer. It is possible to get the list of CuTimerListener for a given timer and the list of all timers.

Constructor & Destructor Documentation

◆ CuTimerService()

CuTimerService::CuTimerService ( )

Class constructor Initializes timerMaxCount to 25.

References CuTimerServicePrivate::timer_max_count, and CuTimerServicePrivate::tmrcnt.

◆ ~CuTimerService()

CuTimerService::~CuTimerService ( )

Member Function Documentation

◆ changeTimeout()

CuTimer * CuTimerService::changeTimeout ( CuTimerListener *  tl,
int  from_timeo,
int  to_timeo 
)

Changes the timeout of the timer that serves the given listener.

Parameters
tlthe CuTimerListener requiring a change in timeout
timeoutthe new timeout, in milliseconds
Returns
A fresh or existing timer satisfying the requirements in terms of timeout.
Note
Internally, unregisterListener and registerListener are called

References perr, registerListener(), CuTimerServicePrivate::shmu, CuTimer::timeout(), and unregisterListener().

◆ getName()

std::string CuTimerService::getName ( ) const
virtual

Returns the name of the service.

Returns
"CuTimerService"

Implements CuServiceI.

◆ getType()

CuServices::Type CuTimerService::getType ( ) const
virtual

CuTimerService::getType returns the service type.

Returns
CuServices::Timer

Implements CuServiceI.

References CuServices::Timer.

◆ registerListener()

CuTimer * CuTimerService::registerListener ( CuTimerListener *  tl,
int  timeout,
CuEventLoopService loo_s = nullptr,
const std::string &  tmrname = std::string() 
)

Register a new CuTimerListener with a given timeout. Reuse existing timers if possible. Listeners shall be notified in the event loop thread if the method is called with a non null reference to CuEventLoopService, in the CuTimer's thread otherwise.

Parameters
timer_listenera CuTimerListener (e.g. CuThread)
timeoutthe desired timeout
loop_serviceif specified (not null) then the timeout callback is executed in the same thread as the event loop thread (usually, the main thread).
Since
1.3.0
Parameters
tmrnamean optional name for the timer to be created. If the timer is reused, passing a non empty tmrname will overwrite the timer name.
Returns
a new CuTimer or a CuTimer already in use
Timer registration

A timer with the same timeout is reused and the listener and loop service are added to the instance.

Note
If the same listener is registered with another loo_s, the new one replaces the old one.

References CuTimerPrivate::m_id, CuTimerPrivate::m_name, pgreen, CuTimer::setTimeout(), CuTimerServicePrivate::shmu, CuTimerServicePrivate::ti_cache, CuTimerServicePrivate::ti_map, CuTimerServicePrivate::timer_max_count, and CuTimerServicePrivate::tmrcnt.

Referenced by changeTimeout().

◆ restart()

void CuTimerService::restart ( CuTimer t)

restart the timer t with interval millis

Parameters
tthe timer to restart
millisthe desired interval

The timer is rescheduled if a timeout is already pending

◆ start()

void CuTimerService::start ( CuTimer t)

start the timer

Parameters
twhich timer
millistimeout in milliseconds

if the timer is pending, nothing is done. Timer is started otherwise.

◆ unregisterListener()

void CuTimerService::unregisterListener ( CuTimerListener *  tl,
int  timeout 
)

Unregister a listener with the given timeout from the service.

Parameters
tlthe CuTimerListner to unregister
timeoutthe to remove listener's timeout

If the timer associated to tl has no more listeners after unregistration, it will be stopped and deleted.

References pfatal, and CuTimerServicePrivate::shmu.

Referenced by changeTimeout().


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