25 #ifndef SDBUSIPCSERVICE_H
26 #define SDBUSIPCSERVICE_H
28 #include "IpcCommon.h"
29 #include "IIpcService.h"
37 #include <condition_variable>
42 typedef struct sd_bus sd_bus;
43 typedef struct sd_bus_slot sd_bus_slot;
44 typedef struct sd_bus_message sd_bus_message;
45 typedef struct sd_event_source sd_event_source;
52 ,
public std::enable_shared_from_this<SDBusIpcService>
62 SDBusIpcService(BusType busType,
const std::string& serviceName,
int defaultTimeoutMs = -1);
63 SDBusIpcService(
const std::string &busAddress,
const std::string& serviceName,
int defaultTimeoutMs = -1);
68 std::shared_ptr<AI_IPC::IAsyncReplyGetter>
invokeMethod(
const AI_IPC::Method &method,
const AI_IPC::VariantList &args,
int timeoutMs)
override;
69 bool invokeMethod(
const AI_IPC::Method &method,
const AI_IPC::VariantList &args, AI_IPC::VariantList &replyArgs,
int timeoutMs)
override;
77 bool enableMonitor(
const std::set<std::string> &matchRules,
const AI_IPC::MonitorHandler& handler)
override;
80 void flush()
override;
82 bool start()
override;
91 void freeMethodReply(uint32_t replyId);
92 bool sendMethodReply(uint32_t replyId,
93 const AI_IPC::VariantList& replyArgs);
98 bool init(
const std::string &serviceName,
int defaultTimeoutMs);
100 void eventLoopThread();
102 bool runOnEventLoopThread(std::function<
void()> &&fn)
const;
104 static int onExecCall(sd_event_source *s,
int fd, uint32_t revents,
void *userdata);
106 static int onRuleMatch(sd_bus_message *m,
void *userData,
void *retError);
107 static int onMethodCall(sd_bus_message *reply,
void *userData,
void *retError);
108 static int onMethodReply(sd_bus_message *reply,
void *userData,
void *retError);
111 uint64_t mDefaultTimeoutUsecs;
116 std::atomic<bool> mStarted;
122 sd_bus_slot *objectSlot;
124 std::string interface;
126 AI_IPC::MethodHandler callback;
130 const AI_IPC::MethodHandler &handler)
132 , path(method.object), interface(method.interface), name(method.name)
139 sd_bus_slot *matchSlot;
140 AI_IPC::SignalHandler callback;
143 const AI_IPC::SignalHandler &handler)
149 uint64_t mHandlerTag;
150 std::map<std::string, RegisteredMethod> mMethodHandlers;
151 std::map<std::string, RegisteredSignal> mSignalHandlers;
156 std::function<void()> func;
158 Executor(uint64_t t, std::function<
void()> &&f)
159 : tag(t), func(std::move(f))
163 mutable uint64_t mExecCounter;
164 uint64_t mLastExecTag;
166 mutable std::mutex mExecLock;
167 mutable std::condition_variable mExecCond;
168 mutable std::deque< Executor > mExecQueue;
170 std::map< uint64_t, std::shared_ptr<SDBusAsyncReplyGetter> > mCalls;
171 std::map< uint32_t, sd_bus_message* > mCallReplies;
172 std::queue<uint32_t> mReplyIdentifiers;
IPC service that enables us to invoke remote method and emit signals as well as to handle incoming me...
Definition: IIpcService.h:42
Implements the IAsyncReplyGetter getter interface to provide an API to get the results to a method ca...
Definition: SDBusAsyncReplyGetter.h:35
Definition: SDBusAsyncReplySender.h:37
uid_t getSenderUid() const override
Get Id of the user (unix user Id) who invoked the method.
Definition: SDBusAsyncReplySender.cpp:80
Definition: SDBusIpcService.h:53
bool enableMonitor(const std::set< std::string > &matchRules, const AI_IPC::MonitorHandler &handler) override
Definition: SDBusIpcService.cpp:256
bool stop() override
Definition: SDBusIpcService.cpp:321
bool start() override
Definition: SDBusIpcService.cpp:294
std::string getBusAddress() const override
Definition: SDBusIpcService.cpp:392
std::string registerMethodHandler(const AI_IPC::Method &method, const AI_IPC::MethodHandler &handler) override
Definition: SDBusIpcService.cpp:636
bool emitSignal(const AI_IPC::Signal &signal, const AI_IPC::VariantList &args) override
Definition: SDBusIpcService.cpp:582
std::string registerSignalHandler(const AI_IPC::Signal &signal, const AI_IPC::SignalHandler &handler) override
Definition: SDBusIpcService.cpp:707
void flush() override
Definition: SDBusIpcService.cpp:282
bool isServiceAvailable(const std::string &serviceName) const override
Definition: SDBusIpcService.cpp:354
bool disableMonitor() override
Definition: SDBusIpcService.cpp:269
std::shared_ptr< AI_IPC::IAsyncReplyGetter > invokeMethod(const AI_IPC::Method &method, const AI_IPC::VariantList &args, int timeoutMs) override
Definition: SDBusIpcService.cpp:412
bool unregisterHandler(const std::string ®Id) override
Definition: SDBusIpcService.cpp:763
bool isValid() const override
Returns true if we initialised ourselves successfully.
Definition: SDBusIpcService.cpp:204
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
Definition: SDBusIpcService.h:154
Definition: SDBusIpcService.h:121
Definition: SDBusIpcService.h:138