mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-14 08:01:14 +01:00
Merge pull request #47 from Ottatop/udev_fix
Reschedule ConnectForAllOutputs callbacks until stream exists
This commit is contained in:
commit
a552c3abda
2 changed files with 42 additions and 20 deletions
|
@ -895,26 +895,32 @@ impl State<UdevData> {
|
|||
// Run any connected callbacks
|
||||
{
|
||||
let clone = output.clone();
|
||||
self.loop_handle.insert_idle(move |data| {
|
||||
let stream = data
|
||||
.state
|
||||
.api_state
|
||||
.stream
|
||||
.as_ref()
|
||||
.expect("Stream doesn't exist");
|
||||
let mut stream = stream.lock().expect("Couldn't lock stream");
|
||||
for callback_id in data.state.output_callback_ids.iter() {
|
||||
crate::api::send_to_client(
|
||||
&mut stream,
|
||||
&OutgoingMsg::CallCallback {
|
||||
callback_id: *callback_id,
|
||||
args: Some(Args::ConnectForAllOutputs {
|
||||
output_name: clone.name(),
|
||||
}),
|
||||
},
|
||||
)
|
||||
.expect("Send to client failed");
|
||||
}
|
||||
self.loop_handle.insert_idle(|data| {
|
||||
crate::state::schedule(
|
||||
data,
|
||||
|dt| dt.state.api_state.stream.is_some(),
|
||||
move |dt| {
|
||||
let stream = dt
|
||||
.state
|
||||
.api_state
|
||||
.stream
|
||||
.as_ref()
|
||||
.expect("Stream doesn't exist");
|
||||
let mut stream = stream.lock().expect("Couldn't lock stream");
|
||||
for callback_id in dt.state.output_callback_ids.iter() {
|
||||
crate::api::send_to_client(
|
||||
&mut stream,
|
||||
&OutgoingMsg::CallCallback {
|
||||
callback_id: *callback_id,
|
||||
args: Some(Args::ConnectForAllOutputs {
|
||||
output_name: clone.name(),
|
||||
}),
|
||||
},
|
||||
)
|
||||
.expect("Send to client failed");
|
||||
}
|
||||
},
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
16
src/state.rs
16
src/state.rs
|
@ -738,6 +738,22 @@ pub fn schedule_on_commit<F, B: Backend>(
|
|||
on_commit(data);
|
||||
}
|
||||
|
||||
// Schedule something to be done when `condition` returns true.
|
||||
pub fn schedule<F1, F2, B: Backend>(data: &mut CalloopData<B>, condition: F1, run: F2)
|
||||
where
|
||||
F1: Fn(&mut CalloopData<B>) -> bool + 'static,
|
||||
F2: FnOnce(&mut CalloopData<B>) + 'static,
|
||||
{
|
||||
if !condition(data) {
|
||||
data.state.loop_handle.insert_idle(|data| {
|
||||
schedule(data, condition, run);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
run(data);
|
||||
}
|
||||
|
||||
impl<B: Backend> State<B> {
|
||||
pub fn init(
|
||||
backend_data: B,
|
||||
|
|
Loading…
Reference in a new issue