forked from Kistler-Group/sdbus-cpp
refactor: use async tag to denote async calls or operations
This commit is contained in:
@@ -407,7 +407,7 @@ namespace sdbus {
|
||||
|
||||
assert(interfaceName_ != nullptr); // onInterface() must be placed/called prior to this function
|
||||
|
||||
return proxy_.callMethodAsync("Get")
|
||||
return proxy_.callMethod("Get", async)
|
||||
.onInterface("org.freedesktop.DBus.Properties")
|
||||
.withArguments(*interfaceName_, propertyName_)
|
||||
.uponReplyInvoke(std::forward<_Function>(callback));
|
||||
@@ -417,7 +417,7 @@ namespace sdbus {
|
||||
{
|
||||
assert(interfaceName_ != nullptr); // onInterface() must be placed/called prior to this function
|
||||
|
||||
return proxy_.callMethodAsync("Get")
|
||||
return proxy_.callMethod("Get", async)
|
||||
.onInterface("org.freedesktop.DBus.Properties")
|
||||
.withArguments(*interfaceName_, propertyName_)
|
||||
.getResultAsFuture<Variant>();
|
||||
@@ -508,7 +508,7 @@ namespace sdbus {
|
||||
|
||||
assert(interfaceName_ != nullptr); // onInterface() must be placed/called prior to this function
|
||||
|
||||
return proxy_.callMethodAsync("Set")
|
||||
return proxy_.callMethod("Set", async)
|
||||
.onInterface("org.freedesktop.DBus.Properties")
|
||||
.withArguments(*interfaceName_, propertyName_, std::move(value_))
|
||||
.uponReplyInvoke(std::forward<_Function>(callback));
|
||||
@@ -518,7 +518,7 @@ namespace sdbus {
|
||||
{
|
||||
assert(interfaceName_ != nullptr); // onInterface() must be placed/called prior to this function
|
||||
|
||||
return proxy_.callMethodAsync("Set")
|
||||
return proxy_.callMethod("Set", async)
|
||||
.onInterface("org.freedesktop.DBus.Properties")
|
||||
.withArguments(*interfaceName_, propertyName_, std::move(value_))
|
||||
.getResultAsFuture<>();
|
||||
@@ -567,7 +567,7 @@ namespace sdbus {
|
||||
|
||||
assert(interfaceName_ != nullptr); // onInterface() must be placed/called prior to this function
|
||||
|
||||
return proxy_.callMethodAsync("GetAll")
|
||||
return proxy_.callMethod("GetAll", async)
|
||||
.onInterface("org.freedesktop.DBus.Properties")
|
||||
.withArguments(*interfaceName_)
|
||||
.uponReplyInvoke(std::forward<_Function>(callback));
|
||||
@@ -577,7 +577,7 @@ namespace sdbus {
|
||||
{
|
||||
assert(interfaceName_ != nullptr); // onInterface() must be placed/called prior to this function
|
||||
|
||||
return proxy_.callMethodAsync("GetAll")
|
||||
return proxy_.callMethod("GetAll", async)
|
||||
.onInterface("org.freedesktop.DBus.Properties")
|
||||
.withArguments(*interfaceName_)
|
||||
.getResultAsFuture<std::map<std::string, Variant>>();
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace sdbus {
|
||||
* The same as enterEventLoop, except that it doesn't block
|
||||
* because it runs the loop in a separate, internally managed thread.
|
||||
*/
|
||||
virtual void enterEventLoopAsync() = 0;
|
||||
virtual void enterEventLoop(async_t) = 0;
|
||||
|
||||
/*!
|
||||
* @brief Leaves the I/O event loop running on this bus connection
|
||||
@@ -204,7 +204,7 @@ namespace sdbus {
|
||||
*
|
||||
* You don't need to directly call this method or getEventLoopPollData() method
|
||||
* when using convenient, internal bus connection event loops through
|
||||
* enterEventLoop() or enterEventLoopAsync() calls, or when the bus is
|
||||
* enterEventLoop() or enterEventLoop(async) calls, or when the bus is
|
||||
* connected to an sd-event event loop through attachSdEventLoop().
|
||||
* It is invoked automatically when necessary.
|
||||
*
|
||||
@@ -334,7 +334,7 @@ namespace sdbus {
|
||||
*
|
||||
* @throws sdbus::Error in case of failure
|
||||
*/
|
||||
[[nodiscard]] virtual Slot addMatchAsync(const std::string& match, message_handler callback, message_handler installCallback) = 0;
|
||||
[[nodiscard]] virtual Slot addMatch(const std::string& match, message_handler callback, message_handler installCallback, async_t) = 0;
|
||||
|
||||
/*!
|
||||
* @brief Asynchronously installs a floating match rule for messages received on this bus connection
|
||||
@@ -352,7 +352,9 @@ namespace sdbus {
|
||||
*
|
||||
* @throws sdbus::Error in case of failure
|
||||
*/
|
||||
virtual void addMatchAsync(const std::string& match, message_handler callback, message_handler installCallback, floating_slot_t) = 0;
|
||||
virtual void addMatch(const std::string& match, message_handler callback, message_handler installCallback, async_t, floating_slot_t) = 0;
|
||||
|
||||
// TODO: addMatchAsync with std::future support?
|
||||
|
||||
/*!
|
||||
* @copydoc IConnection::enterEventLoop()
|
||||
@@ -362,11 +364,11 @@ namespace sdbus {
|
||||
[[deprecated("This function has been replaced by enterEventLoop()")]] void enterProcessingLoop();
|
||||
|
||||
/*!
|
||||
* @copydoc IConnection::enterEventLoopAsync()
|
||||
* @copydoc IConnection::enterEventLoop(sdbus::async_t)
|
||||
*
|
||||
* @deprecated This function has been replaced by enterEventLoopAsync()
|
||||
* @deprecated This function has been replaced by enterEventLoop(async_t)
|
||||
*/
|
||||
[[deprecated("This function has been replaced by enterEventLoopAsync()")]] void enterProcessingLoopAsync();
|
||||
[[deprecated("This function has been replaced by enterEventLoop(async_t)")]] void enterProcessingLoopAsync();
|
||||
|
||||
/*!
|
||||
* @copydoc IConnection::leaveEventLoop()
|
||||
@@ -446,7 +448,7 @@ namespace sdbus {
|
||||
|
||||
inline void IConnection::enterProcessingLoopAsync()
|
||||
{
|
||||
enterEventLoopAsync();
|
||||
enterEventLoop(async);
|
||||
}
|
||||
|
||||
inline void IConnection::leaveProcessingLoop()
|
||||
|
||||
+14
-14
@@ -272,15 +272,15 @@ namespace sdbus {
|
||||
* Example of use:
|
||||
* @code
|
||||
* int a = ..., b = ...;
|
||||
* object_.callMethodAsync("multiply").onInterface(INTERFACE_NAME).withArguments(a, b).uponReplyInvoke([](int result)
|
||||
* object_.callMethod("multiply").onInterface(INTERFACE_NAME).withArguments(a, b).uponReplyInvoke([](int result)
|
||||
* {
|
||||
* std::cout << "Got result of multiplying " << a << " and " << b << ": " << result << std::endl;
|
||||
* });
|
||||
* }, sdbus::async);
|
||||
* @endcode
|
||||
*
|
||||
* @throws sdbus::Error in case of failure
|
||||
*/
|
||||
[[nodiscard]] AsyncMethodInvoker callMethodAsync(const std::string& methodName);
|
||||
[[nodiscard]] AsyncMethodInvoker callMethod(const std::string& methodName, async_t);
|
||||
|
||||
/*!
|
||||
* @brief Registers signal handler for a given signal of the D-Bus object
|
||||
@@ -335,14 +335,14 @@ namespace sdbus {
|
||||
*
|
||||
* Example of use:
|
||||
* @code
|
||||
* std::future<sdbus::Variant> state = object.getPropertyAsync("state").onInterface("com.kistler.foo").getResultAsFuture();
|
||||
* std::future<sdbus::Variant> state = object.getProperty("state", sdbus::async).onInterface("com.kistler.foo").getResultAsFuture();
|
||||
* auto callback = [](const sdbus::Error* err, const sdbus::Variant& value){ ... };
|
||||
* object.getPropertyAsync("state").onInterface("com.kistler.foo").uponReplyInvoke(std::move(callback));
|
||||
* object.getProperty("state", sdbus::async).onInterface("com.kistler.foo").uponReplyInvoke(std::move(callback));
|
||||
* @endcode
|
||||
*
|
||||
* @throws sdbus::Error in case of failure
|
||||
*/
|
||||
[[nodiscard]] AsyncPropertyGetter getPropertyAsync(const std::string& propertyName);
|
||||
[[nodiscard]] AsyncPropertyGetter getProperty(const std::string& propertyName, async_t);
|
||||
|
||||
/*!
|
||||
* @brief Sets value of a property of the D-Bus object
|
||||
@@ -379,12 +379,12 @@ namespace sdbus {
|
||||
* @code
|
||||
* int state = ...;
|
||||
* // We can wait until the set operation finishes by waiting on the future
|
||||
* std::future<void> res = object_.setPropertyAsync("state").onInterface("com.kistler.foo").toValue(state).getResultAsFuture();
|
||||
* std::future<void> res = object_.setProperty("state", sdbus::async).onInterface("com.kistler.foo").toValue(state).getResultAsFuture();
|
||||
* @endcode
|
||||
*
|
||||
* @throws sdbus::Error in case of failure
|
||||
*/
|
||||
[[nodiscard]] AsyncPropertySetter setPropertyAsync(const std::string& propertyName);
|
||||
[[nodiscard]] AsyncPropertySetter setProperty(const std::string& propertyName, async_t);
|
||||
|
||||
/*!
|
||||
* @brief Gets values of all properties of the D-Bus object
|
||||
@@ -414,12 +414,12 @@ namespace sdbus {
|
||||
* Example of use:
|
||||
* @code
|
||||
* auto callback = [](const sdbus::Error* err, const std::map<std::string, Variant>>& properties){ ... };
|
||||
* auto props = object.getAllPropertiesAsync().onInterface("com.kistler.foo").uponReplyInvoke(std::move(callback));
|
||||
* auto props = object.getAllProperties(sdbus::async).onInterface("com.kistler.foo").uponReplyInvoke(std::move(callback));
|
||||
* @endcode
|
||||
*
|
||||
* @throws sdbus::Error in case of failure
|
||||
*/
|
||||
[[nodiscard]] AsyncAllPropertiesGetter getAllPropertiesAsync();
|
||||
[[nodiscard]] AsyncAllPropertiesGetter getAllProperties(async_t);
|
||||
|
||||
/*!
|
||||
* @brief Provides D-Bus connection used by the proxy
|
||||
@@ -521,7 +521,7 @@ namespace sdbus {
|
||||
return MethodInvoker(*this, methodName);
|
||||
}
|
||||
|
||||
inline AsyncMethodInvoker IProxy::callMethodAsync(const std::string& methodName)
|
||||
inline AsyncMethodInvoker IProxy::callMethod(const std::string& methodName, async_t)
|
||||
{
|
||||
return AsyncMethodInvoker(*this, methodName);
|
||||
}
|
||||
@@ -536,7 +536,7 @@ namespace sdbus {
|
||||
return PropertyGetter(*this, propertyName);
|
||||
}
|
||||
|
||||
inline AsyncPropertyGetter IProxy::getPropertyAsync(const std::string& propertyName)
|
||||
inline AsyncPropertyGetter IProxy::getProperty(const std::string& propertyName, async_t)
|
||||
{
|
||||
return AsyncPropertyGetter(*this, propertyName);
|
||||
}
|
||||
@@ -546,7 +546,7 @@ namespace sdbus {
|
||||
return PropertySetter(*this, propertyName);
|
||||
}
|
||||
|
||||
inline AsyncPropertySetter IProxy::setPropertyAsync(const std::string& propertyName)
|
||||
inline AsyncPropertySetter IProxy::setProperty(const std::string& propertyName, async_t)
|
||||
{
|
||||
return AsyncPropertySetter(*this, propertyName);
|
||||
}
|
||||
@@ -556,7 +556,7 @@ namespace sdbus {
|
||||
return AllPropertiesGetter(*this);
|
||||
}
|
||||
|
||||
inline AsyncAllPropertiesGetter IProxy::getAllPropertiesAsync()
|
||||
inline AsyncAllPropertiesGetter IProxy::getAllProperties(async_t)
|
||||
{
|
||||
return AsyncAllPropertiesGetter(*this);
|
||||
}
|
||||
|
||||
@@ -151,14 +151,14 @@ namespace sdbus {
|
||||
}
|
||||
|
||||
template <typename _Function>
|
||||
PendingAsyncCall GetAsync(const std::string& interfaceName, const std::string& propertyName, _Function&& callback)
|
||||
PendingAsyncCall Get(const std::string& interfaceName, const std::string& propertyName, _Function&& callback, async_t)
|
||||
{
|
||||
return proxy_->getPropertyAsync(propertyName).onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback));
|
||||
return proxy_->getProperty(propertyName, async).onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback));
|
||||
}
|
||||
|
||||
std::future<sdbus::Variant> GetAsync(const std::string& interfaceName, const std::string& propertyName, with_future_t)
|
||||
std::future<sdbus::Variant> Get(const std::string& interfaceName, const std::string& propertyName, async_t, with_future_t)
|
||||
{
|
||||
return proxy_->getPropertyAsync(propertyName).onInterface(interfaceName).getResultAsFuture();
|
||||
return proxy_->getProperty(propertyName, async).onInterface(interfaceName).getResultAsFuture();
|
||||
}
|
||||
|
||||
void Set(const std::string& interfaceName, const std::string& propertyName, const sdbus::Variant& value)
|
||||
@@ -172,14 +172,14 @@ namespace sdbus {
|
||||
}
|
||||
|
||||
template <typename _Function>
|
||||
PendingAsyncCall SetAsync(const std::string& interfaceName, const std::string& propertyName, const sdbus::Variant& value, _Function&& callback)
|
||||
PendingAsyncCall Set(const std::string& interfaceName, const std::string& propertyName, const sdbus::Variant& value, _Function&& callback, async_t)
|
||||
{
|
||||
return proxy_->setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).uponReplyInvoke(std::forward<_Function>(callback));
|
||||
return proxy_->setProperty(propertyName, async).onInterface(interfaceName).toValue(value).uponReplyInvoke(std::forward<_Function>(callback));
|
||||
}
|
||||
|
||||
std::future<void> SetAsync(const std::string& interfaceName, const std::string& propertyName, const sdbus::Variant& value, with_future_t)
|
||||
std::future<void> Set(const std::string& interfaceName, const std::string& propertyName, const sdbus::Variant& value, async_t, with_future_t)
|
||||
{
|
||||
return proxy_->setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).getResultAsFuture();
|
||||
return proxy_->setProperty(propertyName, async).onInterface(interfaceName).toValue(value).getResultAsFuture();
|
||||
}
|
||||
|
||||
std::map<std::string, sdbus::Variant> GetAll(const std::string& interfaceName)
|
||||
@@ -188,14 +188,14 @@ namespace sdbus {
|
||||
}
|
||||
|
||||
template <typename _Function>
|
||||
PendingAsyncCall GetAllAsync(const std::string& interfaceName, _Function&& callback)
|
||||
PendingAsyncCall GetAll(const std::string& interfaceName, _Function&& callback, async_t)
|
||||
{
|
||||
return proxy_->getAllPropertiesAsync().onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback));
|
||||
return proxy_->getAllProperties(async).onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback));
|
||||
}
|
||||
|
||||
std::future<std::map<std::string, sdbus::Variant>> GetAllAsync(const std::string& interfaceName, with_future_t)
|
||||
std::future<std::map<std::string, sdbus::Variant>> GetAll(const std::string& interfaceName, async_t, with_future_t)
|
||||
{
|
||||
return proxy_->getAllPropertiesAsync().onInterface(interfaceName).getResultAsFuture();
|
||||
return proxy_->getAllProperties(async).onInterface(interfaceName).getResultAsFuture();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -72,6 +72,12 @@ namespace sdbus {
|
||||
// Type-erased RAII-style handle to callbacks/subscriptions registered to sdbus-c++
|
||||
using Slot = std::unique_ptr<void, std::function<void(void*)>>;
|
||||
|
||||
// Tag denoting an asynchronous call or operation
|
||||
struct async_t { explicit async_t() = default; };
|
||||
inline constexpr async_t async{};
|
||||
// Tag denoting a variant of an asynchronous method call that returns std::future instead of accepting
|
||||
struct with_future_t { explicit with_future_t() = default; };
|
||||
inline constexpr with_future_t with_future{};
|
||||
// Tag specifying that an owning slot handle shall be returned from a registration/subscription function to the caller
|
||||
struct return_slot_t { explicit return_slot_t() = default; };
|
||||
inline constexpr return_slot_t return_slot{};
|
||||
@@ -88,9 +94,6 @@ namespace sdbus {
|
||||
// Such proxies are typically created to carry out a simple synchronous D-Bus call(s) and then are destroyed.
|
||||
struct dont_run_event_loop_thread_t { explicit dont_run_event_loop_thread_t() = default; };
|
||||
inline constexpr dont_run_event_loop_thread_t dont_run_event_loop_thread{};
|
||||
// Tag denoting an asynchronous call that returns std::future as a handle
|
||||
struct with_future_t { explicit with_future_t() = default; };
|
||||
inline constexpr with_future_t with_future{};
|
||||
// Tag denoting a call where the reply shouldn't be waited for
|
||||
struct dont_expect_reply_t { explicit dont_expect_reply_t() = default; };
|
||||
inline constexpr dont_expect_reply_t dont_expect_reply{};
|
||||
|
||||
Reference in New Issue
Block a user