Object that manages the timeouts for a given dbus connection.
More...
#include <DbusTimeouts.h>
|
| 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...
|
|
|
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 ¤tTime) const |
| Utility function that simply checks if a timespec is after or equal to another timespec. More...
|
|
|
static dbus_bool_t | addTimeOutCb (DBusTimeout *timeout, void *userData) |
|
static void | toggleTimeOutCb (DBusTimeout *timeout, void *userData) |
|
static void | removeTimeOutCb (DBusTimeout *timeout, void *userData) |
|
|
int | mTimerFd |
|
DBusConnection *const | mDbusConnection |
|
bool | mWithinEventHandler |
|
std::list< TimeoutEntry > | mTimeouts |
|
const std::thread::id | mExpectedThreadId |
|
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.
◆ addTimeOut()
dbus_bool_t DbusTimeouts::addTimeOut |
( |
DBusTimeout * |
timeout | ) |
|
|
private |
Adds the given timeout to the timerfd to poll on.
- Parameters
-
[in] | timeout | The 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] | base | The base time to calculate the new offset from |
[in] | offset | The 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] | expiryTime | The expiry time point. |
[in] | currentTime | The 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] | pollEvents | Bitmask of the poll events that woke the main loop. |
◆ removeTimeOut()
void DbusTimeouts::removeTimeOut |
( |
DBusTimeout * |
timeout | ) |
|
|
private |
Removes the timeout from the timerfd.
- Parameters
-
[in] | timeout | The timeout object to remove |
◆ toggleTimeOut()
void DbusTimeouts::toggleTimeOut |
( |
DBusTimeout * |
timeout | ) |
|
|
private |
Toggles the enable / disable state of a timeout.
- Parameters
-
[in] | timeout | The 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:
- AppInfrastructure/IpcService/source/libdbus/DbusTimeouts.h
- AppInfrastructure/IpcService/source/libdbus/DbusTimeouts.cpp