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

sdbus-c++ 1.3.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
37namespace sdbus {
38
39 /********************************************/
49 class IConnection
50 {
51 public:
65 struct PollData
66 {
70 int fd;
74 short int events;
75
79 uint64_t timeout_usec;
80
88 [[nodiscard]] std::chrono::microseconds getAbsoluteTimeout() const
89 {
90 return std::chrono::microseconds(timeout_usec);
91 }
92
98 [[nodiscard]] std::optional<std::chrono::microseconds> getRelativeTimeout() const;
99
106 [[nodiscard]] int getPollTimeout() const;
107 };
108
109 virtual ~IConnection() = default;
110
118 virtual void requestName(const std::string& name) = 0;
119
127 virtual void releaseName(const std::string& name) = 0;
128
134 virtual std::string getUniqueName() const = 0;
135
144 virtual void enterEventLoop() = 0;
145
152 virtual void enterEventLoopAsync() = 0;
153
161 virtual void leaveEventLoop() = 0;
162
178 [[deprecated("Use one of other addObjectManager overloads")]] virtual void addObjectManager(const std::string& objectPath) = 0;
179
198 virtual PollData getEventLoopPollData() const = 0;
199
218 virtual bool processPendingRequest() = 0;
219
232 virtual void setMethodCallTimeout(uint64_t timeout) = 0;
233
237 template <typename _Rep, typename _Period>
238 void setMethodCallTimeout(const std::chrono::duration<_Rep, _Period>& timeout);
239
249 virtual uint64_t getMethodCallTimeout() const = 0;
250
266 virtual void addObjectManager(const std::string& objectPath, floating_slot_t) = 0;
267
289 [[nodiscard]] virtual Slot addMatch(const std::string& match, message_handler callback) = 0;
290
306 virtual void addMatch(const std::string& match, message_handler callback, floating_slot_t) = 0;
307
313 [[deprecated("This function has been replaced by enterEventLoop()")]] void enterProcessingLoop();
314
320 [[deprecated("This function has been replaced by enterEventLoopAsync()")]] void enterProcessingLoopAsync();
321
327 [[deprecated("This function has been replaced by leaveEventLoop()")]] void leaveProcessingLoop();
328
334 [[deprecated("This function has been replaced by getEventLoopPollData()")]] PollData getProcessLoopPollData() const;
335 };
336
337 template <typename _Rep, typename _Period>
338 inline void IConnection::setMethodCallTimeout(const std::chrono::duration<_Rep, _Period>& timeout)
339 {
340 auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
341 return setMethodCallTimeout(microsecs.count());
342 }
343
344 inline void IConnection::enterProcessingLoop()
345 {
346 enterEventLoop();
347 }
348
349 inline void IConnection::enterProcessingLoopAsync()
350 {
351 enterEventLoopAsync();
352 }
353
354 inline void IConnection::leaveProcessingLoop()
355 {
356 leaveEventLoop();
357 }
358
359 inline IConnection::PollData IConnection::getProcessLoopPollData() const
360 {
361 return getEventLoopPollData();
362 }
363
371 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createConnection();
372
381 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createConnection(const std::string& name);
382
390 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createDefaultBusConnection();
391
400 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createDefaultBusConnection(const std::string& name);
401
409 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSystemBusConnection();
410
419 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSystemBusConnection(const std::string& name);
420
428 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnection();
429
438 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnection(const std::string& name);
439
450 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnectionWithAddress(const std::string& address);
451
460 [[nodiscard]] std::unique_ptr<sdbus::IConnection> createRemoteSystemBusConnection(const std::string& host);
461}
462
463#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::createRemoteSystemBusConnection
std::unique_ptr< sdbus::IConnection > createRemoteSystemBusConnection(const std::string &host)
Creates/opens D-Bus system connection on a remote host using ssh.
sdbus::createConnection
std::unique_ptr< sdbus::IConnection > createConnection()
Creates/opens D-Bus system bus connection.
TypeTraits.h
sdbus::IConnection
Definition IConnection.h:50
sdbus::IConnection::leaveProcessingLoop
void leaveProcessingLoop()
Leaves the I/O event loop running on this bus connection.
Definition IConnection.h:354
sdbus::IConnection::enterProcessingLoop
void enterProcessingLoop()
Enters I/O event loop on this bus connection.
Definition IConnection.h:344
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:359
sdbus::IConnection::enterProcessingLoopAsync
void enterProcessingLoopAsync()
Enters I/O event loop on this bus connection in a separate thread.
Definition IConnection.h:349
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:66
sdbus::IConnection::PollData::events
short int events
Definition IConnection.h:74
sdbus::IConnection::PollData::getRelativeTimeout
std::optional< std::chrono::microseconds > getRelativeTimeout() const
sdbus::IConnection::PollData::timeout_usec
uint64_t timeout_usec
Definition IConnection.h:79
sdbus::IConnection::PollData::getPollTimeout
int getPollTimeout() const
sdbus::IConnection::PollData::fd
int fd
Definition IConnection.h:70
sdbus::IConnection::PollData::getAbsoluteTimeout
std::chrono::microseconds getAbsoluteTimeout() const
Definition IConnection.h:88
sdbus::floating_slot_t
Definition TypeTraits.h:78