Dobby
3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
|
Event dispatcher loop, runs the thread that polls on the dbus fds. More...
#include <DbusEventDispatcher.h>
Public Member Functions | |
void | startEventDispatcher (DBusConnection *connection) |
Starts the event dispatch thread for the given dbus connection. More... | |
void | stopEventDispatcher () |
Stops the event dispatch thread and cleans up all file descriptors. More... | |
template<class Function , class... Args> | |
bool | callInEventLoop (Function &&f, Args &&... args) |
template<class Function > | |
bool | callInEventLoop (Function func) |
Private Member Functions | |
void | eventDispatcherThreadFn () |
Thread function that processes the events. More... | |
void | cleanupAllEvents () |
Closes the three eventfd's used to wake up and trigger events in the poll loop. More... | |
bool | callInEventLoopImpl (const std::function< void()> &func) |
Calls the supplied function in the context of the dispatch thread. More... | |
Static Private Member Functions | |
static void | dispatchStatusCb (DBusConnection *connection, DBusDispatchStatus status, void *userData) |
libdbus callback when dispatch status changes. More... | |
static void | wakeUpCb (void *userData) |
libdbus callback request to wake-up the event loop. More... | |
Event dispatcher loop, runs the thread that polls on the dbus fds.
This class installs handlers for the four types of dbus events; watches, timeouts, wake-ups and dispatches. Watches and timeouts are a bit tricky and are handled by the DbusWatches and DbusTimeouts objects respectively, however those objects still have a corresponding fd that are added to the poll loop managed by this dispatchers.
In addition the dispatcher has an API to allow you to call arbitrary functions in the context of it's dispatcher thread. This is used by the higher level DbusConnection object to make libdbus API calls on the connection from the dispatch thread, and thereby avoid the many varied race conditions in the dbus library.
|
private |
Calls the supplied function in the context of the dispatch thread.
It is safe to call this method from inside or outside the dispatch thread; if called from within, the function is directly executed, if not in the dispatcher thread then the function is queued up and the method will block until the function has been processed within the thread.
[in] | func | The function to run in the dispatcher thread |
|
private |
Closes the three eventfd's used to wake up and trigger events in the poll loop.
Upon return all eventfds will be closed.
|
staticprivate |
libdbus callback when dispatch status changes.
This simply triggers the eventfd which wakes the poll loop and results in dbus_connection_dispatch() being called.
[in] | connection | The dbus connection object. |
[in] | status | The new status of the dbus loop. |
[in] | userData | Pointer to this. |
|
private |
Thread function that processes the events.
The main poll thread that processes all dbus events.
void DbusEventDispatcher::startEventDispatcher | ( | DBusConnection * | connection | ) |
Starts the event dispatch thread for the given dbus connection.
This creates the the eventfds for the wakeup, dispatch and death events. It then registers the libdbus callback functions before finally spawning the thread that runs the poll event loop.
[in] | connection | The dbus connection to run the event loop for. |
void DbusEventDispatcher::stopEventDispatcher | ( | ) |
Stops the event dispatch thread and cleans up all file descriptors.
Starts by removing all the libdbus callbacks and then ask the thread to terminate by triggering the death eventfd.
|
staticprivate |
libdbus callback request to wake-up the event loop.
This simply triggers the eventfd which wakes the poll loop and results in dbus_connection_dispatch() being called.
[in] | userData | Pointer to this. |