Loading...
Searching...
No Matches
IConnection.h
Go to the documentation of this file.
#ifndef SDBUS_CXX_ICONNECTION_H_
#define SDBUS_CXX_ICONNECTION_H_
#include <sdbus-c++/TypeTraits.h>
#include <chrono>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
// Forward declarations
struct sd_bus;
struct sd_event;
namespace sdbus {
class Message;
class ObjectPath;
class BusName;
using ServiceName = BusName;
}
namespace sdbus {
/********************************************/
class IConnection
{
public:
struct PollData;
virtual ~IConnection() = default;
virtual void enterEventLoop() = 0;
virtual void enterEventLoopAsync() = 0;
virtual void leaveEventLoop() = 0;
virtual void attachSdEventLoop(sd_event *event, int priority = 0) = 0;
virtual void detachSdEventLoop() = 0;
virtual sd_event *getSdEventLoop() = 0;
[[nodiscard]] virtual PollData getEventLoopPollData() const = 0;
virtual bool processPendingEvent() = 0;
[[nodiscard]] virtual Message getCurrentlyProcessedMessage() const = 0;
virtual void setMethodCallTimeout(uint64_t timeout) = 0;
template <typename _Rep, typename _Period>
void setMethodCallTimeout(const std::chrono::duration<_Rep, _Period>& timeout);
[[nodiscard]] virtual uint64_t getMethodCallTimeout() const = 0;
virtual void addObjectManager(const ObjectPath& objectPath) = 0;
[[nodiscard]] virtual Slot addObjectManager(const ObjectPath& objectPath, return_slot_t) = 0;
virtual void addMatch(const std::string& match, message_handler callback) = 0;
[[nodiscard]] virtual Slot addMatch(const std::string& match, message_handler callback, return_slot_t) = 0;
virtual void addMatchAsync(const std::string& match, message_handler callback, message_handler installCallback) = 0;
[[nodiscard]] virtual Slot addMatchAsync( const std::string& match
, message_handler callback
, message_handler installCallback
, return_slot_t ) = 0;
[[nodiscard]] virtual BusName getUniqueName() const = 0;
virtual void requestName(const ServiceName& name) = 0;
virtual void releaseName(const ServiceName& name) = 0;
struct PollData
{
int fd;
short int events;
std::chrono::microseconds timeout;
int eventFd;
[[nodiscard]] std::chrono::microseconds getRelativeTimeout() const;
[[nodiscard]] int getPollTimeout() const;
};
};
template <typename _Rep, typename _Period>
inline void IConnection::setMethodCallTimeout(const std::chrono::duration<_Rep, _Period>& timeout)
{
auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
return setMethodCallTimeout(microsecs.count());
}
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createBusConnection();
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createBusConnection(const ServiceName& name);
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createSystemBusConnection();
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createSystemBusConnection(const ServiceName& name);
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnection();
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnection(const ServiceName& name);
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createSessionBusConnectionWithAddress(const std::string& address);
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createRemoteSystemBusConnection(const std::string& host);
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createDirectBusConnection(const std::string& address);
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createDirectBusConnection(int fd);
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createServerBus(int fd);
[[nodiscard]] std::unique_ptr<sdbus::IConnection> createBusConnection(sd_bus *bus);
}
#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::createBusConnection
std::unique_ptr< sdbus::IConnection > createBusConnection()
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::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.
TypeTraits.h
sdbus::BusName
Definition Types.h:215
sdbus::IConnection
Definition IConnection.h:61
sdbus::IConnection::detachSdEventLoop
virtual void detachSdEventLoop()=0
Attaches the bus connection to an sd-event event loop.
sdbus::IConnection::getUniqueName
virtual BusName getUniqueName() const =0
Asynchronously installs a floating match rule for messages received on this bus connection.
sdbus::IConnection::releaseName
virtual void releaseName(const ServiceName &name)=0
Releases an acquired well-known D-Bus service name on a bus.
sdbus::IConnection::leaveEventLoop
virtual void leaveEventLoop()=0
Leaves the I/O event loop running on this bus connection.
sdbus::IConnection::addObjectManager
virtual Slot addObjectManager(const ObjectPath &objectPath, return_slot_t)=0
Adds an ObjectManager at the specified D-Bus object path.
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::requestName
virtual void requestName(const ServiceName &name)=0
Requests a well-known D-Bus service name on a bus.
sdbus::IConnection::getMethodCallTimeout
virtual uint64_t getMethodCallTimeout() const =0
Gets general method call timeout.
sdbus::IConnection::addObjectManager
virtual void addObjectManager(const ObjectPath &objectPath)=0
Adds an ObjectManager at the specified D-Bus object path.
sdbus::IConnection::getEventLoopPollData
virtual PollData getEventLoopPollData() const =0
Returns fd's, I/O events and timeout data to be used in an external event loop.
sdbus::IConnection::getCurrentlyProcessedMessage
virtual Message getCurrentlyProcessedMessage() const =0
Provides access to the currently processed D-Bus message.
sdbus::IConnection::addMatch
virtual void addMatch(const std::string &match, message_handler callback)=0
Installs a floating match rule for messages received on this bus connection.
sdbus::IConnection::enterEventLoopAsync
virtual void enterEventLoopAsync()=0
Enters I/O event loop on this bus connection in a separate thread.
sdbus::IConnection::processPendingEvent
virtual bool processPendingEvent()=0
Processes a pending event.
sdbus::IConnection::getSdEventLoop
virtual sd_event * getSdEventLoop()=0
Gets current sd-event event loop for the bus connection.
sdbus::IConnection::addMatch
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.
sdbus::Message
Definition Message.h:81
sdbus::ObjectPath
Definition Types.h:195
sdbus::IConnection::PollData
Definition IConnection.h:387
sdbus::IConnection::PollData::events
short int events
Definition IConnection.h:396
sdbus::IConnection::PollData::eventFd
int eventFd
Definition IConnection.h:408
sdbus::IConnection::PollData::getPollTimeout
int getPollTimeout() const
sdbus::IConnection::PollData::fd
int fd
Definition IConnection.h:391
sdbus::IConnection::PollData::getRelativeTimeout
std::chrono::microseconds getRelativeTimeout() const
sdbus::IConnection::PollData::timeout
std::chrono::microseconds timeout
Definition IConnection.h:403
sdbus::return_slot_t
Definition TypeTraits.h:88