summaryrefslogtreecommitdiffstats
path: root/sdbusplus/asio
diff options
context:
space:
mode:
authorJames Feist <james.feist@linux.intel.com>2019-06-04 14:11:48 -0700
committerJames Feist <james.feist@linux.intel.com>2019-06-04 15:19:12 -0700
commitc14699f63e909ed6d8599e65503ee9c1e3a104d6 (patch)
treef1c97de847ec34c78f5f0d0ec19d2573752b0b2d /sdbusplus/asio
parent66ef099b5a77315bb531300dfcc81a53867cd5fa (diff)
downloadsdbusplus-c14699f63e909ed6d8599e65503ee9c1e3a104d6.tar.gz
sdbusplus-c14699f63e909ed6d8599e65503ee9c1e3a104d6.zip
asio: Allow mutable lambdas + small cleanup
There are many cases in which we want to have a mutable capture so that the lambda takes over the parameter and we can modify it after the async callback. By making the top level lambda mutable, the users callback can be mutable. Also remove a couple references to experimental and a copy that I saw when I was fixing this issue. Tested: Added test and made sure that refish which uses many async_method_calls still worked fine Change-Id: Ifb1f9d8b9217187799e2defe429e76a937297ca1 Signed-off-by: James Feist <james.feist@linux.intel.com>
Diffstat (limited to 'sdbusplus/asio')
-rw-r--r--sdbusplus/asio/connection.hpp11
-rw-r--r--sdbusplus/asio/object_server.hpp8
2 files changed, 10 insertions, 9 deletions
diff --git a/sdbusplus/asio/connection.hpp b/sdbusplus/asio/connection.hpp
index 083bfdf..4c447f8 100644
--- a/sdbusplus/asio/connection.hpp
+++ b/sdbusplus/asio/connection.hpp
@@ -25,12 +25,12 @@
#include <boost/asio/spawn.hpp>
#include <boost/callable_traits.hpp>
#include <chrono>
-#include <experimental/tuple>
#include <sdbusplus/asio/detail/async_send_handler.hpp>
#include <sdbusplus/message.hpp>
#include <sdbusplus/utility/read_into_tuple.hpp>
#include <sdbusplus/utility/type_traits.hpp>
#include <string>
+#include <tuple>
namespace sdbusplus
{
@@ -115,7 +115,7 @@ class connection : public sdbusplus::bus::bus
* complete.
*/
template <typename MessageHandler, typename... InputArgs>
- void async_method_call(MessageHandler handler, const std::string& service,
+ void async_method_call(MessageHandler&& handler, const std::string& service,
const std::string& objpath,
const std::string& interf, const std::string& method,
const InputArgs&... a)
@@ -123,8 +123,9 @@ class connection : public sdbusplus::bus::bus
message::message m = new_method_call(service.c_str(), objpath.c_str(),
interf.c_str(), method.c_str());
m.append(a...);
- async_send(m, [handler](boost::system::error_code ec,
- message::message& r) {
+ async_send(m, [handler = std::forward<MessageHandler>(handler)](
+ boost::system::error_code ec,
+ message::message& r) mutable {
using FunctionTuple =
boost::callable_traits::args_t<MessageHandler>;
using UnpackType = typename utility::strip_first_arg<
@@ -146,7 +147,7 @@ class connection : public sdbusplus::bus::bus
// Note. Callback is called whether or not the unpack was
// successful to allow the user to implement their own handling
auto response = std::tuple_cat(std::make_tuple(ec), responseData);
- std::experimental::apply(handler, response);
+ std::apply(handler, response);
});
}
diff --git a/sdbusplus/asio/object_server.hpp b/sdbusplus/asio/object_server.hpp
index fda791b..5ec0a58 100644
--- a/sdbusplus/asio/object_server.hpp
+++ b/sdbusplus/asio/object_server.hpp
@@ -128,14 +128,14 @@ class callback_method_instance : public callback
std::enable_if_t<!std::is_void<T>::value, void>
callFunction(message::message& m, InputTupleType& inputArgs)
{
- ResultType r = std::experimental::apply(func_, inputArgs);
+ ResultType r = std::apply(func_, inputArgs);
m.append(r);
}
template <typename T>
std::enable_if_t<std::is_void<T>::value, void>
callFunction(message::message& m, InputTupleType& inputArgs)
{
- std::experimental::apply(func_, inputArgs);
+ std::apply(func_, inputArgs);
}
#ifdef __cpp_if_constexpr
// optional message-first-argument callback
@@ -218,14 +218,14 @@ class coroutine_method_instance : public callback
std::enable_if_t<!std::is_void<T>::value, void>
callFunction(message::message& m, InputTupleType& inputArgs)
{
- ResultType r = std::experimental::apply(func_, inputArgs);
+ ResultType r = std::apply(func_, inputArgs);
m.append(r);
}
template <typename T>
std::enable_if_t<std::is_void<T>::value, void>
callFunction(message::message& m, InputTupleType& inputArgs)
{
- std::experimental::apply(func_, inputArgs);
+ std::apply(func_, inputArgs);
}
// co-routine body for call
void expandCall(boost::asio::yield_context yield, message::message& m)
OpenPOWER on IntegriCloud