24 #ifndef AI_IPC_DBUSEVENTDISPATCHER_H
25 #define AI_IPC_DBUSEVENTDISPATCHER_H
27 #include <dbus/dbus.h>
34 #include <condition_variable>
72 template<
class Function,
class... Args >
73 bool callInEventLoop(Function&& f, Args&&... args)
76 std::forward<Args>(args)...));
79 template<
class Function >
80 bool callInEventLoop(Function func)
91 static void dispatchStatusCb(DBusConnection *connection, DBusDispatchStatus status,
void *userData);
93 static void wakeUpCb(
void *userData);
96 DBusConnection* mDbusConnection;
98 std::thread mEventDispatcherThread;
102 int mDispatchEventFd;
107 uint64_t mCallCounter;
108 std::mutex mCallLock;
109 std::condition_variable mCallCondVar;
110 std::queue< std::pair<uint64_t, std::function<void()>> > mCallQueue;
Event dispatcher loop, runs the thread that polls on the dbus fds.
Definition: DbusEventDispatcher.h:60
void startEventDispatcher(DBusConnection *connection)
Starts the event dispatch thread for the given dbus connection.
Definition: DbusEventDispatcher.cpp:81
static void dispatchStatusCb(DBusConnection *connection, DBusDispatchStatus status, void *userData)
libdbus callback when dispatch status changes.
Definition: DbusEventDispatcher.cpp:414
static void wakeUpCb(void *userData)
libdbus callback request to wake-up the event loop.
Definition: DbusEventDispatcher.cpp:448
void eventDispatcherThreadFn()
Thread function that processes the events.
Definition: DbusEventDispatcher.cpp:199
void stopEventDispatcher()
Stops the event dispatch thread and cleans up all file descriptors.
Definition: DbusEventDispatcher.cpp:144
void cleanupAllEvents()
Closes the three eventfd's used to wake up and trigger events in the poll loop.
Definition: DbusEventDispatcher.cpp:379
bool callInEventLoopImpl(const std::function< void()> &func)
Calls the supplied function in the context of the dispatch thread.
Definition: DbusEventDispatcher.cpp:485