Break out post-spawn lambda into method
This lambda really is too long to be inline. Break it out into a method
for clarity.
Change-Id: I561850156d8582ebc2b68657949a4f4f5bf7a4d6
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/include/sdbusplus/asio/object_server.hpp b/include/sdbusplus/asio/object_server.hpp
index de0feeb..e45bfae 100644
--- a/include/sdbusplus/asio/object_server.hpp
+++ b/include/sdbusplus/asio/object_server.hpp
@@ -166,48 +166,53 @@
class coroutine_method_instance : public callback
{
public:
+ using self_t = coroutine_method_instance<CallbackType>;
+
coroutine_method_instance(boost::asio::io_context& io,
CallbackType&& func) :
io_(io),
func_(std::move(func))
{}
+
int call(message_t& m) override
{
// make a copy of m to move into the coroutine
message_t b{m};
// spawn off a new coroutine to handle the method call
- boost::asio::spawn(
- io_, [this, b = std::move(b)](boost::asio::yield_context yield) {
- message_t mcpy{std::move(b)};
- std::optional<message_t> err{};
-
- try
- {
- expandCall(yield, mcpy);
- }
- catch (const sdbusplus::exception::SdBusError& e)
- {
- // Catch D-Bus error explicitly called by method handler
- err = mcpy.new_method_errno(e.get_errno(), e.get_error());
- }
- catch (const sdbusplus::exception_t& e)
- {
- err = mcpy.new_method_error(e);
- }
- catch (...)
- {
- err = mcpy.new_method_errno(-EIO);
- }
-
- if (err)
- {
- err->method_return();
- }
- });
+ boost::asio::spawn(io_, std::bind_front(&self_t::after_spawn, this, b));
return 1;
}
private:
+ void after_spawn(message_t b, boost::asio::yield_context yield)
+ {
+ message_t mcpy{std::move(b)};
+ std::optional<message_t> err{};
+
+ try
+ {
+ expandCall(yield, mcpy);
+ }
+ catch (const sdbusplus::exception::SdBusError& e)
+ {
+ // Catch D-Bus error explicitly called by method handler
+ err = mcpy.new_method_errno(e.get_errno(), e.get_error());
+ }
+ catch (const sdbusplus::exception_t& e)
+ {
+ err = mcpy.new_method_error(e);
+ }
+ catch (...)
+ {
+ err = mcpy.new_method_errno(-EIO);
+ }
+
+ if (err)
+ {
+ err->method_return();
+ }
+ }
+
using CallbackSignature = boost::callable_traits::args_t<CallbackType>;
using InputTupleType = utility::decay_tuple_t<CallbackSignature>;
boost::asio::io_context& io_;