26 #include <IIpcService.h>
33 #include <condition_variable>
36 typedef std::function<void(
bool)> ServiceHandlerFn;
61 const std::shared_ptr<AI_IPC::IIpcService>& ipcService);
70 const std::string&
address()
const;
75 const AI_IPC::VariantList& args,
79 const AI_IPC::VariantList& args,
80 AI_IPC::VariantList& replyArgs)
const;
83 const AI_IPC::VariantList& args)
const;
90 const ServiceHandlerFn& handlerFunc);
93 const AI_IPC::SignalHandler& handlerFunc);
111 mutable std::mutex mLock;
113 std::shared_ptr<AI_IPC::IIpcService> mService;
115 std::string mDbusAddress;
116 std::string mDbusSocketPath;
120 std::string mServiceSignal;
126 const ServiceHandlerFn& handler_)
127 : name(name_), handler(handler_)
131 ServiceHandlerFn handler;
134 std::map<int, ServiceHandler> mServiceHandlers;
140 const AI_IPC::SignalHandler& handler_)
141 : regId(regId_), signal(signal_), handler(handler_)
146 AI_IPC::SignalHandler handler;
149 std::map<int, SignalHandler> mSignalHandlers;
152 std::thread mServiceChangeThread;
153 std::mutex mServiceChangeLock;
154 std::condition_variable mServiceChangeCond;
158 enum EventType { Terminate, ServiceAdded, ServiceRemoved };
165 , serviceName(serviceName_)
168 const EventType type;
169 std::string serviceName;
172 std::deque<ServiceChangeEvent> mServiceChangeQueue;
Wraps an IPC service object on a given bus.
Definition: DobbyIpcBus.h:58
void serviceChangeThread()
Thread function that receives notifications on service changes and then calls the install handler.
Definition: DobbyIpcBus.cpp:643
bool serviceAvailable(const std::string &serviceName) const
Queries if the given service is available on the bus.
Definition: DobbyIpcBus.cpp:447
void disconnect()
Simply disconnects from the bus.
Definition: DobbyIpcBus.cpp:265
void registerServiceWatcher()
Install a signal handler to detect services arriving / leaving the bus.
Definition: DobbyIpcBus.cpp:350
bool connect(const std::string &address)
Tries to connect to the bus at the given address.
Definition: DobbyIpcBus.cpp:177
const std::string & address() const
Simply returns the dbus address if we have one.
Definition: DobbyIpcBus.cpp:80
void disconnectNoLock()
Disconnects the service from the bus.
Definition: DobbyIpcBus.cpp:283
int registerSignalHandler(const AI_IPC::Signal &signal, const AI_IPC::SignalHandler &handlerFunc)
Registers a callback function that will be called when the given signal is received on the bus.
Definition: DobbyIpcBus.cpp:509
bool emitSignal(const AI_IPC::Signal &signal, const AI_IPC::VariantList &args) const
Sends out a signal over dbus.
Definition: DobbyIpcBus.cpp:426
int registerServiceHandler(const std::string &serviceName, const ServiceHandlerFn &handlerFunc)
Registers a callback function that will be called when the given service is added or removed from the...
Definition: DobbyIpcBus.cpp:482
const std::string & socketPath() const
Returns just the socket path of the dbus address.
Definition: DobbyIpcBus.cpp:92
void serviceNameChanged(const AI_IPC::VariantList &args)
Callback function called when dbus has informed us that a name on the bus has changed.
Definition: DobbyIpcBus.cpp:599
static std::string socketPathFromAddress(const std::string &address)
Utility function to extract the socket path from the dbus address string.
Definition: DobbyIpcBus.cpp:110
std::shared_ptr< AI_IPC::IAsyncReplyGetter > invokeMethod(const AI_IPC::Method &method, const AI_IPC::VariantList &args, int timeoutMs) const
Invokes the ipc method.
Definition: DobbyIpcBus.cpp:379
void unregisterHandler(int handlerId)
Unregisters a signal or service handler.
Definition: DobbyIpcBus.cpp:543
Method identified by a service, object, interface and method name itself.
Definition: IpcCommon.h:90
Method identified by object, interface and signal name itself.
Definition: IpcCommon.h:105