sdbus-c++ 2.4.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
26
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 class Track;
47} // namespace sdbus
48
49namespace sdbus {
50
51 /********************************************/
62 {
63 public:
64 struct PollData;
65
66 virtual ~IConnection() = default;
67
76 virtual void enterEventLoop() = 0;
77
84 virtual void enterEventLoopAsync() = 0;
85
93 virtual void leaveEventLoop() = 0;
94
105 virtual void attachSdEventLoop(sd_event *event, int priority = 0) = 0;
106
112 virtual void detachSdEventLoop() = 0;
113
119 virtual sd_event *getSdEventLoop() = 0;
120
153 [[nodiscard]] virtual PollData getEventLoopPollData() const = 0;
154
177 virtual bool processPendingEvent() = 0;
178
192 [[nodiscard]] virtual Message getCurrentlyProcessedMessage() const = 0;
193
206 virtual void setMethodCallTimeout(uint64_t timeout) = 0;
207
211 template <typename Rep, typename Period>
212 void setMethodCallTimeout(const std::chrono::duration<Rep, Period>& timeout);
213
223 [[nodiscard]] virtual uint64_t getMethodCallTimeout() const = 0;
224
240 virtual void addObjectManager(const ObjectPath& objectPath) = 0;
241
258 [[nodiscard]] virtual Slot addObjectManager(const ObjectPath& objectPath, return_slot_t) = 0;
259
281 virtual void addMatch(const std::string& match, message_handler callback) = 0;
282
304 [[nodiscard]] virtual Slot addMatch(const std::string& match, message_handler callback, return_slot_t) = 0;
305
327 virtual void addMatchAsync(const std::string& match, message_handler callback, message_handler installCallback) = 0;
328
350 [[nodiscard]] virtual Slot addMatchAsync( const std::string& match
351 , message_handler callback
352 , message_handler installCallback
353 , return_slot_t ) = 0;
354
360 [[nodiscard]] virtual BusName getUniqueName() const = 0;
361
369 virtual void requestName(const ServiceName& name) = 0;
370
378 virtual void releaseName(const ServiceName& name) = 0;
379
387 struct PollData
388 {
392 int fd;
393
397 short int events;
398
404 std::chrono::microseconds timeout;
405
410
418 [[nodiscard]] std::chrono::microseconds getRelativeTimeout() const;
419
426 [[nodiscard]] int getPollTimeout() const;
427 };
428
429 // New virtual functions in sdbus-c++ v2, appended at the end of the class for ABI compatibility
457 [[nodiscard]] virtual Track createTrack(track_handler onEmpty) = 0;
458 };
459
460 template <typename Rep, typename Period>
461 inline void IConnection::setMethodCallTimeout(const std::chrono::duration<Rep, Period>& timeout)
462 {
463 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
464 return setMethodCallTimeout(microsecs.count());
465 }
466
474 [[nodiscard]] std::unique_ptr<IConnection> createBusConnection();
475
484 [[nodiscard]] std::unique_ptr<IConnection> createBusConnection(const ServiceName& name);
485
493 [[nodiscard]] std::unique_ptr<IConnection> createSystemBusConnection();
494
503 [[nodiscard]] std::unique_ptr<IConnection> createSystemBusConnection(const ServiceName& name);
504
512 [[nodiscard]] std::unique_ptr<IConnection> createSessionBusConnection();
513
522 [[nodiscard]] std::unique_ptr<IConnection> createSessionBusConnection(const ServiceName& name);
523
534 [[nodiscard]] std::unique_ptr<IConnection> createSessionBusConnectionWithAddress(const std::string& address);
535
544 [[nodiscard]] std::unique_ptr<IConnection> createRemoteSystemBusConnection(const std::string& host);
545
554 [[nodiscard]] std::unique_ptr<IConnection> createDirectBusConnection(const std::string& address);
555
567 [[nodiscard]] std::unique_ptr<IConnection> createDirectBusConnection(int fd);
568
583 [[nodiscard]] std::unique_ptr<IConnection> createServerBus(int fd);
584
612 [[nodiscard]] std::unique_ptr<IConnection> createBusConnection(sd_bus *bus);
613} // namespace sdbus
614
615#endif /* SDBUS_CXX_ICONNECTION_H_ */
std::unique_ptr< IConnection > createBusConnection()
Creates/opens D-Bus session bus connection when in a user context, and a system bus connection,...
std::unique_ptr< IConnection > createSystemBusConnection()
Creates/opens D-Bus system bus connection.
std::unique_ptr< IConnection > createSessionBusConnection()
Creates/opens D-Bus session bus connection.
std::unique_ptr< IConnection > createServerBus(int fd)
Opens direct D-Bus connection at fd as a server.
std::unique_ptr< IConnection > createDirectBusConnection(const std::string &address)
Opens direct D-Bus connection at a custom address.
std::unique_ptr< IConnection > createRemoteSystemBusConnection(const std::string &host)
Creates/opens D-Bus system connection on a remote host using ssh.
std::unique_ptr< IConnection > createSessionBusConnectionWithAddress(const std::string &address)
Creates/opens D-Bus session bus connection at a custom address.
Definition Types.h:228
Definition IConnection.h:62
virtual void detachSdEventLoop()=0
Attaches the bus connection to a sd-event event loop.
virtual BusName getUniqueName() const =0
Asynchronously installs a floating match rule for messages received on this bus connection.
virtual Track createTrack(track_handler onEmpty)=0
Creates a track object for tracking D-Bus peers on this connection.
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 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 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:82
Definition Types.h:208
Definition Track.h:67
Definition IConnection.h:388
short int events
Definition IConnection.h:397
int eventFd
Definition IConnection.h:409
int fd
Definition IConnection.h:392
std::chrono::microseconds getRelativeTimeout() const
std::chrono::microseconds timeout
Definition IConnection.h:404
Definition TypeTraits.h:90