asio: unpack in place
The existing code uses several different tuples to do the unpack, then
concatenates them with tuple_cat. Simplify the code by generating a
tuple of references to the dbus args, and unpack directly to the main
struct, thus simplifying the flow.
To accomplish this the make_dbus_args_tuple helper method is added,
which strips the non-dbus arguments from a callback so they can be
unpacked separately. This is relatively complex because this code tries
to support
callback(boost::error_code, message_t, dbus_arg);
as well as
callback(boost::error_code, dbus_arg);
Dynamically dependent on which overload is provided. There's likely
more cleanup that can happen there to separate these two, but this
should at least help.
Tested: OpenBMC launches and runs. Redfish service validator (which
should hit the majority of these overloads) passes.
Change-Id: I6bb7ee960459a505eb8633b1cdb30cd2b3037466
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/test/meson.build b/test/meson.build
index 300c3bc..2b7bcfc 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -37,6 +37,7 @@
'message/types',
'timer',
'unpack_properties',
+ 'utility/make_dbus_args_tuple',
'utility/tuple_to_array',
'utility/type_traits',
]
diff --git a/test/utility/make_dbus_args_tuple.cpp b/test/utility/make_dbus_args_tuple.cpp
new file mode 100644
index 0000000..6ec2d71
--- /dev/null
+++ b/test/utility/make_dbus_args_tuple.cpp
@@ -0,0 +1,49 @@
+#include <boost/system/error_code.hpp>
+#include <sdbusplus/message.hpp>
+#include <sdbusplus/utility/make_dbus_args_tuple.hpp>
+
+#include <gtest/gtest.h>
+
+namespace sdbusplus
+{
+namespace utility
+{
+
+TEST(MakeDbusArgsTuple, MessageFirst)
+{
+ std::tuple<boost::system::error_code, sdbusplus::message_t, int>
+ input_tuple;
+ auto tuple_out = make_dbus_args_tuple(input_tuple);
+ static_assert(
+ std::is_same_v<std::tuple_element_t<0, decltype(tuple_out)>, int&>,
+ "Second type wasn't int");
+ static_assert(std::tuple_size_v<decltype(tuple_out)> == 1,
+ "Size was wrong");
+ // Verify the output reference is now the first member, and references the 2
+ // index tuple arg
+ EXPECT_EQ(&std::get<2>(input_tuple), &std::get<0>(tuple_out));
+}
+TEST(MakeDbusArgsTuple, ArgFirst)
+{
+ std::tuple<boost::system::error_code, int> input_tuple{
+ boost::system::error_code(), 42};
+ auto tuple_out = make_dbus_args_tuple(input_tuple);
+ static_assert(
+ std::is_same_v<std::tuple_element_t<0, decltype(tuple_out)>, int&>,
+ "Second type wasn't int");
+ static_assert(std::tuple_size_v<decltype(tuple_out)> == 1,
+ "Size was wrong");
+ // Verify the output reference is now the first member, and references the 1
+ // index tuple arg
+ EXPECT_EQ(&std::get<1>(input_tuple), &std::get<0>(tuple_out));
+ EXPECT_EQ(std::get<0>(tuple_out), 42);
+}
+TEST(MakeDbusArgsTuple, NoArgs)
+{
+ std::tuple<boost::system::error_code> input_tuple;
+ auto tuple_out = make_dbus_args_tuple(input_tuple);
+ static_assert(std::tuple_size_v<decltype(tuple_out)> == 0,
+ "Size was wrong");
+}
+} // namespace utility
+} // namespace sdbusplus