sdbus-c++: include/sdbus-c++/IConnection.h Source File

sdbus-c++ 1.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
27#ifndef SDBUS_CXX_ICONNECTION_H_
28#define SDBUS_CXX_ICONNECTION_H_
29
30#include <sdbus-c++/TypeTraits.h>
31#include <string>
32#include <memory>
33#include <chrono>
34#include <cstdint>
35#include <optional>
36
37struct sd_bus;
38
39namespace sdbus {
40
41 /********************************************/
51 class IConnection
52 {
53 public:
67 struct PollData
68 {
72 int fd;
76 short int events;
77
81 uint64_t timeout_usec;
82
90 [[nodiscard]] std::chrono::microseconds getAbsoluteTimeout() const
91 {
92 return std::chrono::microseconds(timeout_usec);
93 }
94
100 [[nodiscard]] std::optional<std::chrono::microseconds> getRelativeTimeout() const;
101
108 [[nodiscard]] int getPollTimeout() const;
109 };
110
111 virtual ~IConnection() = default;
112
120 virtual void requestName(const std::string& name) = 0;
121
129 virtual void releaseName(const std::string& name) = 0;
130
136 virtual std::string getUniqueName() const = 0;
137
146 virtual void enterEventLoop() = 0;
147
154 virtual void enterEventLoopAsync() = 0;
155
163 virtual void leaveEventLoop() = 0;
164
180 [[deprecated("Use one of other addObjectManager overloads")]] virtual void addObjectManager(const std::string& objectPath) = 0;
181
200 virtual PollData getEventLoopPollData() const = 0;
201
220 virtual bool processPendingRequest() = 0;
221
234 virtual void setMethodCallTimeout(uint64_t timeout) = 0;
235
239 template <typename _Rep, typename _Period>
240 void setMethodCallTimeout(const std::chrono::duration<_Rep, _Period>& timeout);
241
251 virtual uint64_t getMethodCallTimeout() const = 0;
252
268 virtual void addObjectManager(const std::string& objectPath, floating_slot_t) = 0;
269
291 [[nodiscard]] virtual Slot addMatch(const std::string& match, message_handler callback) = 0;
292
308 virtual void addMatch(const std::string& match, message_handler callback, floating_slot_t) = 0;
309
315 [[deprecated("This function has been replaced by enterEventLoop()")]] void enterProcessingLoop();
316
322 [[deprecated("This function has been replaced by enterEventLoopAsync()")]] void enterProcessingLoopAsync();
323
329 [[deprecated("This function has been replaced by leaveEventLoop()")]] void leaveProcessingLoop();
330
336 [[deprecated("This function has been replaced by getEventLoopPollData()")]] PollData getProcessLoopPollData() const;
337 };
338
339 template <typename _Rep, typename _Period>
340 inline void IConnection::setMethodCallTimeout(const std::chrono::duration<_Rep, _Period>& timeout)
341 {
342 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
343 return setMethodCallTimeout(microsecs.count());
344 }
345
346 inline void IConnection::enterProcessingLoop()
347 {
348 enterEventLoop();
349 }
350
351 inline void IConnection::enterProcessingLoopAsync()
352 {
353 enterEventLoopAsync();
354 }
355
356 inline void IConnection::leaveProcessingLoop()
357 {
358 leaveEventLoop();
359 }
360
361 inline IConnection::PollData IConnection::getProcessLoopPollData() const
362 {
363 return getEventLoopPollData();
364 }
365
373 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createConnection();
374
383 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createConnection(const std::string& name);
384
392 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createDefaultBusConnection();
393
402 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createDefaultBusConnection(const std::string& name);
403
411 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSystemBusConnection();
412
421 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSystemBusConnection(const std::string& name);
422
430 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnection();
431
440 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnection(const std::string& name);
441
452 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnectionWithAddress(const std::string& address);
453
462 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createRemoteSystemBusConnection(const std::string& host);
463
472 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createDirectBusConnection(const std::string& address);
473
485 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createDirectBusConnection(int fd);
486
501 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createServerBus(int fd);
502
530 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createBusConnection(sd_bus *bus);
531}
532
533#endif /* SDBUS_CXX_ICONNECTION_H_ */
sdbus::createSessionBusConnection
std::unique_ptr< sdbus::IConnection > createSessionBusConnection()
Creates/opens D-Bus session bus connection.
sdbus::createSystemBusConnection
std::unique_ptr< sdbus::IConnection > createSystemBusConnection()
Creates/opens D-Bus system bus connection.
sdbus::createSessionBusConnectionWithAddress
std::unique_ptr< sdbus::IConnection > createSessionBusConnectionWithAddress(const std::string &address)
Creates/opens D-Bus session bus connection at a custom address.
sdbus::createDefaultBusConnection
std::unique_ptr< sdbus::IConnection > createDefaultBusConnection()
Creates/opens D-Bus session bus connection when in a user context, and a system bus connection,...
sdbus::createBusConnection
std::unique_ptr< sdbus::IConnection > createBusConnection(sd_bus *bus)
Creates sdbus-c++ bus connection representation out of underlying sd_bus instance.
sdbus::createRemoteSystemBusConnection
std::unique_ptr< sdbus::IConnection > createRemoteSystemBusConnection(const std::string &host)
Creates/opens D-Bus system connection on a remote host using ssh.
sdbus::createDirectBusConnection
std::unique_ptr< sdbus::IConnection > createDirectBusConnection(const std::string &address)
Opens direct D-Bus connection at a custom address.
sdbus::createServerBus
std::unique_ptr< sdbus::IConnection > createServerBus(int fd)
Opens direct D-Bus connection at fd as a server.
sdbus::createConnection
std::unique_ptr< sdbus::IConnection > createConnection()
Creates/opens D-Bus system bus connection.
TypeTraits.h
sdbus::IConnection
Definition IConnection.h:52
sdbus::IConnection::leaveProcessingLoop
void leaveProcessingLoop()
Leaves the I/O event loop running on this bus connection.
Definition IConnection.h:356
sdbus::IConnection::enterProcessingLoop
void enterProcessingLoop()
Enters I/O event loop on this bus connection.
Definition IConnection.h:346
sdbus::IConnection::releaseName
virtual void releaseName(const std::string &name)=0
Releases D-Bus name on the connection.
sdbus::IConnection::leaveEventLoop
virtual void leaveEventLoop()=0
Leaves the I/O event loop running on this bus connection.
sdbus::IConnection::processPendingRequest
virtual bool processPendingRequest()=0
Process a pending request.
sdbus::IConnection::requestName
virtual void requestName(const std::string &name)=0
Requests D-Bus name on the connection.
sdbus::IConnection::addObjectManager
virtual void addObjectManager(const std::string &objectPath)=0
Adds an ObjectManager at the specified D-Bus object path.
sdbus::IConnection::getUniqueName
virtual std::string getUniqueName() const =0
Retrieve the unique name of a connection. E.g. ":1.xx".
sdbus::IConnection::setMethodCallTimeout
virtual void setMethodCallTimeout(uint64_t timeout)=0
Sets general method call timeout.
sdbus::IConnection::enterEventLoop
virtual void enterEventLoop()=0
Enters I/O event loop on this bus connection.
sdbus::IConnection::getMethodCallTimeout
virtual uint64_t getMethodCallTimeout() const =0
Gets general method call timeout.
sdbus::IConnection::addObjectManager
virtual void addObjectManager(const std::string &objectPath, floating_slot_t)=0
Adds an ObjectManager at the specified D-Bus object path.
sdbus::IConnection::getEventLoopPollData
virtual PollData getEventLoopPollData() const =0
Returns fd, I/O events and timeout data you can pass to poll.
sdbus::IConnection::addMatch
virtual void addMatch(const std::string &match, message_handler callback, floating_slot_t)=0
Adds a floating match rule for incoming message dispatching.
sdbus::IConnection::enterEventLoopAsync
virtual void enterEventLoopAsync()=0
Enters I/O event loop on this bus connection in a separate thread.
sdbus::IConnection::getProcessLoopPollData
PollData getProcessLoopPollData() const
Returns fd, I/O events and timeout data you can pass to poll.
Definition IConnection.h:361
sdbus::IConnection::enterProcessingLoopAsync
void enterProcessingLoopAsync()
Enters I/O event loop on this bus connection in a separate thread.
Definition IConnection.h:351
sdbus::IConnection::addMatch
virtual Slot addMatch(const std::string &match, message_handler callback)=0
Adds a match rule for incoming message dispatching.
sdbus::IConnection::PollData
Definition IConnection.h:68
sdbus::IConnection::PollData::events
short int events
Definition IConnection.h:76
sdbus::IConnection::PollData::getRelativeTimeout
std::optional< std::chrono::microseconds > getRelativeTimeout() const
sdbus::IConnection::PollData::timeout_usec
uint64_t timeout_usec
Definition IConnection.h:81
sdbus::IConnection::PollData::getPollTimeout
int getPollTimeout() const
sdbus::IConnection::PollData::fd
int fd
Definition IConnection.h:72
sdbus::IConnection::PollData::getAbsoluteTimeout
std::chrono::microseconds getAbsoluteTimeout() const
Definition IConnection.h:90
sdbus::floating_slot_t
Definition TypeTraits.h:78