forked from Kistler-Group/sdbus-cpp
perf: provide also const char* overloads for convenience functions
This commit is contained in:
@@ -53,12 +53,15 @@ namespace sdbus {
|
||||
class VTableAdder
|
||||
{
|
||||
public:
|
||||
VTableAdder(IObject& object, std::vector<VTableItem> vtable);
|
||||
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);
|
||||
|
||||
private:
|
||||
IObject& object_;
|
||||
std::vector<VTableItem> vtable_;
|
||||
@@ -67,16 +70,22 @@ namespace sdbus {
|
||||
class SignalEmitter
|
||||
{
|
||||
public:
|
||||
SignalEmitter(IObject& object, const SignalName& signalName);
|
||||
SignalEmitter(SignalEmitter&& other) = default;
|
||||
~SignalEmitter() noexcept(false);
|
||||
SignalEmitter& onInterface(const InterfaceName& interfaceName);
|
||||
SignalEmitter& onInterface(const std::string& interfaceName);
|
||||
SignalEmitter& onInterface(const char* interfaceName);
|
||||
template <typename... _Args> void withArguments(_Args&&... args);
|
||||
|
||||
SignalEmitter(SignalEmitter&& other) = default;
|
||||
~SignalEmitter() noexcept(false);
|
||||
|
||||
private:
|
||||
friend IObject;
|
||||
SignalEmitter(IObject& object, const SignalName& signalName);
|
||||
SignalEmitter(IObject& object, const char* signalName);
|
||||
|
||||
private:
|
||||
IObject& object_;
|
||||
const SignalName& signalName_;
|
||||
const char* signalName_;
|
||||
Signal signal_;
|
||||
int exceptions_{}; // Number of active exceptions when SignalEmitter is constructed
|
||||
};
|
||||
@@ -84,23 +93,27 @@ namespace sdbus {
|
||||
class MethodInvoker
|
||||
{
|
||||
public:
|
||||
MethodInvoker(IProxy& proxy, const MethodName& methodName);
|
||||
MethodInvoker(MethodInvoker&& other) = default;
|
||||
~MethodInvoker() noexcept(false);
|
||||
|
||||
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(MethodInvoker&& other) = default;
|
||||
~MethodInvoker() noexcept(false);
|
||||
|
||||
private:
|
||||
friend IProxy;
|
||||
MethodInvoker(IProxy& proxy, const MethodName& methodName);
|
||||
MethodInvoker(IProxy& proxy, const char* methodName);
|
||||
|
||||
private:
|
||||
IProxy& proxy_;
|
||||
const MethodName& methodName_;
|
||||
const char* methodName_;
|
||||
uint64_t timeout_{};
|
||||
MethodCall method_;
|
||||
int exceptions_{}; // Number of active exceptions when MethodInvoker is constructed
|
||||
@@ -110,9 +123,9 @@ namespace sdbus {
|
||||
class AsyncMethodInvoker
|
||||
{
|
||||
public:
|
||||
AsyncMethodInvoker(IProxy& proxy, const MethodName& methodName);
|
||||
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);
|
||||
@@ -123,9 +136,14 @@ namespace sdbus {
|
||||
// or std::future<std::tuple<...>> for multiple method return values
|
||||
template <typename... _Args> std::future<future_return_t<_Args...>> getResultAsFuture();
|
||||
|
||||
private:
|
||||
friend IProxy;
|
||||
AsyncMethodInvoker(IProxy& proxy, const MethodName& methodName);
|
||||
AsyncMethodInvoker(IProxy& proxy, const char* methodName);
|
||||
|
||||
private:
|
||||
IProxy& proxy_;
|
||||
const MethodName& methodName_;
|
||||
const char* methodName_;
|
||||
uint64_t timeout_{};
|
||||
MethodCall method_;
|
||||
};
|
||||
@@ -133,29 +151,34 @@ namespace sdbus {
|
||||
class SignalSubscriber
|
||||
{
|
||||
public:
|
||||
SignalSubscriber(IProxy& proxy, const SignalName& signalName);
|
||||
SignalSubscriber& onInterface(InterfaceName interfaceName); // TODO: This could be const char*
|
||||
SignalSubscriber& onInterface(std::string interfaceName); // TODO: This could be const char*
|
||||
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);
|
||||
|
||||
private:
|
||||
IProxy& proxy_;
|
||||
const SignalName& signalName_;
|
||||
InterfaceName interfaceName_;
|
||||
const char* signalName_;
|
||||
const char* interfaceName_{};
|
||||
};
|
||||
|
||||
class PropertyGetter
|
||||
{
|
||||
public:
|
||||
PropertyGetter(IProxy& proxy, std::string_view propertyName);
|
||||
Variant onInterface(std::string_view interfaceName);
|
||||
|
||||
private:
|
||||
static inline const InterfaceName DBUS_PROPERTIES_INTERFACE_NAME{"org.freedesktop.DBus.Properties"};
|
||||
friend IProxy;
|
||||
PropertyGetter(IProxy& proxy, std::string_view propertyName);
|
||||
|
||||
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
|
||||
|
||||
private:
|
||||
IProxy& proxy_;
|
||||
@@ -165,13 +188,15 @@ namespace sdbus {
|
||||
class AsyncPropertyGetter
|
||||
{
|
||||
public:
|
||||
AsyncPropertyGetter(IProxy& proxy, std::string_view propertyName);
|
||||
AsyncPropertyGetter& onInterface(std::string_view interfaceName);
|
||||
template <typename _Function> PendingAsyncCall uponReplyInvoke(_Function&& callback);
|
||||
std::future<Variant> getResultAsFuture();
|
||||
|
||||
private:
|
||||
static inline const InterfaceName DBUS_PROPERTIES_INTERFACE_NAME{"org.freedesktop.DBus.Properties"};
|
||||
friend IProxy;
|
||||
AsyncPropertyGetter(IProxy& proxy, std::string_view propertyName);
|
||||
|
||||
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
|
||||
|
||||
private:
|
||||
IProxy& proxy_;
|
||||
@@ -182,7 +207,6 @@ namespace sdbus {
|
||||
class PropertySetter
|
||||
{
|
||||
public:
|
||||
PropertySetter(IProxy& proxy, std::string_view propertyName);
|
||||
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);
|
||||
@@ -190,7 +214,10 @@ namespace sdbus {
|
||||
void toValue(const Variant& value, dont_expect_reply_t);
|
||||
|
||||
private:
|
||||
static inline const InterfaceName DBUS_PROPERTIES_INTERFACE_NAME{"org.freedesktop.DBus.Properties"};
|
||||
friend IProxy;
|
||||
PropertySetter(IProxy& proxy, std::string_view propertyName);
|
||||
|
||||
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
|
||||
|
||||
private:
|
||||
IProxy& proxy_;
|
||||
@@ -201,7 +228,6 @@ namespace sdbus {
|
||||
class AsyncPropertySetter
|
||||
{
|
||||
public:
|
||||
AsyncPropertySetter(IProxy& proxy, std::string_view propertyName);
|
||||
AsyncPropertySetter& onInterface(std::string_view interfaceName);
|
||||
template <typename _Value> AsyncPropertySetter& toValue(_Value&& value);
|
||||
AsyncPropertySetter& toValue(Variant value);
|
||||
@@ -209,7 +235,10 @@ namespace sdbus {
|
||||
std::future<void> getResultAsFuture();
|
||||
|
||||
private:
|
||||
static inline const InterfaceName DBUS_PROPERTIES_INTERFACE_NAME{"org.freedesktop.DBus.Properties"};
|
||||
friend IProxy;
|
||||
AsyncPropertySetter(IProxy& proxy, std::string_view propertyName);
|
||||
|
||||
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
|
||||
|
||||
private:
|
||||
IProxy& proxy_;
|
||||
@@ -221,11 +250,13 @@ namespace sdbus {
|
||||
class AllPropertiesGetter
|
||||
{
|
||||
public:
|
||||
AllPropertiesGetter(IProxy& proxy);
|
||||
std::map<PropertyName, Variant> onInterface(std::string_view interfaceName);
|
||||
|
||||
private:
|
||||
static inline const InterfaceName DBUS_PROPERTIES_INTERFACE_NAME{"org.freedesktop.DBus.Properties"};
|
||||
friend IProxy;
|
||||
AllPropertiesGetter(IProxy& proxy);
|
||||
|
||||
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
|
||||
|
||||
private:
|
||||
IProxy& proxy_;
|
||||
@@ -234,13 +265,15 @@ namespace sdbus {
|
||||
class AsyncAllPropertiesGetter
|
||||
{
|
||||
public:
|
||||
AsyncAllPropertiesGetter(IProxy& proxy);
|
||||
AsyncAllPropertiesGetter& onInterface(std::string_view interfaceName);
|
||||
template <typename _Function> PendingAsyncCall uponReplyInvoke(_Function&& callback);
|
||||
std::future<std::map<PropertyName, Variant>> getResultAsFuture();
|
||||
|
||||
private:
|
||||
static inline const InterfaceName DBUS_PROPERTIES_INTERFACE_NAME{"org.freedesktop.DBus.Properties"}; // TODO: Couldn't this be const char*?
|
||||
friend IProxy;
|
||||
AsyncAllPropertiesGetter(IProxy& proxy);
|
||||
|
||||
static constexpr const char* DBUS_PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties";
|
||||
|
||||
private:
|
||||
IProxy& proxy_;
|
||||
|
||||
@@ -78,6 +78,11 @@ namespace sdbus {
|
||||
/*** ------------- ***/
|
||||
|
||||
inline SignalEmitter::SignalEmitter(IObject& object, const SignalName& signalName)
|
||||
: SignalEmitter(object, signalName.c_str())
|
||||
{
|
||||
}
|
||||
|
||||
inline SignalEmitter::SignalEmitter(IObject& object, const char* signalName)
|
||||
: object_(object)
|
||||
, signalName_(signalName)
|
||||
, exceptions_(std::uncaught_exceptions())
|
||||
@@ -104,16 +109,19 @@ namespace sdbus {
|
||||
|
||||
inline SignalEmitter& SignalEmitter::onInterface(const InterfaceName& interfaceName)
|
||||
{
|
||||
signal_ = object_.createSignal(interfaceName, signalName_);
|
||||
|
||||
return *this;
|
||||
return onInterface(interfaceName.c_str());
|
||||
}
|
||||
|
||||
inline SignalEmitter& SignalEmitter::onInterface(const std::string& interfaceName)
|
||||
{
|
||||
// Down-cast through static cast for performance reasons (no extra copy and object construction needed)
|
||||
static_assert(sizeof(interfaceName) == sizeof(InterfaceName));
|
||||
return onInterface(static_cast<const InterfaceName&>(interfaceName));
|
||||
return onInterface(interfaceName.c_str());
|
||||
}
|
||||
|
||||
inline SignalEmitter& SignalEmitter::onInterface(const char* interfaceName)
|
||||
{
|
||||
signal_ = object_.createSignal(interfaceName, signalName_);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename... _Args>
|
||||
@@ -129,6 +137,11 @@ namespace sdbus {
|
||||
/*** ------------- ***/
|
||||
|
||||
inline MethodInvoker::MethodInvoker(IProxy& proxy, const MethodName& methodName)
|
||||
: MethodInvoker(proxy, methodName.c_str())
|
||||
{
|
||||
}
|
||||
|
||||
inline MethodInvoker::MethodInvoker(IProxy& proxy, const char* methodName)
|
||||
: proxy_(proxy)
|
||||
, methodName_(methodName)
|
||||
, exceptions_(std::uncaught_exceptions())
|
||||
@@ -156,16 +169,19 @@ namespace sdbus {
|
||||
|
||||
inline MethodInvoker& MethodInvoker::onInterface(const InterfaceName& interfaceName)
|
||||
{
|
||||
method_ = proxy_.createMethodCall(interfaceName, methodName_);
|
||||
|
||||
return *this;
|
||||
return onInterface(interfaceName.c_str());
|
||||
}
|
||||
|
||||
inline MethodInvoker& MethodInvoker::onInterface(const std::string& interfaceName)
|
||||
{
|
||||
// Down-cast through static cast for performance reasons (no extra copy and object construction needed)
|
||||
static_assert(sizeof(interfaceName) == sizeof(InterfaceName));
|
||||
return onInterface(static_cast<const InterfaceName&>(interfaceName));
|
||||
return onInterface(interfaceName.c_str());
|
||||
}
|
||||
|
||||
inline MethodInvoker& MethodInvoker::onInterface(const char* interfaceName)
|
||||
{
|
||||
method_ = proxy_.createMethodCall(interfaceName, methodName_);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline MethodInvoker& MethodInvoker::withTimeout(uint64_t usec)
|
||||
@@ -215,6 +231,11 @@ namespace sdbus {
|
||||
/*** ------------------ ***/
|
||||
|
||||
inline AsyncMethodInvoker::AsyncMethodInvoker(IProxy& proxy, const MethodName& methodName)
|
||||
: AsyncMethodInvoker(proxy, methodName.c_str())
|
||||
{
|
||||
}
|
||||
|
||||
inline AsyncMethodInvoker::AsyncMethodInvoker(IProxy& proxy, const char* methodName)
|
||||
: proxy_(proxy)
|
||||
, methodName_(methodName)
|
||||
{
|
||||
@@ -222,16 +243,19 @@ namespace sdbus {
|
||||
|
||||
inline AsyncMethodInvoker& AsyncMethodInvoker::onInterface(const InterfaceName& interfaceName)
|
||||
{
|
||||
method_ = proxy_.createMethodCall(interfaceName, methodName_);
|
||||
|
||||
return *this;
|
||||
return onInterface(interfaceName.c_str());
|
||||
}
|
||||
|
||||
inline AsyncMethodInvoker& AsyncMethodInvoker::onInterface(const std::string& interfaceName)
|
||||
{
|
||||
// Down-cast through static cast for performance reasons (no extra copy and object construction needed)
|
||||
static_assert(sizeof(interfaceName) == sizeof(InterfaceName));
|
||||
return onInterface(static_cast<const InterfaceName&>(interfaceName));
|
||||
return onInterface(interfaceName.c_str());
|
||||
}
|
||||
|
||||
inline AsyncMethodInvoker& AsyncMethodInvoker::onInterface(const char* interfaceName)
|
||||
{
|
||||
method_ = proxy_.createMethodCall(interfaceName, methodName_);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline AsyncMethodInvoker& AsyncMethodInvoker::withTimeout(uint64_t usec)
|
||||
@@ -320,17 +344,27 @@ namespace sdbus {
|
||||
/*** ---------------- ***/
|
||||
|
||||
inline SignalSubscriber::SignalSubscriber(IProxy& proxy, const SignalName& signalName)
|
||||
: SignalSubscriber(proxy, signalName.c_str())
|
||||
{
|
||||
}
|
||||
|
||||
inline SignalSubscriber::SignalSubscriber(IProxy& proxy, const char* signalName)
|
||||
: proxy_(proxy)
|
||||
, signalName_(signalName)
|
||||
{
|
||||
}
|
||||
|
||||
inline SignalSubscriber& SignalSubscriber::onInterface(std::string interfaceName)
|
||||
inline SignalSubscriber& SignalSubscriber::onInterface(const InterfaceName& interfaceName)
|
||||
{
|
||||
return onInterface(InterfaceName{std::move(interfaceName)});
|
||||
return onInterface(interfaceName.c_str());
|
||||
}
|
||||
|
||||
inline SignalSubscriber& SignalSubscriber::onInterface(InterfaceName interfaceName)
|
||||
inline SignalSubscriber& SignalSubscriber::onInterface(const std::string& interfaceName)
|
||||
{
|
||||
return onInterface(interfaceName.c_str());
|
||||
}
|
||||
|
||||
inline SignalSubscriber& SignalSubscriber::onInterface(const char* interfaceName)
|
||||
{
|
||||
interfaceName_ = std::move(interfaceName);
|
||||
|
||||
@@ -340,7 +374,7 @@ namespace sdbus {
|
||||
template <typename _Function>
|
||||
inline void SignalSubscriber::call(_Function&& callback)
|
||||
{
|
||||
assert(!interfaceName_.empty()); // onInterface() must be placed/called prior to this function
|
||||
assert(interfaceName_ != nullptr); // onInterface() must be placed/called prior to this function
|
||||
|
||||
proxy_.registerSignalHandler( interfaceName_
|
||||
, signalName_
|
||||
@@ -350,7 +384,7 @@ namespace sdbus {
|
||||
template <typename _Function>
|
||||
[[nodiscard]] inline Slot SignalSubscriber::call(_Function&& callback, return_slot_t)
|
||||
{
|
||||
assert(!interfaceName_.empty()); // onInterface() must be placed/called prior to this function
|
||||
assert(interfaceName_ != nullptr); // onInterface() must be placed/called prior to this function
|
||||
|
||||
return proxy_.registerSignalHandler( interfaceName_
|
||||
, signalName_
|
||||
|
||||
+27
-20
@@ -225,26 +225,15 @@ namespace sdbus {
|
||||
[[nodiscard]] SignalEmitter emitSignal(const SignalName& signalName);
|
||||
|
||||
/*!
|
||||
* @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 = ...;
|
||||
* object_.emitSignal("fooSignal").onInterface("com.kistler.foo").withArguments(arg1, arg2);
|
||||
* @endcode
|
||||
*
|
||||
* @throws sdbus::Error in case of failure
|
||||
* @copydoc IObject::emitSignal(const SignalName&)
|
||||
*/
|
||||
[[nodiscard]] SignalEmitter emitSignal(const std::string& signalName);
|
||||
|
||||
/*!
|
||||
* @copydoc IObject::emitSignal(const SignalName&)
|
||||
*/
|
||||
[[nodiscard]] SignalEmitter emitSignal(const char* signalName);
|
||||
|
||||
/*!
|
||||
* @brief Emits PropertyChanged signal for specified properties under a given interface of this object path
|
||||
*
|
||||
@@ -255,6 +244,11 @@ namespace sdbus {
|
||||
*/
|
||||
virtual void emitPropertiesChangedSignal(const InterfaceName& interfaceName, const std::vector<PropertyName>& propNames) = 0;
|
||||
|
||||
/*!
|
||||
* @copydoc IObject::emitPropertiesChangedSignal(const InterfaceName&,const std::vector<PropertyName>&)
|
||||
*/
|
||||
virtual void emitPropertiesChangedSignal(const char* interfaceName, const std::vector<PropertyName>& propNames) = 0;
|
||||
|
||||
/*!
|
||||
* @brief Emits PropertyChanged signal for all properties on a given interface of this object path
|
||||
*
|
||||
@@ -264,6 +258,11 @@ namespace sdbus {
|
||||
*/
|
||||
virtual void emitPropertiesChangedSignal(const InterfaceName& interfaceName) = 0;
|
||||
|
||||
/*!
|
||||
* @copydoc IObject::emitPropertiesChangedSignal(const InterfaceName&)
|
||||
*/
|
||||
virtual void emitPropertiesChangedSignal(const char* interfaceName) = 0;
|
||||
|
||||
/*!
|
||||
* @brief Emits InterfacesAdded signal on this object path
|
||||
*
|
||||
@@ -361,6 +360,11 @@ namespace sdbus {
|
||||
* @return Currently processed D-Bus message
|
||||
*/
|
||||
[[nodiscard]] virtual Message getCurrentlyProcessedMessage() const = 0;
|
||||
|
||||
protected:
|
||||
friend SignalEmitter;
|
||||
|
||||
[[nodiscard]] virtual Signal createSignal(const char* interfaceName, const char* signalName) = 0;
|
||||
};
|
||||
|
||||
// Out-of-line member definitions
|
||||
@@ -372,9 +376,12 @@ namespace sdbus {
|
||||
|
||||
inline SignalEmitter IObject::emitSignal(const std::string& signalName)
|
||||
{
|
||||
// Down-cast through static cast for performance reasons (no extra copy and object construction needed)
|
||||
static_assert(sizeof(signalName) == sizeof(SignalName));
|
||||
return emitSignal(static_cast<const SignalName&>(signalName));
|
||||
return SignalEmitter(*this, signalName.c_str());
|
||||
}
|
||||
|
||||
inline SignalEmitter IObject::emitSignal(const char* signalName)
|
||||
{
|
||||
return SignalEmitter(*this, signalName);
|
||||
}
|
||||
|
||||
template <typename... VTableItems, typename>
|
||||
|
||||
+57
-25
@@ -226,6 +226,11 @@ namespace sdbus {
|
||||
*/
|
||||
[[nodiscard]] MethodInvoker callMethod(const std::string& methodName);
|
||||
|
||||
/*!
|
||||
* @copydoc IProxy::callMethod(const MethodName&)
|
||||
*/
|
||||
[[nodiscard]] MethodInvoker callMethod(const char* methodName);
|
||||
|
||||
/*!
|
||||
* @brief Calls method on the D-Bus object asynchronously
|
||||
*
|
||||
@@ -256,6 +261,11 @@ namespace sdbus {
|
||||
*/
|
||||
[[nodiscard]] AsyncMethodInvoker callMethodAsync(const std::string& methodName);
|
||||
|
||||
/*!
|
||||
* @copydoc IProxy::callMethodAsync(const MethodName&)
|
||||
*/
|
||||
[[nodiscard]] AsyncMethodInvoker callMethodAsync(const char* methodName);
|
||||
|
||||
/*!
|
||||
* @brief Registers a handler for the desired signal emitted by the D-Bus object
|
||||
*
|
||||
@@ -323,6 +333,11 @@ namespace sdbus {
|
||||
*/
|
||||
[[nodiscard]] SignalSubscriber uponSignal(const std::string& signalName);
|
||||
|
||||
/*!
|
||||
* @copydoc IProxy::uponSignal(const SignalName&)
|
||||
*/
|
||||
[[nodiscard]] SignalSubscriber uponSignal(const char* signalName);
|
||||
|
||||
/*!
|
||||
* @brief Unregisters proxy's signal handlers and stops receiving replies to pending async calls
|
||||
*
|
||||
@@ -384,7 +399,7 @@ namespace sdbus {
|
||||
/*!
|
||||
* @copydoc IProxy::getPropertyAsync(const PropertyName&)
|
||||
*/
|
||||
[[nodiscard]] AsyncPropertyGetter getPropertyAsync(const std::string& propertyName);
|
||||
[[nodiscard]] AsyncPropertyGetter getPropertyAsync(std::string_view propertyName);
|
||||
|
||||
/*!
|
||||
* @brief Sets value of a property of the D-Bus object
|
||||
@@ -411,7 +426,7 @@ namespace sdbus {
|
||||
/*!
|
||||
* @copydoc IProxy::setProperty(const PropertyName&)
|
||||
*/
|
||||
[[nodiscard]] PropertySetter setProperty(const std::string& propertyName);
|
||||
[[nodiscard]] PropertySetter setProperty(std::string_view propertyName);
|
||||
|
||||
/*!
|
||||
* @brief Sets value of a property of the D-Bus object asynchronously
|
||||
@@ -436,7 +451,7 @@ namespace sdbus {
|
||||
/*!
|
||||
* @copydoc IProxy::setPropertyAsync(const PropertyName&)
|
||||
*/
|
||||
[[nodiscard]] AsyncPropertySetter setPropertyAsync(const std::string& propertyName);
|
||||
[[nodiscard]] AsyncPropertySetter setPropertyAsync(std::string_view propertyName);
|
||||
|
||||
/*!
|
||||
* @brief Gets values of all properties of the D-Bus object
|
||||
@@ -499,6 +514,20 @@ namespace sdbus {
|
||||
* @return Currently processed D-Bus message
|
||||
*/
|
||||
[[nodiscard]] virtual Message getCurrentlyProcessedMessage() const = 0;
|
||||
|
||||
protected:
|
||||
friend MethodInvoker;
|
||||
friend AsyncMethodInvoker;
|
||||
friend SignalSubscriber;
|
||||
|
||||
[[nodiscard]] virtual MethodCall createMethodCall(const char* interfaceName, const char* methodName) = 0;
|
||||
virtual void registerSignalHandler( const char* interfaceName
|
||||
, const char* signalName
|
||||
, signal_handler signalHandler ) = 0;
|
||||
[[nodiscard]] virtual Slot registerSignalHandler( const char* interfaceName
|
||||
, const char* signalName
|
||||
, signal_handler signalHandler
|
||||
, return_slot_t ) = 0;
|
||||
};
|
||||
|
||||
/********************************************//**
|
||||
@@ -577,9 +606,12 @@ namespace sdbus {
|
||||
|
||||
inline MethodInvoker IProxy::callMethod(const std::string& methodName)
|
||||
{
|
||||
// Down-cast through static cast for performance reasons (no extra copy and object construction needed)
|
||||
static_assert(sizeof(methodName) == sizeof(MethodName));
|
||||
return callMethod(static_cast<const MethodName&>(methodName));
|
||||
return MethodInvoker(*this, methodName.c_str());
|
||||
}
|
||||
|
||||
inline MethodInvoker IProxy::callMethod(const char* methodName)
|
||||
{
|
||||
return MethodInvoker(*this, methodName);
|
||||
}
|
||||
|
||||
inline AsyncMethodInvoker IProxy::callMethodAsync(const MethodName& methodName)
|
||||
@@ -589,9 +621,12 @@ namespace sdbus {
|
||||
|
||||
inline AsyncMethodInvoker IProxy::callMethodAsync(const std::string& methodName)
|
||||
{
|
||||
// Down-cast through static cast for performance reasons (no extra copy and object construction needed)
|
||||
static_assert(sizeof(methodName) == sizeof(MethodName));
|
||||
return callMethodAsync(static_cast<const MethodName&>(methodName));
|
||||
return AsyncMethodInvoker(*this, methodName.c_str());
|
||||
}
|
||||
|
||||
inline AsyncMethodInvoker IProxy::callMethodAsync(const char* methodName)
|
||||
{
|
||||
return AsyncMethodInvoker(*this, methodName);
|
||||
}
|
||||
|
||||
inline SignalSubscriber IProxy::uponSignal(const SignalName& signalName)
|
||||
@@ -601,9 +636,12 @@ namespace sdbus {
|
||||
|
||||
inline SignalSubscriber IProxy::uponSignal(const std::string& signalName)
|
||||
{
|
||||
// Down-cast through static cast for performance reasons (no extra copy and object construction needed)
|
||||
static_assert(sizeof(signalName) == sizeof(SignalName));
|
||||
return uponSignal(static_cast<const SignalName&>(signalName));
|
||||
return SignalSubscriber(*this, signalName.c_str());
|
||||
}
|
||||
|
||||
inline SignalSubscriber IProxy::uponSignal(const char* signalName)
|
||||
{
|
||||
return SignalSubscriber(*this, signalName);
|
||||
}
|
||||
|
||||
inline PropertyGetter IProxy::getProperty(const PropertyName& propertyName)
|
||||
@@ -613,7 +651,7 @@ namespace sdbus {
|
||||
|
||||
inline PropertyGetter IProxy::getProperty(std::string_view propertyName)
|
||||
{
|
||||
return PropertyGetter(*this, propertyName);
|
||||
return PropertyGetter(*this, std::move(propertyName));
|
||||
}
|
||||
|
||||
inline AsyncPropertyGetter IProxy::getPropertyAsync(const PropertyName& propertyName)
|
||||
@@ -621,11 +659,9 @@ namespace sdbus {
|
||||
return AsyncPropertyGetter(*this, propertyName);
|
||||
}
|
||||
|
||||
inline AsyncPropertyGetter IProxy::getPropertyAsync(const std::string& propertyName)
|
||||
inline AsyncPropertyGetter IProxy::getPropertyAsync(std::string_view propertyName)
|
||||
{
|
||||
// Down-cast through static cast for performance reasons (no extra copy and object construction needed)
|
||||
static_assert(sizeof(propertyName) == sizeof(PropertyName));
|
||||
return getPropertyAsync(static_cast<const PropertyName&>(propertyName));
|
||||
return AsyncPropertyGetter(*this, std::move(propertyName));
|
||||
}
|
||||
|
||||
inline PropertySetter IProxy::setProperty(const PropertyName& propertyName)
|
||||
@@ -633,11 +669,9 @@ namespace sdbus {
|
||||
return PropertySetter(*this, propertyName);
|
||||
}
|
||||
|
||||
inline PropertySetter IProxy::setProperty(const std::string& propertyName)
|
||||
inline PropertySetter IProxy::setProperty(std::string_view propertyName)
|
||||
{
|
||||
// Down-cast through static cast for performance reasons (no extra copy and object construction needed)
|
||||
static_assert(sizeof(propertyName) == sizeof(PropertyName));
|
||||
return setProperty(static_cast<const PropertyName&>(propertyName));
|
||||
return PropertySetter(*this, std::move(propertyName));
|
||||
}
|
||||
|
||||
inline AsyncPropertySetter IProxy::setPropertyAsync(const PropertyName& propertyName)
|
||||
@@ -645,11 +679,9 @@ namespace sdbus {
|
||||
return AsyncPropertySetter(*this, propertyName);
|
||||
}
|
||||
|
||||
inline AsyncPropertySetter IProxy::setPropertyAsync(const std::string& propertyName)
|
||||
inline AsyncPropertySetter IProxy::setPropertyAsync(std::string_view propertyName)
|
||||
{
|
||||
// Down-cast through static cast for performance reasons (no extra copy and object construction needed)
|
||||
static_assert(sizeof(propertyName) == sizeof(PropertyName));
|
||||
return setPropertyAsync(static_cast<const PropertyName&>(propertyName));
|
||||
return AsyncPropertySetter(*this, std::move(propertyName));
|
||||
}
|
||||
|
||||
inline AllPropertiesGetter IProxy::getAllProperties()
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <sdbus-c++/IProxy.h>
|
||||
#include <sdbus-c++/Types.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
@@ -39,7 +40,7 @@ namespace sdbus {
|
||||
// Proxy for peer
|
||||
class Peer_proxy
|
||||
{
|
||||
static inline const InterfaceName INTERFACE_NAME{"org.freedesktop.DBus.Peer"};
|
||||
static inline const char* INTERFACE_NAME = "org.freedesktop.DBus.Peer";
|
||||
|
||||
protected:
|
||||
Peer_proxy(sdbus::IProxy& proxy)
|
||||
@@ -78,7 +79,7 @@ namespace sdbus {
|
||||
// Proxy for introspection
|
||||
class Introspectable_proxy
|
||||
{
|
||||
static inline const InterfaceName INTERFACE_NAME{"org.freedesktop.DBus.Introspectable"};
|
||||
static inline const char* INTERFACE_NAME = "org.freedesktop.DBus.Introspectable";
|
||||
|
||||
protected:
|
||||
Introspectable_proxy(sdbus::IProxy& proxy)
|
||||
@@ -112,7 +113,7 @@ namespace sdbus {
|
||||
// Proxy for properties
|
||||
class Properties_proxy
|
||||
{
|
||||
static inline const InterfaceName INTERFACE_NAME{"org.freedesktop.DBus.Properties"};
|
||||
static inline const char* INTERFACE_NAME = "org.freedesktop.DBus.Properties";
|
||||
|
||||
protected:
|
||||
Properties_proxy(sdbus::IProxy& proxy)
|
||||
@@ -150,7 +151,7 @@ namespace sdbus {
|
||||
return proxy_->getProperty(propertyName).onInterface(interfaceName);
|
||||
}
|
||||
|
||||
sdbus::Variant Get(const InterfaceName& interfaceName, std::string_view propertyName)
|
||||
sdbus::Variant Get(std::string_view interfaceName, std::string_view propertyName)
|
||||
{
|
||||
return proxy_->getProperty(propertyName).onInterface(interfaceName);
|
||||
}
|
||||
@@ -162,7 +163,7 @@ namespace sdbus {
|
||||
}
|
||||
|
||||
template <typename _Function>
|
||||
PendingAsyncCall GetAsync(const InterfaceName& interfaceName, const std::string& propertyName, _Function&& callback)
|
||||
PendingAsyncCall GetAsync(std::string_view interfaceName, std::string_view propertyName, _Function&& callback)
|
||||
{
|
||||
return proxy_->getPropertyAsync(propertyName).onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback));
|
||||
}
|
||||
@@ -172,7 +173,7 @@ namespace sdbus {
|
||||
return proxy_->getPropertyAsync(propertyName).onInterface(interfaceName).getResultAsFuture();
|
||||
}
|
||||
|
||||
std::future<sdbus::Variant> GetAsync(const InterfaceName& interfaceName, const std::string& propertyName, with_future_t)
|
||||
std::future<sdbus::Variant> GetAsync(std::string_view interfaceName, std::string_view propertyName, with_future_t)
|
||||
{
|
||||
return proxy_->getPropertyAsync(propertyName).onInterface(interfaceName).getResultAsFuture();
|
||||
}
|
||||
@@ -182,7 +183,7 @@ namespace sdbus {
|
||||
proxy_->setProperty(propertyName).onInterface(interfaceName).toValue(value);
|
||||
}
|
||||
|
||||
void Set(const InterfaceName& interfaceName, const std::string& propertyName, const sdbus::Variant& value)
|
||||
void Set(std::string_view interfaceName, const std::string_view propertyName, const sdbus::Variant& value)
|
||||
{
|
||||
proxy_->setProperty(propertyName).onInterface(interfaceName).toValue(value);
|
||||
}
|
||||
@@ -192,7 +193,7 @@ namespace sdbus {
|
||||
proxy_->setProperty(propertyName).onInterface(interfaceName).toValue(value, dont_expect_reply);
|
||||
}
|
||||
|
||||
void Set(const InterfaceName& interfaceName, const std::string& propertyName, const sdbus::Variant& value, dont_expect_reply_t)
|
||||
void Set(std::string_view interfaceName, const std::string_view propertyName, const sdbus::Variant& value, dont_expect_reply_t)
|
||||
{
|
||||
proxy_->setProperty(propertyName).onInterface(interfaceName).toValue(value, dont_expect_reply);
|
||||
}
|
||||
@@ -204,7 +205,7 @@ namespace sdbus {
|
||||
}
|
||||
|
||||
template <typename _Function>
|
||||
PendingAsyncCall SetAsync(const InterfaceName& interfaceName, const std::string& propertyName, const sdbus::Variant& value, _Function&& callback)
|
||||
PendingAsyncCall SetAsync(std::string_view interfaceName, std::string_view propertyName, const sdbus::Variant& value, _Function&& callback)
|
||||
{
|
||||
return proxy_->setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).uponReplyInvoke(std::forward<_Function>(callback));
|
||||
}
|
||||
@@ -214,7 +215,7 @@ namespace sdbus {
|
||||
return proxy_->setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).getResultAsFuture();
|
||||
}
|
||||
|
||||
std::future<void> SetAsync(const InterfaceName& interfaceName, const std::string& propertyName, const sdbus::Variant& value, with_future_t)
|
||||
std::future<void> SetAsync(std::string_view interfaceName, std::string_view propertyName, const sdbus::Variant& value, with_future_t)
|
||||
{
|
||||
return proxy_->setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).getResultAsFuture();
|
||||
}
|
||||
@@ -224,17 +225,33 @@ namespace sdbus {
|
||||
return proxy_->getAllProperties().onInterface(interfaceName);
|
||||
}
|
||||
|
||||
std::map<PropertyName, sdbus::Variant> GetAll(std::string_view interfaceName)
|
||||
{
|
||||
return proxy_->getAllProperties().onInterface(interfaceName);
|
||||
}
|
||||
|
||||
template <typename _Function>
|
||||
PendingAsyncCall GetAllAsync(const InterfaceName& interfaceName, _Function&& callback)
|
||||
{
|
||||
return proxy_->getAllPropertiesAsync().onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback));
|
||||
}
|
||||
|
||||
template <typename _Function>
|
||||
PendingAsyncCall GetAllAsync(std::string_view interfaceName, _Function&& callback)
|
||||
{
|
||||
return proxy_->getAllPropertiesAsync().onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback));
|
||||
}
|
||||
|
||||
std::future<std::map<PropertyName, sdbus::Variant>> GetAllAsync(const InterfaceName& interfaceName, with_future_t)
|
||||
{
|
||||
return proxy_->getAllPropertiesAsync().onInterface(interfaceName).getResultAsFuture();
|
||||
}
|
||||
|
||||
std::future<std::map<PropertyName, sdbus::Variant>> GetAllAsync(std::string_view interfaceName, with_future_t)
|
||||
{
|
||||
return proxy_->getAllPropertiesAsync().onInterface(interfaceName).getResultAsFuture();
|
||||
}
|
||||
|
||||
private:
|
||||
sdbus::IProxy* proxy_;
|
||||
};
|
||||
@@ -242,7 +259,7 @@ namespace sdbus {
|
||||
// Proxy for object manager
|
||||
class ObjectManager_proxy
|
||||
{
|
||||
static inline const InterfaceName INTERFACE_NAME{"org.freedesktop.DBus.ObjectManager"};
|
||||
static inline const char* INTERFACE_NAME = "org.freedesktop.DBus.ObjectManager";
|
||||
|
||||
protected:
|
||||
ObjectManager_proxy(sdbus::IProxy& proxy)
|
||||
@@ -301,7 +318,7 @@ namespace sdbus {
|
||||
// Adaptor for properties
|
||||
class Properties_adaptor
|
||||
{
|
||||
static inline const InterfaceName INTERFACE_NAME{"org.freedesktop.DBus.Properties"};
|
||||
static inline const char* INTERFACE_NAME = "org.freedesktop.DBus.Properties";
|
||||
|
||||
protected:
|
||||
Properties_adaptor(sdbus::IObject& object) : object_(&object)
|
||||
@@ -325,11 +342,21 @@ namespace sdbus {
|
||||
object_->emitPropertiesChangedSignal(interfaceName, properties);
|
||||
}
|
||||
|
||||
void emitPropertiesChangedSignal(const char* interfaceName, const std::vector<PropertyName>& properties)
|
||||
{
|
||||
object_->emitPropertiesChangedSignal(interfaceName, properties);
|
||||
}
|
||||
|
||||
void emitPropertiesChangedSignal(const InterfaceName& interfaceName)
|
||||
{
|
||||
object_->emitPropertiesChangedSignal(interfaceName);
|
||||
}
|
||||
|
||||
void emitPropertiesChangedSignal(const char* interfaceName)
|
||||
{
|
||||
object_->emitPropertiesChangedSignal(interfaceName);
|
||||
}
|
||||
|
||||
private:
|
||||
sdbus::IObject* object_;
|
||||
};
|
||||
@@ -346,7 +373,7 @@ namespace sdbus {
|
||||
*/
|
||||
class ObjectManager_adaptor
|
||||
{
|
||||
static inline const InterfaceName INTERFACE_NAME{"org.freedesktop.DBus.ObjectManager"};
|
||||
static inline const char* INTERFACE_NAME = "org.freedesktop.DBus.ObjectManager";
|
||||
|
||||
protected:
|
||||
explicit ObjectManager_adaptor(sdbus::IObject& object) : object_(&object)
|
||||
|
||||
Reference in New Issue
Block a user