Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
AI_IPC::DbusTimeouts Class Reference

Object that manages the timeouts for a given dbus connection. More...

#include <DbusTimeouts.h>

Classes

struct  _TimeoutEntry
 

Public Member Functions

 DbusTimeouts (DBusConnection *conn)
 
int fd () const
 Returns the timerfd that the dispatcher should poll on.
 
void processEvent (unsigned int pollEvents)
 Called when something has happened on the timerfd event loop. More...
 

Private Types

typedef struct AI_IPC::DbusTimeouts::_TimeoutEntry TimeoutEntry
 

Private Member Functions

dbus_bool_t addTimeOut (DBusTimeout *timeout)
 Adds the given timeout to the timerfd to poll on. More...
 
void toggleTimeOut (DBusTimeout *timeout)
 Toggles the enable / disable state of a timeout. More...
 
void removeTimeOut (DBusTimeout *timeout)
 Removes the timeout from the timerfd. More...
 
struct timespec calcAbsTime (const struct timespec &base, int milliseconds) const
 Calculates a new time value based on the time now and the supplied millisecond offset. More...
 
void updateTimerFd () const
 Writes the item on the head of the expiry queue into the timerfd for the next wake-up time. More...
 
bool hasExpired (const struct timespec &expiryTime, const struct timespec &currentTime) const
 Utility function that simply checks if a timespec is after or equal to another timespec. More...
 

Static Private Member Functions

static dbus_bool_t addTimeOutCb (DBusTimeout *timeout, void *userData)
 
static void toggleTimeOutCb (DBusTimeout *timeout, void *userData)
 
static void removeTimeOutCb (DBusTimeout *timeout, void *userData)
 

Private Attributes

int mTimerFd
 
DBusConnection *const mDbusConnection
 
bool mWithinEventHandler
 
std::list< TimeoutEntrymTimeouts
 
const std::thread::id mExpectedThreadId
 

Detailed Description

Object that manages the timeouts for a given dbus connection.

Warning
This class is not thread safe, it is designed to only be called from one thread which is the same thread the libdbus callbacks will be called from. On debug builds an error will be reported if called from any other thread.

Internally it creates an timerfd object and a sorted list of expiry times matched to dbus timeout objects. The expiry item on the head of the list is programmed into the timerfd so the poll loop will wake up when the timer expires.

Although the code is not thread safe (by design) it handles reentrant calls to the installed dbus callbacks while in the processing loop.

Member Function Documentation

◆ addTimeOut()

dbus_bool_t DbusTimeouts::addTimeOut ( DBusTimeout *  timeout)
private

Adds the given timeout to the timerfd to poll on.

Parameters
[in]timeoutThe timeout object to add
Returns
TRUE if the timeout was added, otherwise FALSE.

◆ calcAbsTime()

struct timespec DbusTimeouts::calcAbsTime ( const struct timespec &  base,
int  milliseconds 
) const
private

Calculates a new time value based on the time now and the supplied millisecond offset.

Parameters
[in]baseThe base time to calculate the new offset from
[in]offsetThe milliseconds offset
Returns
a timespec that is the base value plus the offset.

◆ hasExpired()

bool DbusTimeouts::hasExpired ( const struct timespec &  expiryTime,
const struct timespec &  currentTime 
) const
inlineprivate

Utility function that simply checks if a timespec is after or equal to another timespec.

This is used to determine if a timer has expired or not.

Parameters
[in]expiryTimeThe expiry time point.
[in]currentTimeThe current time point.
Returns
true if expiryTime is less than or equal to the currentTime.

◆ processEvent()

void DbusTimeouts::processEvent ( unsigned int  pollEvents)

Called when something has happened on the timerfd event loop.

The main disaptcher loop polls on the timerfd we supply, when anything changes then this method is called.

Parameters
[in]pollEventsBitmask of the poll events that woke the main loop.

◆ removeTimeOut()

void DbusTimeouts::removeTimeOut ( DBusTimeout *  timeout)
private

Removes the timeout from the timerfd.

Parameters
[in]timeoutThe timeout object to remove

◆ toggleTimeOut()

void DbusTimeouts::toggleTimeOut ( DBusTimeout *  timeout)
private

Toggles the enable / disable state of a timeout.

Parameters
[in]timeoutThe timeout object to toggle

◆ updateTimerFd()

void DbusTimeouts::updateTimerFd ( ) const
private

Writes the item on the head of the expiry queue into the timerfd for the next wake-up time.

If the expiry queue is empty then 0 is written into the timerfd which disables it.


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