async: context: add implicit conversion to bus_t
Many existing sdbusplus library calls expect a `bus_t`. Add an
implicit conversion to `bus_t&` so that a `context_t&` can be passed
into any function that formerly accepted a `bus_t&`.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I791bf88d86ba5761a4d2fa9bf811b6e794b097af
diff --git a/include/sdbusplus/async/callback.hpp b/include/sdbusplus/async/callback.hpp
index 61efab8..9f738cf 100644
--- a/include/sdbusplus/async/callback.hpp
+++ b/include/sdbusplus/async/callback.hpp
@@ -35,7 +35,7 @@
* For example, `sd_bus_call_async` could be turned into a Sender with a
* call to this and a small lambda such as:
* ```
- * callback([bus = get_busp(ctx.get_bus()),
+ * callback([bus = get_busp(ctx),
* msg = std::move(msg)](auto cb, auto data) {
* return sd_bus_call_async(bus, nullptr, msg.get(), cb, data, 0);
* })
diff --git a/include/sdbusplus/async/context.hpp b/include/sdbusplus/async/context.hpp
index 40356d5..828f42a 100644
--- a/include/sdbusplus/async/context.hpp
+++ b/include/sdbusplus/async/context.hpp
@@ -71,6 +71,10 @@
{
return bus;
}
+ operator bus_t&() noexcept
+ {
+ return bus;
+ }
bool request_stop() noexcept
{
diff --git a/include/sdbusplus/async/proxy.hpp b/include/sdbusplus/async/proxy.hpp
index 5934a7e..4e00005 100644
--- a/include/sdbusplus/async/proxy.hpp
+++ b/include/sdbusplus/async/proxy.hpp
@@ -134,7 +134,7 @@
// Use 'callback' to perform the operation and "then" "unpack" the
// contents.
return callback(
- [bus = get_busp(ctx.get_bus()),
+ [bus = get_busp(ctx),
msg = std::move(msg)](auto cb, auto data) mutable {
return sd_bus_call_async(bus, nullptr, msg.get(), cb, data, 0);
}) | execution::then([](message_t&& m) { return m.unpack<Rs...>(); });
diff --git a/src/async/context.cpp b/src/async/context.cpp
index 5bb58ae..b324c6c 100644
--- a/src/async/context.cpp
+++ b/src/async/context.cpp
@@ -281,7 +281,7 @@
// Get the bus' timeout.
uint64_t to_usec = 0;
- sd_bus_get_timeout(get_busp(ctx.get_bus()), &to_usec);
+ sd_bus_get_timeout(get_busp(ctx), &to_usec);
if (to_usec == UINT64_MAX)
{
diff --git a/src/async/match.cpp b/src/async/match.cpp
index ed5237b..7dceba4 100644
--- a/src/async/match.cpp
+++ b/src/async/match.cpp
@@ -13,8 +13,8 @@
};
sd_bus_slot* s;
- auto r = sd_bus_add_match(get_busp(ctx.get_bus()), &s, pattern.data(),
- match_cb, this);
+ auto r = sd_bus_add_match(get_busp(ctx), &s, pattern.data(), match_cb,
+ this);
if (r < 0)
{
throw exception::SdBusError(-r, "sd_bus_add_match (async::match)");