2017-11-27 14:13:55 +01:00
|
|
|
/**
|
2022-07-05 17:08:35 +02:00
|
|
|
* (C) 2016 - 2021 KISTLER INSTRUMENTE AG, Winterthur, Switzerland
|
2024-04-16 22:48:34 +02:00
|
|
|
* (C) 2016 - 2024 Stanislav Angelovic <stanislav.angelovic@protonmail.com>
|
2017-11-27 14:13:55 +01:00
|
|
|
*
|
|
|
|
|
* @file IObject.h
|
|
|
|
|
*
|
|
|
|
|
* Created on: Nov 8, 2016
|
|
|
|
|
* Project: sdbus-c++
|
|
|
|
|
* Description: High-level D-Bus IPC C++ library based on sd-bus
|
|
|
|
|
*
|
|
|
|
|
* This file is part of sdbus-c++.
|
|
|
|
|
*
|
|
|
|
|
* sdbus-c++ is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2.1 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* sdbus-c++ is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
* along with sdbus-c++. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef SDBUS_CXX_IOBJECT_H_
|
|
|
|
|
#define SDBUS_CXX_IOBJECT_H_
|
|
|
|
|
|
2019-04-09 21:28:07 +02:00
|
|
|
#include <sdbus-c++/ConvenienceApiClasses.h>
|
2019-01-10 08:47:59 +01:00
|
|
|
#include <sdbus-c++/Flags.h>
|
2024-01-09 23:31:47 +01:00
|
|
|
#include <sdbus-c++/TypeTraits.h>
|
|
|
|
|
#include <sdbus-c++/VTableItems.h>
|
|
|
|
|
|
2017-11-27 14:13:55 +01:00
|
|
|
#include <functional>
|
|
|
|
|
#include <memory>
|
2024-01-09 23:31:47 +01:00
|
|
|
#include <string>
|
2019-06-03 23:47:27 +02:00
|
|
|
#include <vector>
|
2017-11-27 14:13:55 +01:00
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
|
namespace sdbus {
|
2018-07-02 11:22:00 +02:00
|
|
|
class Signal;
|
2017-11-27 14:13:55 +01:00
|
|
|
class IConnection;
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
class ObjectPath;
|
2017-11-27 14:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace sdbus {
|
|
|
|
|
|
|
|
|
|
/********************************************//**
|
|
|
|
|
* @class IObject
|
|
|
|
|
*
|
2019-04-09 21:28:07 +02:00
|
|
|
* IObject class represents a D-Bus object instance identified by a specific object path.
|
|
|
|
|
* D-Bus object provides its interfaces, methods, signals and properties on a bus
|
|
|
|
|
* identified by a specific bus name.
|
2017-11-27 14:13:55 +01:00
|
|
|
*
|
2019-04-09 21:28:07 +02:00
|
|
|
* All IObject member methods throw @c sdbus::Error in case of D-Bus or sdbus-c++ error.
|
|
|
|
|
* The IObject class has been designed as thread-aware. However, the operation of
|
|
|
|
|
* creating and sending asynchronous method replies, as well as creating and emitting
|
|
|
|
|
* signals, is thread-safe by design.
|
2017-11-27 14:13:55 +01:00
|
|
|
*
|
|
|
|
|
***********************************************/
|
|
|
|
|
class IObject
|
|
|
|
|
{
|
2024-04-24 08:48:39 +02:00
|
|
|
public: // High-level, convenience API
|
2019-05-29 22:28:15 +02:00
|
|
|
virtual ~IObject() = default;
|
|
|
|
|
|
2017-11-27 14:13:55 +01:00
|
|
|
/*!
|
2023-12-30 18:40:38 +01:00
|
|
|
* @brief Adds a declaration of methods, properties and signals of the object at a given interface
|
2019-06-04 22:21:49 +02:00
|
|
|
*
|
2024-04-24 08:48:39 +02:00
|
|
|
* @param[in] vtable Individual instances of VTable item structures stored in a vector
|
|
|
|
|
* @return VTableAdder high-level helper class
|
2019-06-04 22:21:49 +02:00
|
|
|
*
|
2023-12-30 18:40:38 +01:00
|
|
|
* This method is used to declare attributes for the object under the given interface.
|
2024-04-24 08:48:39 +02:00
|
|
|
* Parameter `vtable' represents a vtable definition that may contain method declarations
|
2023-12-30 18:40:38 +01:00
|
|
|
* (using MethodVTableItem struct), property declarations (using PropertyVTableItem
|
|
|
|
|
* struct), signal declarations (using SignalVTableItem struct), or global interface
|
|
|
|
|
* flags (using InterfaceFlagsVTableItem struct).
|
2020-01-27 07:57:38 +01:00
|
|
|
*
|
2023-12-30 18:40:38 +01:00
|
|
|
* An interface can have any number of vtables attached to it.
|
2019-06-04 22:21:49 +02:00
|
|
|
*
|
2024-04-24 08:48:39 +02:00
|
|
|
* Consult manual pages for the underlying `sd_bus_add_object_vtable` function for more information.
|
2023-12-30 18:40:38 +01:00
|
|
|
*
|
2024-04-24 08:48:39 +02:00
|
|
|
* The method can be called at any time during object's lifetime.
|
2023-12-30 18:40:38 +01:00
|
|
|
*
|
2024-04-24 08:48:39 +02:00
|
|
|
* When called like `addVTable(vtable).forInterface(interface)`, then an internal registration
|
|
|
|
|
* slot is created for that vtable and its lifetime is tied to the lifetime of the Object instance.
|
|
|
|
|
* When called like `addVTable(items...).forInterface(interface, sdbus::return_slot)`, then an internal
|
|
|
|
|
* registration slot is created for the vtable and is returned to the caller. Keeping the slot means
|
|
|
|
|
* keep the registration "alive". Destroying the slot means that the vtable is not needed anymore,
|
|
|
|
|
* and the vtable gets removed from the object. This allows for "dynamic" object API where vtables
|
|
|
|
|
* can be added or removed by the user at runtime.
|
2019-06-04 22:21:49 +02:00
|
|
|
*
|
2023-12-30 18:40:38 +01:00
|
|
|
* The function provides strong exception guarantee. The state of the object remains
|
|
|
|
|
* unmodified in face of an exception.
|
2019-06-04 22:21:49 +02:00
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
2024-04-24 08:48:39 +02:00
|
|
|
[[nodiscard]] VTableAdder addVTable(std::vector<VTableItem> vtable);
|
2017-11-27 14:13:55 +01:00
|
|
|
|
|
|
|
|
/*!
|
2023-12-30 18:40:38 +01:00
|
|
|
* @brief Adds a declaration of methods, properties and signals of the object at a given interface
|
|
|
|
|
*
|
2024-04-24 08:48:39 +02:00
|
|
|
* @param[in] items Individual instances of VTable item structures
|
|
|
|
|
* @return VTableAdder high-level helper class
|
2023-12-30 18:40:38 +01:00
|
|
|
*
|
|
|
|
|
* This method is used to declare attributes for the object under the given interface.
|
2024-04-24 08:48:39 +02:00
|
|
|
* Parameter pack contains vtable definition that may contain method declarations
|
|
|
|
|
* (using MethodVTableItem struct), property declarations (using PropertyVTableItem
|
|
|
|
|
* struct), signal declarations (using SignalVTableItem struct), or global interface
|
|
|
|
|
* flags (using InterfaceFlagsVTableItem struct).
|
2019-06-04 22:21:49 +02:00
|
|
|
*
|
2023-12-30 18:40:38 +01:00
|
|
|
* An interface can have any number of vtables attached to it.
|
|
|
|
|
*
|
2024-04-24 08:48:39 +02:00
|
|
|
* Consult manual pages for the underlying `sd_bus_add_object_vtable` function for more information.
|
2023-12-30 18:40:38 +01:00
|
|
|
*
|
2024-04-24 08:48:39 +02:00
|
|
|
* The method can be called at any time during object's lifetime.
|
|
|
|
|
*
|
|
|
|
|
* When called like `addVTable(items...).forInterface(interface)`, then an internal registration
|
|
|
|
|
* slot is created for that vtable and its lifetime is tied to the lifetime of the Object instance.
|
|
|
|
|
* When called like `addVTable(items...).forInterface(interface, sdbus::return_slot)`, then an internal
|
|
|
|
|
* registration slot is created for the vtable and is returned to the caller. Keeping the slot means
|
|
|
|
|
* keep the registration "alive". Destroying the slot means that the vtable is not needed anymore,
|
|
|
|
|
* and the vtable gets removed from the object. This allows for "dynamic" object API where vtables
|
2023-12-30 18:40:38 +01:00
|
|
|
* can be added or removed by the user at runtime.
|
|
|
|
|
*
|
|
|
|
|
* The function provides strong exception guarantee. The state of the object remains
|
|
|
|
|
* unmodified in face of an exception.
|
2019-06-04 22:21:49 +02:00
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
2023-12-30 18:40:38 +01:00
|
|
|
template < typename... VTableItems
|
|
|
|
|
, typename = std::enable_if_t<(is_one_of_variants_types<VTableItem, std::decay_t<VTableItems>> && ...)> >
|
|
|
|
|
[[nodiscard]] VTableAdder addVTable(VTableItems&&... items);
|
2017-11-27 14:13:55 +01:00
|
|
|
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
/*!
|
|
|
|
|
* @brief Emits signal on D-Bus
|
|
|
|
|
*
|
|
|
|
|
* @param[in] signalName Name of the signal
|
|
|
|
|
* @return A helper object for convenient emission of signals
|
|
|
|
|
*
|
|
|
|
|
* This is a high-level, convenience way of emitting D-Bus signals that abstracts
|
|
|
|
|
* from the D-Bus message concept. Signal arguments are automatically serialized
|
|
|
|
|
* in a message and D-Bus signatures automatically deduced from the provided native arguments.
|
|
|
|
|
*
|
|
|
|
|
* Example of use:
|
|
|
|
|
* @code
|
|
|
|
|
* int arg1 = ...;
|
|
|
|
|
* double arg2 = ...;
|
|
|
|
|
* SignalName fooSignal{"fooSignal"};
|
|
|
|
|
* object_.emitSignal(fooSignal).onInterface("com.kistler.foo").withArguments(arg1, arg2);
|
|
|
|
|
* @endcode
|
|
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
|
|
|
|
[[nodiscard]] SignalEmitter emitSignal(const SignalName& signalName);
|
|
|
|
|
|
2024-02-16 09:27:45 +01:00
|
|
|
/*!
|
2024-04-16 22:28:42 +02:00
|
|
|
* @copydoc IObject::emitSignal(const SignalName&)
|
2024-02-16 09:27:45 +01:00
|
|
|
*/
|
|
|
|
|
[[nodiscard]] SignalEmitter emitSignal(const std::string& signalName);
|
|
|
|
|
|
2024-04-16 22:28:42 +02:00
|
|
|
/*!
|
|
|
|
|
* @copydoc IObject::emitSignal(const SignalName&)
|
|
|
|
|
*/
|
|
|
|
|
[[nodiscard]] SignalEmitter emitSignal(const char* signalName);
|
|
|
|
|
|
2019-06-03 22:02:15 +02:00
|
|
|
/*!
|
2019-06-04 22:21:49 +02:00
|
|
|
* @brief Emits PropertyChanged signal for specified properties under a given interface of this object path
|
|
|
|
|
*
|
|
|
|
|
* @param[in] interfaceName Name of an interface that properties belong to
|
|
|
|
|
* @param[in] propNames Names of properties that will be included in the PropertiesChanged signal
|
|
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
virtual void emitPropertiesChangedSignal(const InterfaceName& interfaceName, const std::vector<PropertyName>& propNames) = 0;
|
2019-06-03 22:02:15 +02:00
|
|
|
|
2024-04-16 22:28:42 +02:00
|
|
|
/*!
|
|
|
|
|
* @copydoc IObject::emitPropertiesChangedSignal(const InterfaceName&,const std::vector<PropertyName>&)
|
|
|
|
|
*/
|
|
|
|
|
virtual void emitPropertiesChangedSignal(const char* interfaceName, const std::vector<PropertyName>& propNames) = 0;
|
|
|
|
|
|
2019-06-03 22:02:15 +02:00
|
|
|
/*!
|
2019-06-04 22:21:49 +02:00
|
|
|
* @brief Emits PropertyChanged signal for all properties on a given interface of this object path
|
|
|
|
|
*
|
|
|
|
|
* @param[in] interfaceName Name of an interface
|
|
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
virtual void emitPropertiesChangedSignal(const InterfaceName& interfaceName) = 0;
|
2019-06-03 22:02:15 +02:00
|
|
|
|
2024-04-16 22:28:42 +02:00
|
|
|
/*!
|
|
|
|
|
* @copydoc IObject::emitPropertiesChangedSignal(const InterfaceName&)
|
|
|
|
|
*/
|
|
|
|
|
virtual void emitPropertiesChangedSignal(const char* interfaceName) = 0;
|
|
|
|
|
|
2019-04-04 20:39:03 +02:00
|
|
|
/*!
|
2019-06-03 23:47:27 +02:00
|
|
|
* @brief Emits InterfacesAdded signal on this object path
|
|
|
|
|
*
|
|
|
|
|
* This emits an InterfacesAdded signal on this object path, by iterating all registered
|
|
|
|
|
* interfaces on the path. All properties are queried and included in the signal.
|
|
|
|
|
* This call is equivalent to emitInterfacesAddedSignal() with an explicit list of
|
|
|
|
|
* registered interfaces. However, unlike emitInterfacesAddedSignal(interfaces), this
|
|
|
|
|
* call can figure out the list of supported interfaces itself. Furthermore, it properly
|
|
|
|
|
* adds the builtin org.freedesktop.DBus.* interfaces.
|
|
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
|
|
|
|
virtual void emitInterfacesAddedSignal() = 0;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Emits InterfacesAdded signal on this object path
|
|
|
|
|
*
|
|
|
|
|
* This emits an InterfacesAdded signal on this object path with explicitly provided list
|
2023-12-30 18:40:38 +01:00
|
|
|
* of registered interfaces. Since v2.0, sdbus-c++ supports dynamically addable/removable
|
|
|
|
|
* object interfaces and their vtables, so this method now makes more sense.
|
2019-06-03 23:47:27 +02:00
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
virtual void emitInterfacesAddedSignal(const std::vector<InterfaceName>& interfaces) = 0;
|
2019-06-03 23:47:27 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Emits InterfacesRemoved signal on this object path
|
|
|
|
|
*
|
|
|
|
|
* This is like sd_bus_emit_object_added(), but emits an InterfacesRemoved signal on this
|
|
|
|
|
* object path. This only includes any registered interfaces but skips the properties.
|
|
|
|
|
* This function shall be called (just) before destroying the object.
|
|
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
|
|
|
|
virtual void emitInterfacesRemovedSignal() = 0;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Emits InterfacesRemoved signal on this object path
|
|
|
|
|
*
|
|
|
|
|
* This emits an InterfacesRemoved signal on the given path with explicitly provided list
|
2023-12-30 18:40:38 +01:00
|
|
|
* of registered interfaces. Since v2.0, sdbus-c++ supports dynamically addable/removable
|
|
|
|
|
* object interfaces and their vtables, so this method now makes more sense.
|
2019-06-03 23:47:27 +02:00
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
virtual void emitInterfacesRemovedSignal(const std::vector<InterfaceName>& interfaces) = 0;
|
2019-04-04 20:39:03 +02:00
|
|
|
|
2019-05-29 22:28:15 +02:00
|
|
|
/*!
|
2019-06-04 22:21:49 +02:00
|
|
|
* @brief Adds an ObjectManager interface at the path of this D-Bus object
|
|
|
|
|
*
|
|
|
|
|
* Creates an ObjectManager interface at the specified object path on
|
|
|
|
|
* the connection. This is a convenient way to interrogate a connection
|
|
|
|
|
* to see what objects it has.
|
|
|
|
|
*
|
2024-04-24 09:18:40 +02:00
|
|
|
* This call creates a so-called floating registration. This means that
|
|
|
|
|
* the ObjectManager interface stays there for the lifetime of the object.
|
|
|
|
|
*
|
2019-06-04 22:21:49 +02:00
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
2019-05-29 22:28:15 +02:00
|
|
|
virtual void addObjectManager() = 0;
|
|
|
|
|
|
|
|
|
|
/*!
|
2024-04-24 09:18:40 +02:00
|
|
|
* @brief Adds an ObjectManager interface at the path of this D-Bus object
|
|
|
|
|
*
|
|
|
|
|
* @return Slot handle owning the registration
|
|
|
|
|
*
|
|
|
|
|
* Creates an ObjectManager interface at the specified object path on
|
|
|
|
|
* the connection. This is a convenient way to interrogate a connection
|
|
|
|
|
* to see what objects it has.
|
|
|
|
|
*
|
|
|
|
|
* The lifetime of the ObjectManager interface is bound to the lifetime
|
|
|
|
|
* of the returned slot instance.
|
2019-06-04 22:21:49 +02:00
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
2024-04-24 09:18:40 +02:00
|
|
|
[[nodiscard]] virtual Slot addObjectManager(return_slot_t) = 0;
|
2019-05-29 22:28:15 +02:00
|
|
|
|
2019-06-03 23:47:27 +02:00
|
|
|
/*!
|
2019-06-04 22:21:49 +02:00
|
|
|
* @brief Provides D-Bus connection used by the object
|
|
|
|
|
*
|
|
|
|
|
* @return Reference to the D-Bus connection
|
|
|
|
|
*/
|
2023-12-30 19:57:48 +01:00
|
|
|
[[nodiscard]] virtual sdbus::IConnection& getConnection() const = 0;
|
2019-06-03 23:47:27 +02:00
|
|
|
|
2020-05-28 15:36:58 +02:00
|
|
|
/*!
|
|
|
|
|
* @brief Returns object path of the underlying DBus object
|
|
|
|
|
*/
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
[[nodiscard]] virtual const ObjectPath& getObjectPath() const = 0;
|
2021-06-02 15:17:20 +00:00
|
|
|
|
|
|
|
|
/*!
|
2023-02-02 21:51:09 +01:00
|
|
|
* @brief Provides access to the currently processed D-Bus message
|
2021-06-02 15:17:20 +00:00
|
|
|
*
|
2023-02-02 21:51:09 +01:00
|
|
|
* This method provides access to the currently processed incoming D-Bus message.
|
2021-06-02 15:17:20 +00:00
|
|
|
* "Currently processed" means that the registered callback handler(s) for that message
|
|
|
|
|
* are being invoked. This method is meant to be called from within a callback handler
|
2023-02-02 21:51:09 +01:00
|
|
|
* (e.g. from a D-Bus signal handler, or async method reply handler, etc.). In such a case it is
|
|
|
|
|
* guaranteed to return a valid D-Bus message instance for which the handler is called.
|
|
|
|
|
* If called from other contexts/threads, it may return a valid or invalid message, depending
|
|
|
|
|
* on whether a message was processed or not at the time of the call.
|
2021-06-02 15:17:20 +00:00
|
|
|
*
|
2023-02-02 21:51:09 +01:00
|
|
|
* @return Currently processed D-Bus message
|
2021-06-02 15:17:20 +00:00
|
|
|
*/
|
2023-12-30 19:57:48 +01:00
|
|
|
[[nodiscard]] virtual Message getCurrentlyProcessedMessage() const = 0;
|
2024-04-16 22:28:42 +02:00
|
|
|
|
2024-04-24 08:48:39 +02:00
|
|
|
/*!
|
|
|
|
|
* @brief Unregisters object's API and removes object from the bus
|
|
|
|
|
*
|
|
|
|
|
* This method unregisters the object, its interfaces, methods, signals and properties
|
|
|
|
|
* from the bus. Unregistration is done automatically also in object's destructor. This
|
|
|
|
|
* method makes sense if, in the process of object removal, we need to make sure that
|
|
|
|
|
* callbacks are unregistered explicitly before the final destruction of the object instance.
|
|
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
|
|
|
|
virtual void unregister() = 0;
|
|
|
|
|
|
|
|
|
|
public: // Lower-level, message-based API
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Adds a declaration of methods, properties and signals of the object at a given interface
|
|
|
|
|
*
|
|
|
|
|
* @param[in] interfaceName Name of an interface the the vtable is registered for
|
|
|
|
|
* @param[in] items Individual instances of VTable item structures
|
|
|
|
|
*
|
|
|
|
|
* This method is used to declare attributes for the object under the given interface.
|
|
|
|
|
* Parameter `items' represents a vtable definition that may contain method declarations
|
|
|
|
|
* (using MethodVTableItem struct), property declarations (using PropertyVTableItem
|
|
|
|
|
* struct), signal declarations (using SignalVTableItem struct), or global interface
|
|
|
|
|
* flags (using InterfaceFlagsVTableItem struct).
|
|
|
|
|
*
|
|
|
|
|
* An interface can have any number of vtables attached to it.
|
|
|
|
|
*
|
|
|
|
|
* Consult manual pages for the underlying `sd_bus_add_object_vtable` function for more information.
|
|
|
|
|
*
|
|
|
|
|
* The method can be called at any time during object's lifetime. For each vtable an internal
|
|
|
|
|
* registration slot is created and its lifetime is tied to the lifetime of the Object instance.
|
|
|
|
|
*
|
|
|
|
|
* The function provides strong exception guarantee. The state of the object remains
|
|
|
|
|
* unmodified in face of an exception.
|
|
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
|
|
|
|
template < typename... VTableItems
|
|
|
|
|
, typename = std::enable_if_t<(is_one_of_variants_types<VTableItem, std::decay_t<VTableItems>> && ...)> >
|
|
|
|
|
void addVTable(InterfaceName interfaceName, VTableItems&&... items);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Adds a declaration of methods, properties and signals of the object at a given interface
|
|
|
|
|
*
|
|
|
|
|
* @param[in] interfaceName Name of an interface the the vtable is registered for
|
|
|
|
|
* @param[in] vtable A list of individual descriptions in the form of VTable item instances
|
|
|
|
|
*
|
|
|
|
|
* This method is used to declare attributes for the object under the given interface.
|
|
|
|
|
* The `vtable' parameter may contain method declarations (using MethodVTableItem struct),
|
|
|
|
|
* property declarations (using PropertyVTableItem struct), signal declarations (using
|
|
|
|
|
* SignalVTableItem struct), or global interface flags (using InterfaceFlagsVTableItem struct).
|
|
|
|
|
*
|
|
|
|
|
* An interface can have any number of vtables attached to it.
|
|
|
|
|
*
|
|
|
|
|
* Consult manual pages for the underlying `sd_bus_add_object_vtable` function for more information.
|
|
|
|
|
*
|
|
|
|
|
* The method can be called at any time during object's lifetime. For each vtable an internal
|
|
|
|
|
* registration slot is created and its lifetime is tied to the lifetime of the Object instance.
|
|
|
|
|
*
|
|
|
|
|
* The function provides strong exception guarantee. The state of the object remains
|
|
|
|
|
* unmodified in face of an exception.
|
|
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
|
|
|
|
virtual void addVTable(InterfaceName interfaceName, std::vector<VTableItem> vtable) = 0;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Adds a declaration of methods, properties and signals of the object at a given interface
|
|
|
|
|
*
|
|
|
|
|
* @param[in] interfaceName Name of an interface the the vtable is registered for
|
|
|
|
|
* @param[in] vtable A list of individual descriptions in the form of VTable item instances
|
|
|
|
|
*
|
|
|
|
|
* This method is used to declare attributes for the object under the given interface.
|
|
|
|
|
* The `vtable' parameter may contain method declarations (using MethodVTableItem struct),
|
|
|
|
|
* property declarations (using PropertyVTableItem struct), signal declarations (using
|
|
|
|
|
* SignalVTableItem struct), or global interface flags (using InterfaceFlagsVTableItem struct).
|
|
|
|
|
*
|
|
|
|
|
* An interface can have any number of vtables attached to it.
|
|
|
|
|
*
|
|
|
|
|
* Consult manual pages for the underlying `sd_bus_add_object_vtable` function for more information.
|
|
|
|
|
*
|
|
|
|
|
* The method can be called at any time during object's lifetime. For each vtable an internal
|
|
|
|
|
* registration slot is created and is returned to the caller. The returned slot should be destroyed
|
|
|
|
|
* when the vtable is not needed anymore. This allows for "dynamic" object API where vtables
|
|
|
|
|
* can be added or removed by the user at runtime.
|
|
|
|
|
*
|
|
|
|
|
* The function provides strong exception guarantee. The state of the object remains
|
|
|
|
|
* unmodified in face of an exception.
|
|
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
|
|
|
|
[[nodiscard]] virtual Slot addVTable(InterfaceName interfaceName, std::vector<VTableItem> vtable, return_slot_t) = 0;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Creates a signal message
|
|
|
|
|
*
|
|
|
|
|
* @param[in] interfaceName Name of an interface that the signal belongs under
|
|
|
|
|
* @param[in] signalName Name of the signal
|
|
|
|
|
* @return A signal message
|
|
|
|
|
*
|
|
|
|
|
* Serialize signal arguments into the returned message and emit the signal by passing
|
|
|
|
|
* the message with serialized arguments to the @c emitSignal function.
|
|
|
|
|
* Alternatively, use higher-level API @c emitSignal(const std::string& signalName) defined below.
|
|
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
2024-10-02 21:22:02 +02:00
|
|
|
[[nodiscard]] virtual Signal createSignal(const InterfaceName& interfaceName, const SignalName& signalName) const = 0;
|
2024-04-24 08:48:39 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* @brief Emits signal for this object path
|
|
|
|
|
*
|
|
|
|
|
* @param[in] message Signal message to be sent out
|
|
|
|
|
*
|
|
|
|
|
* Note: To avoid messing with messages, use higher-level API defined below.
|
|
|
|
|
*
|
|
|
|
|
* @throws sdbus::Error in case of failure
|
|
|
|
|
*/
|
|
|
|
|
virtual void emitSignal(const sdbus::Signal& message) = 0;
|
|
|
|
|
|
|
|
|
|
protected: // Internal API for efficiency reasons used by high-level API helper classes
|
2024-04-16 22:28:42 +02:00
|
|
|
friend SignalEmitter;
|
|
|
|
|
|
2024-10-02 21:22:02 +02:00
|
|
|
[[nodiscard]] virtual Signal createSignal(const char* interfaceName, const char* signalName) const = 0;
|
2017-11-27 14:13:55 +01:00
|
|
|
};
|
|
|
|
|
|
2019-11-03 13:54:13 +01:00
|
|
|
// Out-of-line member definitions
|
|
|
|
|
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
inline SignalEmitter IObject::emitSignal(const SignalName& signalName)
|
2017-11-27 14:13:55 +01:00
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
return SignalEmitter(*this, signalName);
|
2017-11-27 14:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
inline SignalEmitter IObject::emitSignal(const std::string& signalName)
|
|
|
|
|
{
|
2024-04-16 22:28:42 +02:00
|
|
|
return SignalEmitter(*this, signalName.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline SignalEmitter IObject::emitSignal(const char* signalName)
|
|
|
|
|
{
|
|
|
|
|
return SignalEmitter(*this, signalName);
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
template <typename... VTableItems, typename>
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
void IObject::addVTable(InterfaceName interfaceName, VTableItems&&... items)
|
2017-11-27 14:13:55 +01:00
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
addVTable(std::move(interfaceName), {std::forward<VTableItems>(items)...});
|
2017-11-27 14:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
template <typename... VTableItems, typename>
|
|
|
|
|
VTableAdder IObject::addVTable(VTableItems&&... items)
|
2019-01-10 08:47:59 +01:00
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
return addVTable(std::vector<VTableItem>{std::forward<VTableItems>(items)...});
|
2019-01-10 08:47:59 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
inline VTableAdder IObject::addVTable(std::vector<VTableItem> vtable)
|
2017-11-27 14:13:55 +01:00
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
return VTableAdder(*this, std::move(vtable));
|
2017-11-27 14:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2019-06-04 22:21:49 +02:00
|
|
|
* @brief Creates instance representing a D-Bus object
|
|
|
|
|
*
|
|
|
|
|
* @param[in] connection D-Bus connection to be used by the object
|
|
|
|
|
* @param[in] objectPath Path of the D-Bus object
|
|
|
|
|
* @return Pointer to the object representation instance
|
|
|
|
|
*
|
|
|
|
|
* The provided connection will be used by the object to export methods,
|
|
|
|
|
* issue signals and provide properties.
|
|
|
|
|
*
|
|
|
|
|
* Creating a D-Bus object instance is (thread-)safe even upon the connection
|
2020-02-02 22:22:26 +01:00
|
|
|
* which is already running its I/O event loop.
|
2019-06-04 22:21:49 +02:00
|
|
|
*
|
|
|
|
|
* Code example:
|
|
|
|
|
* @code
|
|
|
|
|
* auto proxy = sdbus::createObject(connection, "/com/kistler/foo");
|
|
|
|
|
* @endcode
|
|
|
|
|
*/
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
[[nodiscard]] std::unique_ptr<sdbus::IObject> createObject(sdbus::IConnection& connection, ObjectPath objectPath);
|
2017-11-27 14:13:55 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 21:28:07 +02:00
|
|
|
#include <sdbus-c++/ConvenienceApiClasses.inl>
|
2024-01-09 23:31:47 +01:00
|
|
|
#include <sdbus-c++/VTableItems.inl>
|
2017-11-27 14:13:55 +01:00
|
|
|
|
|
|
|
|
#endif /* SDBUS_CXX_IOBJECT_H_ */
|