Loading...
Searching...
No Matches
ConvenienceApiClasses.h
Go to the documentation of this file.
#ifndef SDBUS_CXX_CONVENIENCEAPICLASSES_H_
#define SDBUS_CXX_CONVENIENCEAPICLASSES_H_
#include <sdbus-c++/Awaitable.h>
#include <sdbus-c++/Message.h>
#include <sdbus-c++/TypeTraits.h>
#include <sdbus-c++/Types.h>
#include <sdbus-c++/VTableItems.h>
#include <chrono>
#include <cstdint>
#include <future>
#include <map>
#include <string>
#include <string_view>
#include <vector>
// Forward declarations
namespace sdbus {
class IObject;
class IProxy;
class Error;
class PendingAsyncCall;
} // namespace sdbus
namespace sdbus {
class VTableAdder
{
public:
void forInterface(InterfaceName interfaceName);
void forInterface(std::string interfaceName);
[[nodiscard]] Slot forInterface(InterfaceName interfaceName, return_slot_t);
[[nodiscard]] Slot forInterface(std::string interfaceName, return_slot_t);
private:
friend IObject;
VTableAdder(IObject& object, std::vector<VTableItem> vtable);
IObject& object_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
std::vector<VTableItem> vtable_;
};
class SignalEmitter
{
public:
SignalEmitter& onInterface(const InterfaceName& interfaceName);
SignalEmitter& onInterface(const std::string& interfaceName);
SignalEmitter& onInterface(const char* interfaceName);
template <typename... Args> void withArguments(Args&&... args);
SignalEmitter(const SignalEmitter&) = delete;
SignalEmitter& operator=(const SignalEmitter&) = delete;
SignalEmitter(SignalEmitter&& other) = default;
SignalEmitter& operator=(SignalEmitter&&) = delete;
~SignalEmitter() noexcept(false);
private:
friend IObject;
SignalEmitter(IObject& object, const SignalName& signalName);
SignalEmitter(IObject& object, const char* signalName);
IObject& object_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
const char* signalName_;
Signal signal_;
int exceptions_{}; // Number of active exceptions when SignalEmitter is constructed
};
class MethodInvoker
{
public:
MethodInvoker& onInterface(const InterfaceName& interfaceName);
MethodInvoker& onInterface(const std::string& interfaceName);
MethodInvoker& onInterface(const char* interfaceName);
MethodInvoker& withTimeout(uint64_t usec);
template <typename Rep, typename Period>
MethodInvoker& withTimeout(const std::chrono::duration<Rep, Period>& timeout);
template <typename... Args> MethodInvoker& withArguments(Args&&... args);
template <typename... Args> void storeResultsTo(Args&... args);
void dontExpectReply();
MethodInvoker(const MethodInvoker&) = delete;
MethodInvoker& operator=(const MethodInvoker&) = delete;
MethodInvoker(MethodInvoker&& other) = default;
MethodInvoker& operator=(MethodInvoker&&) = delete;
~MethodInvoker() noexcept(false);
private:
friend IProxy;
MethodInvoker(IProxy& proxy, const MethodName& methodName);
MethodInvoker(IProxy& proxy, const char* methodName);
IProxy& proxy_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
const char* methodName_;
uint64_t timeout_{};
MethodCall method_;
int exceptions_{}; // Number of active exceptions when MethodInvoker is constructed
bool methodCalled_{};
};
class AsyncMethodInvoker
{
public:
AsyncMethodInvoker& onInterface(const InterfaceName& interfaceName);
AsyncMethodInvoker& onInterface(const std::string& interfaceName);
AsyncMethodInvoker& onInterface(const char* interfaceName);
AsyncMethodInvoker& withTimeout(uint64_t usec);
template <typename Rep, typename Period>
AsyncMethodInvoker& withTimeout(const std::chrono::duration<Rep, Period>& timeout);
template <typename... Args> AsyncMethodInvoker& withArguments(Args&&... args);
template <typename Function> PendingAsyncCall uponReplyInvoke(Function&& callback);
template <typename Function> [[nodiscard]] Slot uponReplyInvoke(Function&& callback, return_slot_t);
// Returned future will be std::future<void> for no (void) D-Bus method return value
// or std::future<T> for single D-Bus method return value
// or std::future<std::tuple<...>> for multiple method return values
template <typename... Args> std::future<future_return_t<Args...>> getResultAsFuture();
template <typename... Args> Awaitable<awaitable_return_t<Args...>> getResultAsAwaitable();
private:
friend IProxy;
AsyncMethodInvoker(IProxy& proxy, const MethodName& methodName);
AsyncMethodInvoker(IProxy& proxy, const char* methodName);
template <typename Function> async_reply_handler makeAsyncReplyHandler(Function&& callback);
IProxy& proxy_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
const char* methodName_;
uint64_t timeout_{};
MethodCall method_;
};
class SignalSubscriber
{
public:
SignalSubscriber& onInterface(const InterfaceName& interfaceName);
SignalSubscriber& onInterface(const std::string& interfaceName);
SignalSubscriber& onInterface(const char* interfaceName);
template <typename Function> void call(Function&& callback);
template <typename Function> [[nodiscard]] Slot call(Function&& callback, return_slot_t);
private:
friend IProxy;
SignalSubscriber(IProxy& proxy, const SignalName& signalName);
SignalSubscriber(IProxy& proxy, const char* signalName);
template <typename Function> signal_handler makeSignalHandler(Function&& callback);
IProxy& proxy_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
const char* signalName_;
const char* interfaceName_{};
};
class PropertyGetter
{
public:
Variant onInterface(std::string_view interfaceName);
private:
friend IProxy;
PropertyGetter(IProxy& proxy, std::string_view propertyName);
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
IProxy& proxy_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
std::string_view propertyName_;
};
class AsyncPropertyGetter
{
public:
AsyncPropertyGetter& onInterface(std::string_view interfaceName);
template <typename Function> PendingAsyncCall uponReplyInvoke(Function&& callback);
template <typename Function> [[nodiscard]] Slot uponReplyInvoke(Function&& callback, return_slot_t);
std::future<Variant> getResultAsFuture();
Awaitable<Variant> getResultAsAwaitable();
private:
friend IProxy;
AsyncPropertyGetter(IProxy& proxy, std::string_view propertyName);
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
IProxy& proxy_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
std::string_view propertyName_;
std::string_view interfaceName_;
};
class PropertySetter
{
public:
PropertySetter& onInterface(std::string_view interfaceName);
template <typename Value> void toValue(const Value& value);
template <typename Value> void toValue(const Value& value, dont_expect_reply_t);
void toValue(const Variant& value);
void toValue(const Variant& value, dont_expect_reply_t);
private:
friend IProxy;
PropertySetter(IProxy& proxy, std::string_view propertyName);
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
IProxy& proxy_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
std::string_view propertyName_;
std::string_view interfaceName_;
};
class AsyncPropertySetter
{
public:
AsyncPropertySetter& onInterface(std::string_view interfaceName);
template <typename Value> AsyncPropertySetter& toValue(Value&& value);
AsyncPropertySetter& toValue(Variant value);
template <typename Function> PendingAsyncCall uponReplyInvoke(Function&& callback);
template <typename Function> [[nodiscard]] Slot uponReplyInvoke(Function&& callback, return_slot_t);
std::future<void> getResultAsFuture();
Awaitable<void> getResultAsAwaitable();
private:
friend IProxy;
AsyncPropertySetter(IProxy& proxy, std::string_view propertyName);
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
IProxy& proxy_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
std::string_view propertyName_;
std::string_view interfaceName_;
Variant value_;
};
class AllPropertiesGetter
{
public:
std::map<PropertyName, Variant> onInterface(std::string_view interfaceName);
private:
friend IProxy;
explicit AllPropertiesGetter(IProxy& proxy);
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
IProxy& proxy_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
};
class AsyncAllPropertiesGetter
{
public:
AsyncAllPropertiesGetter& onInterface(std::string_view interfaceName);
template <typename Function> PendingAsyncCall uponReplyInvoke(Function&& callback);
template <typename Function> [[nodiscard]] Slot uponReplyInvoke(Function&& callback, return_slot_t);
std::future<std::map<PropertyName, Variant>> getResultAsFuture();
Awaitable<std::map<PropertyName, Variant>> getResultAsAwaitable();
private:
friend IProxy;
explicit AsyncAllPropertiesGetter(IProxy& proxy);
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
IProxy& proxy_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
std::string_view interfaceName_;
};
} // namespace sdbus
#endif /* SDBUS_CXX_CONVENIENCEAPICLASSES_H_ */
Awaitable.h
Message.h
TypeTraits.h
Types.h
VTableItems.h
sdbus::Awaitable
Definition Awaitable.h:110
sdbus::Error
Definition Error.h:44
sdbus::IObject
Definition IObject.h:63
sdbus::IProxy
Definition IProxy.h:70
sdbus::InterfaceName
Definition Types.h:251
sdbus::MethodCall
Definition Message.h:278
sdbus::PendingAsyncCall
Definition IProxy.h:722
sdbus::Signal
Definition Message.h:314
sdbus::Variant
Definition Types.h:56
sdbus::dont_expect_reply_t
Definition TypeTraits.h:107
sdbus::return_slot_t
Definition TypeTraits.h:88