23 #ifndef AI_IPC_DBUSCONNECTION_H
24 #define AI_IPC_DBUSCONNECTION_H
26 #include "DbusEventDispatcher.h"
27 #include <ConditionVariable.h>
38 #include <condition_variable>
40 #include <sys/types.h>
42 #include <dbus/dbus.h>
68 bool connect(DBusBusType busType,
const std::string& serviceName = std::string());
70 bool connect(
const std::string& address,
const std::string& serviceName = std::string());
82 DBusMessage*
getReply(uint64_t token);
92 bool addMatch(
const std::string& rule);
96 std::string getAddress();
102 DBusConnection *mDbusConnection;
106 bool completeConnect(DBusConnection* conn,
const std::string& serviceName);
110 DBusMessage *message,
113 typedef std::function<DBusHandlerResult(DBusMessage*)> MessageHandler;
114 MessageHandler mHandler;
120 const std::string& name)
const;
122 std::string mServiceName;
136 std::atomic<uint64_t> mTokenCounter;
140 std::map<uint64_t, DBusMessage*> mReplies;
Definition: ConditionVariable.h:67
Definition: SpinLock.h:42
Wraps a dbus connection pointer and runs the dispatch loop for it.
Definition: DbusConnection.h:61
uint64_t sendMessageWithReply(DBusMessage *msg, int timeout)
Sends a dbus message out the connection.
Definition: DbusConnection.cpp:491
static DBusHandlerResult handleDbusMessageCb(DBusConnection *connection, DBusMessage *message, void *userData)
Callback from the libdbus in the context of the event / dispatcher thread.
Definition: DbusConnection.cpp:341
void disconnect()
Disconnect from the bus.
Definition: DbusConnection.cpp:258
static void pendingCallFreeFcn(void *userData)
Callback from libdus when a pending call notifier is being destroyed and we should clean up the conte...
Definition: DbusConnection.cpp:459
uid_t getUnixUser(const std::string &name)
Returns the unix user id of the named client.
Definition: DbusConnection.cpp:739
DBusMessage * getReply(uint64_t token)
Gets the reply for the given request.
Definition: DbusConnection.cpp:611
bool sendMessageNoReply(DBusMessage *msg)
Sends a message on the connection without expecting a reply.
Definition: DbusConnection.cpp:566
static void pendingCallNotifyFcn(DBusPendingCall *pending, void *userData)
Callback from libdus when either a reply is received for a pending call or the timeout expires.
Definition: DbusConnection.cpp:404
bool reserveServiceName(DBusConnection *dbusConnection, const std::string &name) const
Attempts to reserve a service name on dbus.
Definition: DbusConnection.cpp:69
bool nameHasOwner(const std::string &name)
Returns true if the supplied name exists on the bus.
Definition: DbusConnection.cpp:697
bool addMatch(const std::string &rule)
Adds a match rule for the connection.
Definition: DbusConnection.cpp:786
bool cancelReply(uint64_t token)
Cancels waiting for the reply.
Definition: DbusConnection.cpp:663
bool completeConnect(DBusConnection *conn, const std::string &serviceName)
Completes the initialisation of the dbus connection.
Definition: DbusConnection.cpp:189
bool removeMatch(const std::string &rule)
Removes a match rule from the connection.
Definition: DbusConnection.cpp:834
void registerMessageHandler(const std::function< DBusHandlerResult(DBusMessage *)> &handler)
Registers a handler to be called when any message (method call or signal) is received.
Definition: DbusConnection.cpp:376
bool connect(DBusBusType busType, const std::string &serviceName=std::string())
Attempts to connect to one of the known buses and optionally reserve the given service name.
Definition: DbusConnection.cpp:131
bool flushConnection()
Flushes the dbus connection.
Definition: DbusConnection.cpp:880
Event dispatcher loop, runs the thread that polls on the dbus fds.
Definition: DbusEventDispatcher.h:60
Definition: DbusConnection.h:131