26 #ifndef AI_IPC_IPCSERVICE_H
27 #define AI_IPC_IPCSERVICE_H
29 #include "IpcCommon.h"
30 #include "IIpcService.h"
32 #include "DbusConnection.h"
33 #include "IDbusUserIdSenderIdCache.h"
35 #include <ThreadedDispatcher.h>
36 #include <Common/Interface.h>
38 #include <dbus/dbus.h>
49 ,
public std::enable_shared_from_this<IpcService>
59 IpcService(BusType busType,
const std::string& serviceName,
int defaultTimeoutMs = -1);
60 IpcService(
const std::string& dbusAddress,
const std::string& serviceName,
int defaultTimeoutMs = -1);
64 virtual bool isValid()
const override;
66 virtual std::shared_ptr<AI_IPC::IAsyncReplyGetter>
invokeMethod(
const AI_IPC::Method& method,
const AI_IPC::VariantList& args,
int timeoutMs = -1)
override;
68 virtual bool invokeMethod(
const AI_IPC::Method& method,
const AI_IPC::VariantList& args, AI_IPC::VariantList& replyArgs,
int timeoutMs = -1)
override;
78 virtual bool enableMonitor(
const std::set<std::string>& matchRules,
const AI_IPC::MonitorHandler& handler)
override;
82 virtual void flush()
override;
84 virtual bool start()
override;
86 virtual bool stop()
override;
88 bool isRegisteredObjectPath(
const std::string& path);
96 bool invokeMethodAndGetReply(DBusMessage *dbusSendMsg, AI_IPC::VariantList& replyArgs);
98 DBusHandlerResult handleDbusMessageCb(DBusMessage *message);
100 DBusHandlerResult handleDbusMessage(DBusMessage *message);
102 DBusHandlerResult handleDbusSignal(
const AI_IPC::Signal& signal,
const AI_IPC::VariantList& argList);
104 DBusHandlerResult handleDbusMethodCall(
const AI_IPC::Method& method,
const AI_IPC::VariantList& argList, DBusMessage *message);
106 void unregisterHandlers();
108 void registerObjectPath(
const std::string& path);
110 void unregisterObjectPath(
const std::string& path);
112 bool isDbusMessageAllowed(
const std::string& sender,
const std::string& interface);
114 std::string mServiceName;
116 std::string mBusAddress;
118 std::shared_ptr<AI_IPC::DbusConnection> mDbusConnection;
120 std::map<std::string, int> mObjectPaths;
122 std::map<std::string, std::pair<AI_IPC::Method, AI_IPC::MethodHandler>> mMethodHandlers;
124 std::map<std::string, std::pair<AI_IPC::Signal, AI_IPC::SignalHandler>> mSignalHandlers;
130 std::atomic<bool> mRunning;
132 int mNextSignalHandlerRegId;
134 const int mDefaultTimeoutMs;
138 #if (AI_BUILD_TYPE == AI_DEBUG)
140 DBusHandlerResult handleDbusMonitorEvent(DBusMessage *dbusMsg);
142 std::atomic<bool> mInMonitorMode;
144 AI_IPC::MonitorHandler mMonitorCb;
146 std::set<std::string> mMonitorMatchRules;
A dispatcher that does all the work on a single, separate thread started in constructor.
Definition: ThreadedDispatcher.h:46
IPC service that enables us to invoke remote method and emit signals as well as to handle incoming me...
Definition: IIpcService.h:42
Definition: IpcService.h:50
virtual bool start() override
Start IPC service.
Definition: IpcService.cpp:718
virtual void flush() override
Flushes all messages out.
Definition: IpcService.cpp:707
virtual std::string registerMethodHandler(const AI_IPC::Method &method, const AI_IPC::MethodHandler &handler) override
Register a method handler.
Definition: IpcService.cpp:338
std::string getBusAddress() const override
Returns the dbus address the service is using.
Definition: IpcService.cpp:985
virtual bool enableMonitor(const std::set< std::string > &matchRules, const AI_IPC::MonitorHandler &handler) override
Enables monitor mode on the IPC service, this will effectively disable all registered method and sign...
Definition: IpcService.cpp:856
virtual bool unregisterHandler(const std::string ®Id) override
Unregister a method or signal handler.
Definition: IpcService.cpp:435
virtual std::string registerSignalHandler(const AI_IPC::Signal &signal, const AI_IPC::SignalHandler &handler) override
Register a signal handler.
Definition: IpcService.cpp:399
virtual bool disableMonitor() override
Disables monitor mode and restores normal behaviour.
Definition: IpcService.cpp:917
virtual bool stop() override
Stop IPC service.
Definition: IpcService.cpp:740
virtual std::shared_ptr< AI_IPC::IAsyncReplyGetter > invokeMethod(const AI_IPC::Method &method, const AI_IPC::VariantList &args, int timeoutMs=-1) override
Invoke a method and get reply asynchronously.
Definition: IpcService.cpp:225
virtual bool isServiceAvailable(const std::string &serviceName) const override
Checks if the named service is available on the bus.
Definition: IpcService.cpp:971
virtual bool isValid() const override
Returns true if we initialised ourselves successfully.
Definition: IpcService.cpp:220
virtual bool emitSignal(const AI_IPC::Signal &signal, const AI_IPC::VariantList &args) override
Emit a signal.
Definition: IpcService.cpp:301
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