sdbus-c++ 2.0.0
High-level C++ D-Bus library based on systemd D-Bus implementation
Loading...
Searching...
No Matches
IConnection.h
Go to the documentation of this file.
1
27#ifndef SDBUS_CXX_ICONNECTION_H_
28#define SDBUS_CXX_ICONNECTION_H_
29
31
32#include <chrono>
33#include <cstdint>
34#include <memory>
35#include <optional>
36#include <string>
37
38// Forward declarations
39struct sd_bus;
40struct sd_event;
41namespace sdbus {
42 class Message;
43 class ObjectPath;
44 class BusName;
45 using ServiceName = BusName;
46}
47
48namespace sdbus {
49
50 /********************************************/
61 {
62 public:
63 struct PollData;
64
65 virtual ~IConnection() = default;
66
75 virtual void enterEventLoop() = 0;
76
83 virtual void enterEventLoopAsync() = 0;
84
92 virtual void leaveEventLoop() = 0;
93
104 virtual void attachSdEventLoop(sd_event *event, int priority = 0) = 0;
105
111 virtual void detachSdEventLoop() = 0;
112
118 virtual sd_event *getSdEventLoop() = 0;
119
152 [[nodiscard]] virtual PollData getEventLoopPollData() const = 0;
153
176 virtual bool processPendingEvent() = 0;
177
191 [[nodiscard]] virtual Message getCurrentlyProcessedMessage() const = 0;
192
205 virtual void setMethodCallTimeout(uint64_t timeout) = 0;
206
210 template <typename _Rep, typename _Period>
211 void setMethodCallTimeout(const std::chrono::duration<_Rep, _Period>& timeout);
212
222 [[nodiscard]] virtual uint64_t getMethodCallTimeout() const = 0;
223
239 virtual void addObjectManager(const ObjectPath& objectPath) = 0;
240
257 [[nodiscard]] virtual Slot addObjectManager(const ObjectPath& objectPath, return_slot_t) = 0;
258
280 virtual void addMatch(const std::string& match, message_handler callback) = 0;
281
303 [[nodiscard]] virtual Slot addMatch(const std::string& match, message_handler callback, return_slot_t) = 0;
304
326 virtual void addMatchAsync(const std::string& match, message_handler callback, message_handler installCallback) = 0;
327
349 [[nodiscard]] virtual Slot addMatchAsync( const std::string& match
350 , message_handler callback
351 , message_handler installCallback
352 , return_slot_t ) = 0;
353
359 [[nodiscard]] virtual BusName getUniqueName() const = 0;
360
368 virtual void requestName(const ServiceName& name) = 0;
369
377 virtual void releaseName(const ServiceName& name) = 0;
378
386 struct PollData
387 {
391 int fd;
392
396 short int events;
397
403 std::chrono::microseconds timeout;
404
409
417 [[nodiscard]] std::chrono::microseconds getRelativeTimeout() const;
418
425 [[nodiscard]] int getPollTimeout() const;
426 };
427 };
428
429 template <typename _Rep, typename _Period>
430 inline void IConnection::setMethodCallTimeout(const std::chrono::duration<_Rep, _Period>& timeout)
431 {
432 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
433 return setMethodCallTimeout(microsecs.count());
434 }
435
443 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createBusConnection();
444
453 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createBusConnection(const ServiceName& name);
454
462 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSystemBusConnection();
463
472 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSystemBusConnection(const ServiceName& name);
473
481 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnection();
482
491 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnection(const ServiceName& name);
492
503 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnectionWithAddress(const std::string& address);
504
513 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createRemoteSystemBusConnection(const std::string& host);
514
523 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createDirectBusConnection(const std::string& address);
524
536 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createDirectBusConnection(int fd);
537
552 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createServerBus(int fd);
553
581 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createBusConnection(sd_bus *bus);
582}
583
584#endif /* SDBUS_CXX_ICONNECTION_H_ */
std::unique_ptr< sdbus::IConnection > createSessionBusConnection()
Creates/opens D-Bus session bus connection.
std::unique_ptr< sdbus::IConnection > createSystemBusConnection()
Creates/opens D-Bus system bus connection.
std::unique_ptr< sdbus::IConnection > createSessionBusConnectionWithAddress(const std::string &address)
Creates/opens D-Bus session bus connection at a custom address.
std::unique_ptr< sdbus::IConnection > createBusConnection()
Creates/opens D-Bus session bus connection when in a user context, and a system bus connection,...
std::unique_ptr< sdbus::IConnection > createRemoteSystemBusConnection(const std::string &host)
Creates/opens D-Bus system connection on a remote host using ssh.
std::unique_ptr< sdbus::IConnection > createDirectBusConnection(const std::string &address)
Opens direct D-Bus connection at a custom address.
std::unique_ptr< sdbus::IConnection > createServerBus(int fd)
Opens direct D-Bus connection at fd as a server.
Definition Types.h:197
Definition IConnection.h:61
virtual void detachSdEventLoop()=0
Detaches the bus connection from an sd-event event loop.
virtual BusName getUniqueName() const =0
Retrieves the unique name of a connection. E.g. ":1.xx".
virtual void attachSdEventLoop(sd_event *event, int priority=0)=0
Attaches the bus connection to an sd-event event loop.
virtual void releaseName(const ServiceName &name)=0
Releases an acquired well-known D-Bus service name on a bus.
virtual void leaveEventLoop()=0
Leaves the I/O event loop running on this bus connection.
virtual Slot addMatchAsync(const std::string &match, message_handler callback, message_handler installCallback, return_slot_t)=0
Asynchronously installs a match rule for messages received on this bus connection.
virtual Slot addObjectManager(const ObjectPath &objectPath, return_slot_t)=0
Adds an ObjectManager at the specified D-Bus object path.
virtual void setMethodCallTimeout(uint64_t timeout)=0
Sets general method call timeout.
virtual void enterEventLoop()=0
Enters I/O event loop on this bus connection.
virtual void requestName(const ServiceName &name)=0
Requests a well-known D-Bus service name on a bus.
virtual uint64_t getMethodCallTimeout() const =0
Gets general method call timeout.
virtual void addObjectManager(const ObjectPath &objectPath)=0
Adds an ObjectManager at the specified D-Bus object path.
virtual PollData getEventLoopPollData() const =0
Returns fd's, I/O events and timeout data to be used in an external event loop.
virtual Message getCurrentlyProcessedMessage() const =0
Provides access to the currently processed D-Bus message.
virtual void addMatch(const std::string &match, message_handler callback)=0
Installs a floating match rule for messages received on this bus connection.
virtual void enterEventLoopAsync()=0
Enters I/O event loop on this bus connection in a separate thread.
virtual void addMatchAsync(const std::string &match, message_handler callback, message_handler installCallback)=0
Asynchronously installs a floating match rule for messages received on this bus connection.
virtual bool processPendingEvent()=0
Processes a pending event.
virtual sd_event * getSdEventLoop()=0
Gets current sd-event event loop for the bus connection.
virtual Slot addMatch(const std::string &match, message_handler callback, return_slot_t)=0
Installs a match rule for messages received on this bus connection.
Definition Message.h:81
Definition Types.h:177
Definition IConnection.h:387
short int events
Definition IConnection.h:396
int eventFd
Definition IConnection.h:408
int fd
Definition IConnection.h:391
std::chrono::microseconds getRelativeTimeout() const
std::chrono::microseconds timeout
Definition IConnection.h:403
Definition TypeTraits.h:88