async: context: add request_name method
One area we did a poor job on in the older sync interfaces was signals.
Signals should only be emitted when a name is requested, but we didn't
have a way to track that. Add a `request_name` method on the async
context so we can track if a name has been requested in the context (for
later use by signal enhancements).
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I0abea30e3825d41dedd44de86b8b8bca4edbaf9c
diff --git a/example/calculator-aserver.cpp b/example/calculator-aserver.cpp
index 6d41d07..9880e49 100644
--- a/example/calculator-aserver.cpp
+++ b/example/calculator-aserver.cpp
@@ -50,7 +50,7 @@
Calculator c{ctx, path};
ctx.spawn([](sdbusplus::async::context& ctx) -> sdbusplus::async::task<> {
- ctx.get_bus().request_name(Calculator::default_service);
+ ctx.request_name(Calculator::default_service);
co_return;
}(ctx));
diff --git a/include/sdbusplus/async/context.hpp b/include/sdbusplus/async/context.hpp
index 828f42a..05994c9 100644
--- a/include/sdbusplus/async/context.hpp
+++ b/include/sdbusplus/async/context.hpp
@@ -76,6 +76,12 @@
return bus;
}
+ void request_name(const char* service)
+ {
+ name_requested = true;
+ bus.request_name(service);
+ }
+
bool request_stop() noexcept
{
return initial_stop.request_stop();
@@ -92,6 +98,7 @@
bus_t bus;
event_source_t dbus_source;
event_t event_loop{};
+ bool name_requested = false;
/** The async run-loop from std::execution. */
execution::run_loop loop{};