C++ co-routines are coming soon...
Hello,
I just pushed up some code I've been working on for initial community preview:
C++20 coroutine support in sdbusplus[1]. This code should be considered "experimental" for the time-being but a good preview of where I plan to take the sdbusplus bindings. I know there are complaints about the current sdbusplus support in one of three veins depending on your perspective of importance:
1. The current sdbusplus server bindings in phosphor-dbus-interfaces are synchronous.
2. There are no sdbusplus client bindings in phosphor-dbus-interfaces.
3. The code using the sdbusplus Boost/ASIO interfaces is very callback intensive (and difficult to read).
I've been wanting to leverage C++20 coroutines for quite a while in order to address these shortcomings but haven't gotten around to it due to lack of understanding on my part (and lack of time to fix this) and lack of maturity in the library support. There is a proposal for C++23 (P2300)[2] which attempts to fix the "maturity" problem and the authors of that have been using libunifex[3] as their proving ground. Using libunifex and becoming enlightened by Eric Niebler's excellent talk at CppCon'21, I've finally been able to make some good progress on this.
There will be more to come, but I wanted to give a taste of what a C++20 co-routine-based sdbusplus agent might look like. This is an example of a task that reacts to D-Bus "NameOwnerChanged" signals:
```
auto watch_events(sdbusplus::async::context_t& ctx)
-> sdbusplus::execution::task<void>
{
using namespace sdbusplus::async::match;
auto m = match(ctx, rules::nameOwnerChanged());
while (auto msg = co_await m.next())
{
std::string service, old_name, new_name;
msg.read(service, old_name, new_name);
if (!new_name.empty())
{
std::cout << new_name << " owns " << service << std::endl;
}
else
{
std::cout << service << " released" << std::endl;
}
};
co_return;
}
```I currently have match implemented and I plan to get call working very soon. Sometime between now and late January I'll probably do an educational talk on co-routines.
1. https://gerrit.openbmc-project.xyz/c/openbmc/sdbusplus/+/49117
2. https://github.com/cplusplus/papers/issues/1054
3. https://github.com/facebookexperimental/libunifex
4. https://www.youtube.com/watch?v=xLboNIf7BTg
Signature · 1 line
Patrick Williams
Thank you for your effort here!
This three are really long waiting 'must have' things. I will try to test this proposal.
Quoted 81 lines · Patrick Williams
Hello,
I just pushed up some code I've been working on for initial community preview:
C++20 coroutine support in sdbusplus[1]. This code should be considered
"experimental" for the time-being but a good preview of where I plan to take the
sdbusplus bindings. I know there are complaints about the current sdbusplus
support in one of three veins depending on your perspective of importance:1. The current sdbusplus server bindings in phosphor-dbus- interfaces are
synchronous.
2. There are no sdbusplus client bindings in phosphor-dbus- interfaces.
3. The code using the sdbusplus Boost/ASIO interfaces is very callback
intensive (and difficult to read).I've been wanting to leverage C++20 coroutines for quite a while in order to
address these shortcomings but haven't gotten around to it due to lack of
understanding on my part (and lack of time to fix this) and lack of maturity in
the library support. There is a proposal for C++23 (P2300)[2] which attempts to
fix the "maturity" problem and the authors of that have been using libunifex[3]
as their proving ground. Using libunifex and becoming enlightened by Eric
Niebler's excellent talk at CppCon'21, I've finally been able to make some good
progress on this.There will be more to come, but I wanted to give a taste of what a C++20
co-routine-based sdbusplus agent might look like. This is an example of a
task that reacts to D-Bus "NameOwnerChanged" signals:``` auto watch_events(sdbusplus::async::context_t& ctx) -> sdbusplus::execution::task<void> { using namespace sdbusplus::async::match; auto m = match(ctx, rules::nameOwnerChanged()); while (auto msg = co_await m.next()) { std::string service, old_name, new_name; msg.read(service, old_name, new_name); if (!new_name.empty()) { std::cout << new_name << " owns " << service << std::endl; } else { std::cout << service << " released" << std::endl; } }; co_return; } ```I currently have
matchimplemented and I plan to getcallworking very soon.
Sometime between now and late January I'll probably do an educational talk on
co-routines.1. https://gerrit.openbmc-project.xyz/c/openbmc/sdbusplus/+/49117
2. https://github.com/cplusplus/papers/issues/1054
3. https://github.com/facebookexperimental/libunifex
4. https://www.youtube.com/watch?v=xLboNIf7BTg
Signature · 2 lines
Best regards, Andrei Kartashev
Thanks Patrick! Really excited to see C++20 features in action.
Regards,
Tom
Quoted 93 lines · Andrei Kartashev
Thank you for your effort here!
This three are really long waiting 'must have' things. I will try to test this proposal.Quoted 76 lines · Patrick Williams
Hello,
I just pushed up some code I've been working on for initial community preview:
C++20 coroutine support in sdbusplus[1]. This code should be considered
"experimental" for the time-being but a good preview of where I plan to take the
sdbusplus bindings. I know there are complaints about the current sdbusplus
support in one of three veins depending on your perspective of importance:1. The current sdbusplus server bindings in phosphor-dbus-
interfaces are
synchronous.
2. There are no sdbusplus client bindings in phosphor-dbus-
interfaces.
3. The code using the sdbusplus Boost/ASIO interfaces is very
callback
intensive (and difficult to read).I've been wanting to leverage C++20 coroutines for quite a while in order to
address these shortcomings but haven't gotten around to it due to lack of
understanding on my part (and lack of time to fix this) and lack of maturity in
the library support. There is a proposal for C++23 (P2300)[2] which attempts to
fix the "maturity" problem and the authors of that have been using libunifex[3]
as their proving ground. Using libunifex and becoming enlightened by Eric
Niebler's excellent talk at CppCon'21, I've finally been able to make some good
progress on this.There will be more to come, but I wanted to give a taste of what a C++20
co-routine-based sdbusplus agent might look like. This is an example of a
task that reacts to D-Bus "NameOwnerChanged" signals:``` auto watch_events(sdbusplus::async::context_t& ctx) -> sdbusplus::execution::task<void> { using namespace sdbusplus::async::match; auto m = match(ctx, rules::nameOwnerChanged()); while (auto msg = co_await m.next()) { std::string service, old_name, new_name; msg.read(service, old_name, new_name); if (!new_name.empty()) { std::cout << new_name << " owns " << service << std::endl; } else { std::cout << service << " released" << std::endl; } }; co_return; } ```I currently have
matchimplemented and I plan to getcallworking very soon.
Sometime between now and late January I'll probably do an educational talk on
co-routines.Quoted 5 lines
1. https://gerrit.openbmc-project.xyz/c/openbmc/sdbusplus/+/49117
2. https://github.com/cplusplus/papers/issues/1054
3. https://github.com/facebookexperimental/libunifex
4. https://www.youtube.com/watch?v=xLboNIf7BTg--
Best regards,
Andrei Kartashev