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