Break out callFunction
This function is duplicated between both classes, break it out into its
own function to deduplicate the code.
Change-Id: I24dea73a79af6224d80a607b090eb1fffbe92fd6
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 2840373..756f53a 100644
--- a/include/sdbusplus/asio/object_server.hpp
+++ b/include/sdbusplus/asio/object_server.hpp
@@ -105,6 +105,21 @@
};
} // namespace details
+template <typename InputArgs, typename Callback>
+void callFunction(message_t& m, InputArgs& inputArgs, Callback&& callback)
+{
+ using ResultType = boost::callable_traits::return_type_t<Callback>;
+ if constexpr (std::is_void_v<ResultType>)
+ {
+ std::apply(callback, inputArgs);
+ }
+ else
+ {
+ auto r = std::apply(callback, inputArgs);
+ m.append(r);
+ }
+}
+
template <typename CallbackType>
class callback_method_instance : public callback
{
@@ -118,22 +133,8 @@
private:
using CallbackSignature = boost::callable_traits::args_t<CallbackType>;
using InputTupleType = utility::decay_tuple_t<CallbackSignature>;
- using ResultType = boost::callable_traits::return_type_t<CallbackType>;
CallbackType func_;
- void callFunction(message_t& m, InputTupleType& inputArgs)
- {
- if constexpr (std::is_void_v<ResultType>)
- {
- std::apply(func_, inputArgs);
- }
- else
- {
- auto r = std::apply(func_, inputArgs);
- m.append(r);
- }
- }
-
// optional message-first-argument callback
int expandCall(message_t& m)
{
@@ -156,7 +157,7 @@
{
inputArgs.emplace(dbusArgs);
}
- callFunction(ret, *inputArgs);
+ callFunction(ret, *inputArgs, func_);
ret.method_return();
return 1;
}
@@ -210,23 +211,9 @@
private:
using CallbackSignature = boost::callable_traits::args_t<CallbackType>;
using InputTupleType = utility::decay_tuple_t<CallbackSignature>;
- using ResultType = boost::callable_traits::return_type_t<CallbackType>;
boost::asio::io_context& io_;
CallbackType func_;
- void callFunction(message_t& m, InputTupleType& inputArgs)
- {
- if constexpr (std::is_void_v<ResultType>)
- {
- std::apply(func_, inputArgs);
- }
- else
- {
- auto r = std::apply(func_, inputArgs);
- m.append(r);
- }
- }
-
// co-routine body for call
void expandCall(boost::asio::yield_context yield, message_t& m)
{
@@ -257,7 +244,7 @@
inputArgs.emplace(std::tuple_cat(
std::forward_as_tuple(std::move(yield)), dbusArgs));
}
- callFunction(ret, *inputArgs);
+ callFunction(ret, *inputArgs, func_);
ret.method_return();
}
};