message: shorten message type
Create an alias `sdbusplus::message_t` to `sdbusplus::message::message`
to reduce duplication.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ib400b12fe4a412c0c0c3d26a88f3fae46445cfa8
diff --git a/example/asio-example.cpp b/example/asio-example.cpp
index 317deb5..0b23e50 100644
--- a/example/asio-example.cpp
+++ b/example/asio-example.cpp
@@ -40,7 +40,7 @@
return testCount;
}
-int methodWithMessage(sdbusplus::message::message& /*m*/, int test)
+int methodWithMessage(sdbusplus::message_t& /*m*/, int test)
{
std::cout << "methodWithMessage(m, " << test << ") -> " << (test + 1)
<< "\n";
@@ -107,7 +107,7 @@
std::vector<uint8_t> commandData = {4, 3, 2, 1};
method.append(netFn, lun, cmd, commandData, options);
boost::system::error_code ec;
- sdbusplus::message::message reply = conn->async_send(method, yield[ec]);
+ sdbusplus::message_t reply = conn->async_send(method, yield[ec]);
std::tuple<uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>
tupleOut;
try
@@ -271,7 +271,7 @@
using GetSubTreeType = std::vector<std::pair<
std::string,
std::vector<std::pair<std::string, std::vector<std::string>>>>>;
- using message = sdbusplus::message::message;
+ using message = sdbusplus::message_t;
// setup connection to dbus
boost::asio::io_context io;
diff --git a/include/sdbusplus/asio/connection.hpp b/include/sdbusplus/asio/connection.hpp
index 7787b61..7e94cdd 100644
--- a/include/sdbusplus/asio/connection.hpp
+++ b/include/sdbusplus/asio/connection.hpp
@@ -86,16 +86,15 @@
template <typename MessageHandler>
inline BOOST_ASIO_INITFN_RESULT_TYPE(MessageHandler,
void(boost::system::error_code,
- message::message&))
- async_send(message::message& m, MessageHandler&& handler,
- uint64_t timeout = 0)
+ message_t&))
+ async_send(message_t& m, MessageHandler&& handler, uint64_t timeout = 0)
{
boost::asio::async_completion<
- MessageHandler, void(boost::system::error_code, message::message)>
+ MessageHandler, void(boost::system::error_code, message_t)>
init(handler);
detail::async_send_handler<typename boost::asio::async_result<
MessageHandler, void(boost::system::error_code,
- message::message)>::completion_handler_type>(
+ message_t)>::completion_handler_type>(
std::move(init.completion_handler))(get(), m, timeout);
return init.result.get();
}
@@ -107,7 +106,7 @@
* continuation for the async dbus method call. The
* arguments to parse on the return are deduced from
* the handler's signature and then passed in along
- * with an error code and optional message::message
+ * with an error code and optional message_t
* @param[in] service - The service to call.
* @param[in] objpath - The object's path for the call.
* @param[in] interf - The object's interface to call.
@@ -136,7 +135,7 @@
{
return std::is_same_v<
std::tuple_element_t<1, FunctionTupleType>,
- sdbusplus::message::message>;
+ sdbusplus::message_t>;
}
return false;
}();
@@ -144,7 +143,7 @@
FunctionTupleType>;
auto applyHandler = [handler = std::forward<MessageHandler>(handler)](
boost::system::error_code ec,
- message::message& r) mutable {
+ message_t& r) mutable {
UnpackType responseData;
if (!ec)
{
@@ -175,7 +174,7 @@
std::apply(handler, response);
}
};
- message::message m;
+ message_t m;
boost::system::error_code ec;
try
{
@@ -201,7 +200,7 @@
* continuation for the async dbus method call. The
* arguments to parse on the return are deduced from
* the handler's signature and then passed in along
- * with an error code and optional message::message
+ * with an error code and optional message_t
* @param[in] service - The service to call.
* @param[in] objpath - The object's path for the call.
* @param[in] interf - The object's interface to call.
@@ -244,7 +243,7 @@
const std::string& interf, const std::string& method,
const InputArgs&... a)
{
- message::message m;
+ message_t m;
try
{
m = new_method_call(service.c_str(), objpath.c_str(),
@@ -256,7 +255,7 @@
ec = boost::system::errc::make_error_code(
static_cast<boost::system::errc::errc_t>(e.get_errno()));
}
- message::message r;
+ message_t r;
if (!ec)
{
r = async_send(m, yield[ec]);
diff --git a/include/sdbusplus/asio/detail/async_send_handler.hpp b/include/sdbusplus/asio/detail/async_send_handler.hpp
index d02075b..13d23e4 100644
--- a/include/sdbusplus/asio/detail/async_send_handler.hpp
+++ b/include/sdbusplus/asio/detail/async_send_handler.hpp
@@ -35,7 +35,7 @@
{}
async_send_handler(Handler& handler) : handler_(handler)
{}
- void operator()(sd_bus* conn, message::message& mesg, uint64_t timeout)
+ void operator()(sd_bus* conn, message_t& mesg, uint64_t timeout)
{
async_send_handler* context = new async_send_handler(std::move(*this));
int ec = sd_bus_call_async(conn, NULL, mesg.get(), &callback, context,
@@ -58,7 +58,7 @@
}
std::unique_ptr<async_send_handler> context(
static_cast<async_send_handler*>(userdata));
- message::message message(mesg);
+ message_t message(mesg);
auto ec = make_error_code(
static_cast<boost::system::errc::errc_t>(message.get_errno()));
context->handler_(ec, message);
diff --git a/include/sdbusplus/asio/object_server.hpp b/include/sdbusplus/asio/object_server.hpp
index 43c0795..6bd90e0 100644
--- a/include/sdbusplus/asio/object_server.hpp
+++ b/include/sdbusplus/asio/object_server.hpp
@@ -33,7 +33,7 @@
{
public:
virtual ~callback() = default;
- virtual int call(message::message& m) = 0;
+ virtual int call(message_t& m) = 0;
};
enum class SetPropertyReturnValue : size_t
@@ -47,7 +47,7 @@
{
public:
virtual ~callback_set() = default;
- virtual SetPropertyReturnValue call(message::message& m) = 0;
+ virtual SetPropertyReturnValue call(message_t& m) = 0;
virtual SetPropertyReturnValue set(const boost::any& value) = 0;
};
@@ -61,13 +61,13 @@
inline const bool FirstArgIsMessage_v =
std::is_same_v<utility::get_first_arg_t<utility::decay_tuple_t<
boost::callable_traits::args_t<T>>>,
- message::message>;
+ message_t>;
template <typename T>
inline const bool SecondArgIsMessage_v = std::is_same_v<
utility::get_first_arg_t<utility::strip_first_arg_t<
utility::decay_tuple_t<boost::callable_traits::args_t<T>>>>,
- message::message>;
+ message_t>;
template <typename T>
static constexpr bool callbackYields = FirstArgIsYield_v<T>;
template <typename T>
@@ -78,7 +78,7 @@
namespace details
{
// small helper class to count the number of non-dbus arguments
-// to a registered dbus function (like message::message or yield_context)
+// to a registered dbus function (like message_t or yield_context)
// so the registered signature can omit them
template <typename FirstArg, typename... Rest>
struct NonDbusArgsCount;
@@ -96,7 +96,7 @@
{
constexpr static std::size_t size()
{
- if constexpr (std::is_same_v<FirstArg, message::message> ||
+ if constexpr (std::is_same_v<FirstArg, message_t> ||
std::is_same_v<FirstArg, boost::asio::yield_context>)
{
return 1 + NonDbusArgsCount<std::tuple<OtherArgs...>>::size();
@@ -116,7 +116,7 @@
public:
callback_method_instance(CallbackType&& func) : func_(std::move(func))
{}
- int call(message::message& m) override
+ int call(message_t& m) override
{
return expandCall(m);
}
@@ -128,20 +128,20 @@
CallbackType func_;
template <typename T>
std::enable_if_t<!std::is_void_v<T>, void>
- callFunction(message::message& m, InputTupleType& inputArgs)
+ callFunction(message_t& m, InputTupleType& inputArgs)
{
ResultType r = std::apply(func_, inputArgs);
m.append(r);
}
template <typename T>
std::enable_if_t<std::is_void_v<T>, void>
- callFunction(message::message&, InputTupleType& inputArgs)
+ callFunction(message_t&, InputTupleType& inputArgs)
{
std::apply(func_, inputArgs);
}
#ifdef __cpp_if_constexpr
// optional message-first-argument callback
- int expandCall(message::message& m)
+ int expandCall(message_t& m)
{
using DbusTupleType = utility::strip_first_n_args_t<
details::NonDbusArgsCount<InputTupleType>::size(), InputTupleType>;
@@ -168,7 +168,7 @@
};
#else
// normal dbus-types-only callback
- int expandCall(message::message& m)
+ int expandCall(message_t& m)
{
InputTupleType inputArgs;
if (!utility::read_into_tuple(inputArgs, m))
@@ -194,15 +194,15 @@
io_(io),
func_(std::move(func))
{}
- int call(message::message& m) override
+ int call(message_t& m) override
{
// make a copy of m to move into the coroutine
- message::message b{m};
+ 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::message mcpy{std::move(b)};
- std::optional<message::message> err{};
+ message_t mcpy{std::move(b)};
+ std::optional<message_t> err{};
try
{
@@ -234,19 +234,19 @@
CallbackType func_;
template <typename T>
std::enable_if_t<!std::is_void_v<T>, void>
- callFunction(message::message& m, InputTupleType& inputArgs)
+ callFunction(message_t& m, InputTupleType& inputArgs)
{
ResultType r = std::apply(func_, inputArgs);
m.append(r);
}
template <typename T>
std::enable_if_t<std::is_void_v<T>, void>
- callFunction(message::message& m, InputTupleType& inputArgs)
+ callFunction(message_t& m, InputTupleType& inputArgs)
{
std::apply(func_, inputArgs);
}
// co-routine body for call
- void expandCall(boost::asio::yield_context yield, message::message& m)
+ void expandCall(boost::asio::yield_context yield, message_t& m)
{
using DbusTupleType = utility::strip_first_n_args_t<
details::NonDbusArgsCount<InputTupleType>::size(), InputTupleType>;
@@ -290,7 +290,7 @@
value_(value),
func_(std::move(func))
{}
- int call(message::message& m) override
+ int call(message_t& m) override
{
auto r = func_(*value_);
m.append(r);
@@ -311,7 +311,7 @@
value_(value),
func_(std::move(func))
{}
- SetPropertyReturnValue call(message::message& m) override
+ SetPropertyReturnValue call(message_t& m) override
{
PropertyType input;
m.read(input);
@@ -626,7 +626,7 @@
{
dbus_interface* data = static_cast<dbus_interface*>(userdata);
auto func = data->callbacksGet_.find(property);
- auto mesg = message::message(reply);
+ auto mesg = message_t(reply);
if (func != data->callbacksGet_.end())
{
#ifdef __EXCEPTIONS
@@ -657,7 +657,7 @@
{
dbus_interface* data = static_cast<dbus_interface*>(userdata);
auto func = data->callbacksSet_.find(property);
- auto mesg = message::message(value);
+ auto mesg = message_t(value);
if (func != data->callbacksSet_.end())
{
#ifdef __EXCEPTIONS
@@ -695,7 +695,7 @@
sd_bus_error* error)
{
dbus_interface* data = static_cast<dbus_interface*>(userdata);
- auto mesg = message::message(m);
+ auto mesg = message_t(m);
auto func = data->callbacksMethod_.find(mesg.get_member());
if (func != data->callbacksMethod_.end())
{
@@ -732,7 +732,7 @@
{
if (!initialized_)
{
- return message::message(nullptr);
+ return message_t(nullptr);
}
return interface_->new_signal(member);
}
diff --git a/include/sdbusplus/bus.hpp b/include/sdbusplus/bus.hpp
index 80ae4c4..8c6094a 100644
--- a/include/sdbusplus/bus.hpp
+++ b/include/sdbusplus/bus.hpp
@@ -212,7 +212,7 @@
throw exception::SdBusError(-r, "sd_bus_process");
}
- return message::message(m, _intf, std::false_type());
+ return message_t(m, _intf, std::false_type());
}
/** @brief Process waiting dbus messages or signals, discarding unhandled.
@@ -260,7 +260,7 @@
throw exception::SdBusError(-r, "sd_bus_message_new_method_call");
}
- return message::message(m, _intf, std::false_type());
+ return message_t(m, _intf, std::false_type());
}
/** @brief Create a signal message.
@@ -281,7 +281,7 @@
throw exception::SdBusError(-r, "sd_bus_message_new_signal");
}
- return message::message(m, _intf, std::false_type());
+ return message_t(m, _intf, std::false_type());
}
/** @brief Perform a message call.
@@ -295,7 +295,7 @@
*
* @return The response message.
*/
- auto call(message::message& m, uint64_t timeout_us)
+ auto call(message_t& m, uint64_t timeout_us)
{
sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message* reply = nullptr;
@@ -306,10 +306,9 @@
throw exception::SdBusError(&error, "sd_bus_call");
}
- return message::message(reply, _intf, std::false_type());
+ return message_t(reply, _intf, std::false_type());
}
- auto call(message::message& m,
- std::optional<SdBusDuration> timeout = std::nullopt)
+ auto call(message_t& m, std::optional<SdBusDuration> timeout = std::nullopt)
{
return call(m, timeout ? timeout->count() : 0);
}
@@ -319,7 +318,7 @@
* @param[in] m - The method_call message.
* @param[in] timeout_us - The timeout for the method call.
*/
- void call_noreply(message::message& m, uint64_t timeout_us)
+ void call_noreply(message_t& m, uint64_t timeout_us)
{
sd_bus_error error = SD_BUS_ERROR_NULL;
int r = _intf->sd_bus_call(_bus.get(), m.get(), timeout_us, &error,
@@ -329,7 +328,7 @@
throw exception::SdBusError(&error, "sd_bus_call noreply");
}
}
- auto call_noreply(message::message& m,
+ auto call_noreply(message_t& m,
std::optional<SdBusDuration> timeout = std::nullopt)
{
return call_noreply(m, timeout ? timeout->count() : 0);
@@ -341,7 +340,7 @@
* @param[in] m - The method_call message.
* @param[in] timeout_us - The timeout for the method call.
*/
- void call_noreply_noerror(message::message& m, uint64_t timeout_us)
+ void call_noreply_noerror(message_t& m, uint64_t timeout_us)
{
try
{
@@ -353,8 +352,7 @@
}
}
auto call_noreply_noerror(
- message::message& m,
- std::optional<SdBusDuration> timeout = std::nullopt)
+ message_t& m, std::optional<SdBusDuration> timeout = std::nullopt)
{
return call_noreply_noerror(m, timeout ? timeout->count() : 0);
}
@@ -594,7 +592,7 @@
*
* @return The dbus bus.
*/
-inline auto message::message::get_bus() const
+inline auto message_t::get_bus() const
{
sd_bus* b = nullptr;
b = _intf->sd_bus_message_get_bus(_msg.get());
diff --git a/include/sdbusplus/bus/match.hpp b/include/sdbusplus/bus/match.hpp
index ae167b9..9d4b363 100644
--- a/include/sdbusplus/bus/match.hpp
+++ b/include/sdbusplus/bus/match.hpp
@@ -55,7 +55,7 @@
match(bus, _match.c_str(), handler, context)
{}
- using callback_t = std::function<void(sdbusplus::message::message&)>;
+ using callback_t = std::function<void(sdbusplus::message_t&)>;
/** @brief Register a signal match.
*
@@ -86,7 +86,7 @@
sd_bus_error* /*e*/)
{
auto c = static_cast<callback_t*>(context);
- message::message message{m};
+ message_t message{m};
(*c)(message);
diff --git a/include/sdbusplus/message.hpp b/include/sdbusplus/message.hpp
index 055a639..a3f95af 100644
--- a/include/sdbusplus/message.hpp
+++ b/include/sdbusplus/message.hpp
@@ -495,6 +495,8 @@
} // namespace message
+using message_t = message::message;
+
} // namespace sdbusplus
#ifdef __clang__
diff --git a/include/sdbusplus/sdbuspp_support/server.hpp b/include/sdbusplus/sdbuspp_support/server.hpp
index e72575b..3cf78e9 100644
--- a/include/sdbusplus/sdbuspp_support/server.hpp
+++ b/include/sdbusplus/sdbuspp_support/server.hpp
@@ -30,7 +30,7 @@
try
{
// Refcount the message.
- auto m = message::message(msg, intf);
+ auto m = message_t(msg, intf);
// Set up the transaction.
server::transaction::set_id(m);
@@ -86,7 +86,7 @@
try
{
// Refcount the message.
- auto m = message::message(msg, intf);
+ auto m = message_t(msg, intf);
// Set up the transaction.
server::transaction::set_id(m);
diff --git a/include/sdbusplus/server/transaction.hpp b/include/sdbusplus/server/transaction.hpp
index 0ec39f0..cbb08f5 100644
--- a/include/sdbusplus/server/transaction.hpp
+++ b/include/sdbusplus/server/transaction.hpp
@@ -33,12 +33,12 @@
struct Transaction
{
- Transaction(sdbusplus::bus::bus& bus, sdbusplus::message::message& msg) :
+ Transaction(sdbusplus::bus::bus& bus, sdbusplus::message_t& msg) :
bus(bus), msg(msg)
{}
sdbusplus::bus::bus& bus;
- sdbusplus::message::message& msg;
+ sdbusplus::message_t& msg;
};
} // namespace transaction
@@ -55,11 +55,11 @@
size_t operator()(sdbusplus::bus::bus& b) const;
};
-/** @ brief Overload of std::hash for sdbusplus::message::message */
+/** @ brief Overload of std::hash for sdbusplus::message_t */
template <>
-struct hash<sdbusplus::message::message>
+struct hash<sdbusplus::message_t>
{
- size_t operator()(sdbusplus::message::message& m) const;
+ size_t operator()(sdbusplus::message_t& m) const;
};
/** @ brief Overload of std::hash for Transaction */
@@ -103,7 +103,7 @@
*
* @param[in] msg - The message to create the transaction from.
*/
-void set_id(message::message& msg);
+void set_id(message_t& msg);
} // namespace transaction
} // namespace server
diff --git a/include/sdbusplus/utility/read_into_tuple.hpp b/include/sdbusplus/utility/read_into_tuple.hpp
index ae225ba..7241ff1 100644
--- a/include/sdbusplus/utility/read_into_tuple.hpp
+++ b/include/sdbusplus/utility/read_into_tuple.hpp
@@ -38,7 +38,7 @@
}
} // namespace detail
template <class Tuple>
-constexpr bool read_into_tuple(Tuple& t, message::message& m)
+constexpr bool read_into_tuple(Tuple& t, message_t& m)
{
return detail::index_apply<std::tuple_size<Tuple>{}>([&](auto... Is) {
if (m.is_method_error())
diff --git a/src/server/transaction.cpp b/src/server/transaction.cpp
index 52f9043..cdb3e56 100644
--- a/src/server/transaction.cpp
+++ b/src/server/transaction.cpp
@@ -30,7 +30,7 @@
details::id = value;
}
-void set_id(message::message& msg)
+void set_id(message_t& msg)
{
auto tbus = msg.get_bus();
auto t = Transaction(tbus, msg);
@@ -50,8 +50,7 @@
return std::hash<std::string>{}(name);
}
-size_t hash<sdbusplus::message::message>::operator()(
- sdbusplus::message::message& m) const
+size_t hash<sdbusplus::message_t>::operator()(sdbusplus::message_t& m) const
{
switch (m.get_type())
{
@@ -79,7 +78,7 @@
sdbusplus::server::transaction::Transaction const& t) const
{
auto hash1 = std::hash<sdbusplus::bus::bus>{}(t.bus);
- auto hash2 = std::hash<sdbusplus::message::message>{}(t.msg);
+ auto hash2 = std::hash<sdbusplus::message_t>{}(t.msg);
// boost::hash_combine() algorithm.
return static_cast<size_t>(
diff --git a/test/bus/match.cpp b/test/bus/match.cpp
index 3fa1647..ee76972 100644
--- a/test/bus/match.cpp
+++ b/test/bus/match.cpp
@@ -50,7 +50,7 @@
TEST_F(Match, FunctorIs_LambdaTakingMessage)
{
bool triggered = false;
- auto trigger = [&triggered](sdbusplus::message::message& /*m*/) {
+ auto trigger = [&triggered](sdbusplus::message_t& /*m*/) {
triggered = true;
};
@@ -74,7 +74,7 @@
public:
bool triggered = false;
- void callback(sdbusplus::message::message& /*m*/)
+ void callback(sdbusplus::message_t& /*m*/)
{
triggered = true;
}
diff --git a/test/message/append.cpp b/test/message/append.cpp
index 288199b..720efb8 100644
--- a/test/message/append.cpp
+++ b/test/message/append.cpp
@@ -39,7 +39,7 @@
.WillRepeatedly(Return(0));
};
- sdbusplus::message::message new_message()
+ sdbusplus::message_t new_message()
{
return sdbusplus::get_mocked_new(&mock).new_method_call(
nullptr, nullptr, nullptr, nullptr);
diff --git a/test/message/read.cpp b/test/message/read.cpp
index d1d78e7..6131c24 100644
--- a/test/message/read.cpp
+++ b/test/message/read.cpp
@@ -43,7 +43,7 @@
.WillRepeatedly(Return(0));
};
- sdbusplus::message::message new_message()
+ sdbusplus::message_t new_message()
{
return sdbusplus::get_mocked_new(&mock).new_method_call(
nullptr, nullptr, nullptr, nullptr);
diff --git a/test/server/message_variant.cpp b/test/server/message_variant.cpp
index fef1eff..0fcde8d 100644
--- a/test/server/message_variant.cpp
+++ b/test/server/message_variant.cpp
@@ -9,7 +9,7 @@
struct Object : public ::testing::Test
{
sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
- sdbusplus::message::message msg = bus.new_method_call(
+ sdbusplus::message_t msg = bus.new_method_call(
"xyz.openbmc_project.sdbusplus.test.Object",
"/xyz/openbmc_project/sdbusplus/test/object",
"xyz.openbmc_project.sdbusplus.test.Object", "Unused");