Add custom event support to loop trait
This adds bindings for pw_loop_add_event
and pw_loop_signal_event
so we can create custom events and hook them into the loop.
This would be the start of enabling inter-thread communication, for sendings events to a thread currently running the mainloop.
This MR is marked as Draft, because I have a few questions, and because it might be unsound right now.
-
Why doesResolved.fn add_signal_local
callassert_main_thread()
, and why is it only local? I'm not an expert about thread safety in pipewire, so do we have to take similar caution in the two new methods? -
BothDone.add_signal_local
andadd_event
return aSource
, andsignal_event
takes a source to signal the event associated with that source.
It might be unsound to let users pass a source fromadd_signal_local
tosignal_event
, but I'm not sure.
Should we just create aLoopEvent
newtype for event sources?
Edit:
-
We also need to be careful about users creating multiple loops, and sending the event to the wrong one. If we make aDone.LoopEvent
newtype, we should probably add asignal
method to that, which signals the loop stored in the source, instead of having thesignal_event
trait method. This would also be more ergonomic. Thoughts?