Curve / rohrkabel

🔌 A C++ RAII Pipewire-API Wrapper
MIT License
52 stars 4 forks source link

Thread-Loop Improvements #3

Closed Curve closed 2 years ago

Curve commented 2 years ago

Rohrkabel needs some heavy improvements regarding the Thread-Loop.

The current support for the thread-loop is a bit unintuitive, namely the following things are not as clear and simple as I'd like them to be:

  • Exceptions Generally, I'd like to avoid throwing exceptions where possible. Currently we throw on pw_proxy_events::error.
    This is problematic when the thread-loop is used because the exception can then not be properly caught.

    I'd like to replace the exceptions, maybe we could make the constructor of proxy, node, etc. private and have a static method create / bind that returns a tl::expected and constructs the object - It would then return the exception when an error was thrown.
    However this would require create to wait for the object to be successfully bound/created to know if it has an error (i.e. update the core, which in turn would also complicate things a little)

(implemented in f531d2c5d9530242a55be3f238c1372aa12b434f)

Possible Solutions

1. Revert the thread-loop changes and bring back call_safe.

Pros:

Cons:

2. Make object constructors (i.e. node, port, ...) private and use static method to instantiate the object

And return shared_ptr that has custom deleter to make sure object is deleted safely.

Pros:

Cons:

3. The pipewire-rs appraoch

See https://pipewire.pages.freedesktop.org/pipewire-rs/pipewire/channel/index.html#examples

Design:

Pros:

Cons:

4. Design all inherently unsafe methods to be async

Design:

Pros:

Cons:

This issue currently serves as an outlet for my ideas regarding this issue.
I will keep updating this post with ideas that come to mind and will leave it open until I have found a solution that I'm pleased with.

💡 Help is always appreciated!

In case you're reading this issue and have any ideas or suggestions on how to tackle this problem, feel free to comment!

Current proposed solution

After some back and forth I think I will settle with solution 3