Loading...
Searching...
No Matches
AdaptorInterfaces.h
Go to the documentation of this file.
#ifndef SDBUS_CXX_ADAPTORINTERFACES_H_
#define SDBUS_CXX_ADAPTORINTERFACES_H_
#include <sdbus-c++/IObject.h>
#include <cassert>
#include <string>
#include <memory>
// Forward declarations
namespace sdbus {
class IConnection;
}
namespace sdbus {
/********************************************/
class ObjectHolder
{
protected:
ObjectHolder(std::unique_ptr<IObject>&& object)
: object_(std::move(object))
{
}
const IObject& getObject() const
{
assert(object_ != nullptr);
return *object_;
}
IObject& getObject()
{
assert(object_ != nullptr);
return *object_;
}
private:
std::unique_ptr<IObject> object_;
};
/********************************************/
template <typename... _Interfaces>
class AdaptorInterfaces
: protected ObjectHolder
, public _Interfaces...
{
public:
AdaptorInterfaces(IConnection& connection, ObjectPath objectPath)
: ObjectHolder(createObject(connection, std::move(objectPath)))
, _Interfaces(getObject())...
{
}
void registerAdaptor()
{
(_Interfaces::registerAdaptor(), ...);
}
void unregisterAdaptor()
{
getObject().unregister();
}
using ObjectHolder::getObject;
protected:
using base_type = AdaptorInterfaces;
AdaptorInterfaces(const AdaptorInterfaces&) = delete;
AdaptorInterfaces& operator=(const AdaptorInterfaces&) = delete;
AdaptorInterfaces(AdaptorInterfaces&&) = delete;
AdaptorInterfaces& operator=(AdaptorInterfaces&&) = delete;
~AdaptorInterfaces() = default;
};
}
#endif /* SDBUS_CXX_ADAPTORINTERFACES_H_ */
IObject.h
sdbus::createObject
std::unique_ptr< sdbus::IObject > createObject(sdbus::IConnection &connection, ObjectPath objectPath)
Creates instance representing a D-Bus object.
sdbus::IConnection
Definition IConnection.h:61