Loading...
Searching...
No Matches
IObject.h
Go to the documentation of this file.
#ifndef SDBUS_CXX_IOBJECT_H_
#define SDBUS_CXX_IOBJECT_H_
#include <sdbus-c++/ConvenienceApiClasses.h>
#include <sdbus-c++/Flags.h>
#include <sdbus-c++/TypeTraits.h>
#include <sdbus-c++/VTableItems.h>
#include <functional>
#include <memory>
#include <string>
#include <vector>
// Forward declarations
namespace sdbus {
class Signal;
class IConnection;
class ObjectPath;
} // namespace sdbus
namespace sdbus {
/********************************************/
class IObject
{
public: // High-level, convenience API
virtual ~IObject() = default;
[[nodiscard]] VTableAdder addVTable(std::vector<VTableItem> vtable);
template < typename... VTableItems
, typename = std::enable_if_t<(is_one_of_variants_types<VTableItem, std::decay_t<VTableItems>> && ...)> > // NOLINT(modernize-use-constraints): We are C++17 compatible at the moment
[[nodiscard]] VTableAdder addVTable(VTableItems&&... items);
[[nodiscard]] SignalEmitter emitSignal(const SignalName& signalName);
[[nodiscard]] SignalEmitter emitSignal(const std::string& signalName);
[[nodiscard]] SignalEmitter emitSignal(const char* signalName);
virtual void emitPropertiesChangedSignal(const InterfaceName& interfaceName, const std::vector<PropertyName>& propNames) = 0;
virtual void emitPropertiesChangedSignal(const char* interfaceName, const std::vector<PropertyName>& propNames) = 0;
virtual void emitPropertiesChangedSignal(const InterfaceName& interfaceName) = 0;
virtual void emitPropertiesChangedSignal(const char* interfaceName) = 0;
virtual void emitInterfacesAddedSignal() = 0;
virtual void emitInterfacesAddedSignal(const std::vector<InterfaceName>& interfaces) = 0;
virtual void emitInterfacesRemovedSignal() = 0;
virtual void emitInterfacesRemovedSignal(const std::vector<InterfaceName>& interfaces) = 0;
virtual void addObjectManager() = 0;
[[nodiscard]] virtual Slot addObjectManager(return_slot_t) = 0;
[[nodiscard]] virtual sdbus::IConnection& getConnection() const = 0;
[[nodiscard]] virtual const ObjectPath& getObjectPath() const = 0;
[[nodiscard]] virtual Message getCurrentlyProcessedMessage() const = 0;
virtual void unregister() = 0;
// Lower-level, message-based API
template < typename... VTableItems
, typename = std::enable_if_t<(is_one_of_variants_types<VTableItem, std::decay_t<VTableItems>> && ...)> >
void addVTable(InterfaceName interfaceName, VTableItems&&... items);
virtual void addVTable(InterfaceName interfaceName, std::vector<VTableItem> vtable) = 0;
[[nodiscard]] virtual Slot addVTable(InterfaceName interfaceName, std::vector<VTableItem> vtable, return_slot_t) = 0;
[[nodiscard]] virtual Signal createSignal(const InterfaceName& interfaceName, const SignalName& signalName) const = 0;
virtual void emitSignal(const Signal& message) = 0;
protected: // Internal API for efficiency reasons used by high-level API helper classes
friend SignalEmitter;
[[nodiscard]] virtual Signal createSignal(const char* interfaceName, const char* signalName) const = 0;
};
// Out-of-line member definitions
inline SignalEmitter IObject::emitSignal(const SignalName& signalName)
{
return {*this, signalName};
}
inline SignalEmitter IObject::emitSignal(const std::string& signalName)
{
return {*this, signalName.c_str()};
}
inline SignalEmitter IObject::emitSignal(const char* signalName)
{
return {*this, signalName};
}
template <typename... VTableItems, typename>
void IObject::addVTable(InterfaceName interfaceName, VTableItems&&... items)
{
addVTable(std::move(interfaceName), {std::forward<VTableItems>(items)...});
}
template <typename... VTableItems, typename>
VTableAdder IObject::addVTable(VTableItems&&... items)
{
return addVTable(std::vector<VTableItem>{std::forward<VTableItems>(items)...});
}
inline VTableAdder IObject::addVTable(std::vector<VTableItem> vtable)
{
return {*this, std::move(vtable)};
}
[[nodiscard]] std::unique_ptr<IObject> createObject(IConnection& connection, ObjectPath objectPath);
} // namespace sdbus
#include <sdbus-c++/ConvenienceApiClasses.inl> // NOLINT(misc-header-include-cycle)
#include <sdbus-c++/VTableItems.inl>
#endif /* SDBUS_CXX_IOBJECT_H_ */
ConvenienceApiClasses.h
ConvenienceApiClasses.inl
Flags.h
sdbus::createObject
std::unique_ptr< IObject > createObject(IConnection &connection, ObjectPath objectPath)
Creates instance representing a D-Bus object.
TypeTraits.h
VTableItems.h
VTableItems.inl
sdbus::IConnection
Definition IConnection.h:61
sdbus::IObject
Definition IObject.h:63
sdbus::IObject::emitPropertiesChangedSignal
virtual void emitPropertiesChangedSignal(const char *interfaceName, const std::vector< PropertyName > &propNames)=0
Emits PropertyChanged signal for specified properties under a given interface of this object path.
sdbus::IObject::addObjectManager
virtual Slot addObjectManager(return_slot_t)=0
Adds an ObjectManager interface at the path of this D-Bus object.
sdbus::IObject::getCurrentlyProcessedMessage
virtual Message getCurrentlyProcessedMessage() const =0
Provides access to the currently processed D-Bus message.
sdbus::IObject::emitInterfacesRemovedSignal
virtual void emitInterfacesRemovedSignal()=0
Emits InterfacesRemoved signal on this object path.
sdbus::IObject::emitPropertiesChangedSignal
virtual void emitPropertiesChangedSignal(const InterfaceName &interfaceName)=0
Emits PropertyChanged signal for all properties on a given interface of this object path.
sdbus::IObject::getObjectPath
virtual const ObjectPath & getObjectPath() const =0
Returns object path of the underlying DBus object.
sdbus::IObject::addVTable
VTableAdder addVTable(VTableItems &&... items)
Adds a declaration of methods, properties and signals of the object at a given interface.
Definition IObject.h:449
sdbus::IObject::createSignal
virtual Signal createSignal(const InterfaceName &interfaceName, const SignalName &signalName) const =0
Adds a declaration of methods, properties and signals of the object at a given interface.
sdbus::IObject::emitSignal
SignalEmitter emitSignal(const SignalName &signalName)
Emits signal on D-Bus.
Definition IObject.h:427
sdbus::IObject::emitInterfacesRemovedSignal
virtual void emitInterfacesRemovedSignal(const std::vector< InterfaceName > &interfaces)=0
Emits InterfacesRemoved signal on this object path.
sdbus::IObject::emitInterfacesAddedSignal
virtual void emitInterfacesAddedSignal(const std::vector< InterfaceName > &interfaces)=0
Emits InterfacesAdded signal on this object path.
sdbus::IObject::emitPropertiesChangedSignal
virtual void emitPropertiesChangedSignal(const InterfaceName &interfaceName, const std::vector< PropertyName > &propNames)=0
Emits PropertyChanged signal for specified properties under a given interface of this object path.
sdbus::IObject::addObjectManager
virtual void addObjectManager()=0
Adds an ObjectManager interface at the path of this D-Bus object.
sdbus::IObject::getConnection
virtual sdbus::IConnection & getConnection() const =0
Provides D-Bus connection used by the object.
sdbus::IObject::emitInterfacesAddedSignal
virtual void emitInterfacesAddedSignal()=0
Emits InterfacesAdded signal on this object path.
sdbus::IObject::emitPropertiesChangedSignal
virtual void emitPropertiesChangedSignal(const char *interfaceName)=0
Emits PropertyChanged signal for all properties on a given interface of this object path.
sdbus::IObject::emitSignal
virtual void emitSignal(const Signal &message)=0
Emits signal for this object path.
sdbus::IObject::unregister
virtual void unregister()=0
Unregisters object's API and removes object from the bus.
sdbus::InterfaceName
Definition Types.h:251
sdbus::Message
Definition Message.h:81
sdbus::ObjectPath
Definition Types.h:208
sdbus::Signal
Definition Message.h:314
sdbus::VTableAdder
Definition ConvenienceApiClasses.h:55
sdbus::return_slot_t
Definition TypeTraits.h:88