Loading...
Searching...
No Matches
ProxyInterfaces.h
Go to the documentation of this file.
#ifndef SDBUS_CXX_PROXYINTERFACES_H_
#define SDBUS_CXX_PROXYINTERFACES_H_
#include <sdbus-c++/IProxy.h>
#include <cassert>
#include <string>
#include <memory>
// Forward declarations
namespace sdbus {
class IConnection;
}
namespace sdbus {
/********************************************/
class ProxyObjectHolder
{
protected:
ProxyObjectHolder(std::unique_ptr<IProxy>&& proxy)
: proxy_(std::move(proxy))
{
assert(proxy_ != nullptr);
}
const IProxy& getProxy() const
{
assert(proxy_ != nullptr);
return *proxy_;
}
IProxy& getProxy()
{
assert(proxy_ != nullptr);
return *proxy_;
}
private:
std::unique_ptr<IProxy> proxy_;
};
/********************************************/
template <typename... _Interfaces>
class ProxyInterfaces
: protected ProxyObjectHolder
, public _Interfaces...
{
public:
ProxyInterfaces(ServiceName destination, ObjectPath objectPath)
: ProxyObjectHolder(createProxy(std::move(destination), std::move(objectPath)))
, _Interfaces(getProxy())...
{
}
ProxyInterfaces(ServiceName destination, ObjectPath objectPath, dont_run_event_loop_thread_t)
: ProxyObjectHolder(createProxy(std::move(destination), std::move(objectPath), dont_run_event_loop_thread))
, _Interfaces(getProxy())...
{
}
ProxyInterfaces(IConnection& connection, ServiceName destination, ObjectPath objectPath)
: ProxyObjectHolder(createProxy(connection, std::move(destination), std::move(objectPath)))
, _Interfaces(getProxy())...
{
}
ProxyInterfaces(std::unique_ptr<sdbus::IConnection>&& connection, ServiceName destination, ObjectPath objectPath)
: ProxyObjectHolder(createProxy(std::move(connection), std::move(destination), std::move(objectPath)))
, _Interfaces(getProxy())...
{
}
ProxyInterfaces(std::unique_ptr<sdbus::IConnection>&& connection, ServiceName destination, ObjectPath objectPath, dont_run_event_loop_thread_t)
: ProxyObjectHolder(createProxy(std::move(connection), std::move(destination), std::move(objectPath), dont_run_event_loop_thread))
, _Interfaces(getProxy())...
{
}
void registerProxy()
{
(_Interfaces::registerProxy(), ...);
}
void unregisterProxy()
{
getProxy().unregister();
}
using ProxyObjectHolder::getProxy;
protected:
using base_type = ProxyInterfaces;
ProxyInterfaces(const ProxyInterfaces&) = delete;
ProxyInterfaces& operator=(const ProxyInterfaces&) = delete;
ProxyInterfaces(ProxyInterfaces&&) = delete;
ProxyInterfaces& operator=(ProxyInterfaces&&) = delete;
~ProxyInterfaces() = default;
};
}
#endif /* SDBUS_CXX_INTERFACES_H_ */
IProxy.h
sdbus::createProxy
std::unique_ptr< sdbus::IProxy > createProxy(sdbus::IConnection &connection, ServiceName destination, ObjectPath objectPath)
Creates a proxy object for a specific remote D-Bus object.
sdbus::IConnection
Definition IConnection.h:61
sdbus::IProxy
Definition IProxy.h:69
sdbus::IProxy::unregister
virtual void unregister()=0
Unregisters proxy's signal handlers and stops receiving replies to pending async calls.
sdbus::ObjectPath
Definition Types.h:195
sdbus::ProxyInterfaces
Definition ProxyInterfaces.h:96
sdbus::ProxyInterfaces::unregisterProxy
void unregisterProxy()
Unregisters the proxy so it no more receives signals and async call replies.
Definition ProxyInterfaces.h:195
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(std::unique_ptr< sdbus::IConnection > &&connection, ServiceName destination, ObjectPath objectPath, dont_run_event_loop_thread_t)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:170
sdbus::ProxyInterfaces::registerProxy
void registerProxy()
Registers handlers for D-Bus signals of the remote object.
Definition ProxyInterfaces.h:183
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(ServiceName destination, ObjectPath objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:107
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(ServiceName destination, ObjectPath objectPath, dont_run_event_loop_thread_t)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:122
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(IConnection &connection, ServiceName destination, ObjectPath objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:138
sdbus::ProxyInterfaces::ProxyInterfaces
ProxyInterfaces(std::unique_ptr< sdbus::IConnection > &&connection, ServiceName destination, ObjectPath objectPath)
Creates native-like proxy object instance.
Definition ProxyInterfaces.h:154
sdbus::ProxyInterfaces::getProxy
const IProxy & getProxy() const
Returns reference to the underlying IProxy instance.
Definition ProxyInterfaces.h:60
sdbus::dont_run_event_loop_thread_t
Definition TypeTraits.h:101