refactor app/jack init

This commit is contained in:
🪞👃🪞 2024-07-10 13:15:53 +03:00
parent 117f4d5363
commit 23d9910399
7 changed files with 166 additions and 80 deletions

View file

@ -30,6 +30,55 @@ pub use ::_jack::{
Unowned
};
pub enum JackClient {
Inactive(Client),
Active(DynamicAsyncClient),
}
impl JackClient {
pub fn client (&self) -> &Client {
match self {
Self::Inactive(ref client) =>
client,
Self::Active(ref client) =>
client.as_client(),
}
}
pub fn transport (&self) -> Transport {
match self {
Self::Inactive(client) =>
client.transport(),
Self::Active(client) =>
client.as_client().transport(),
}
}
fn register_port <PS: PortSpec> (&self, name: &str, spec: PS) -> Usually<Port<PS>> {
Ok(match self {
Self::Inactive(client) =>
client.register_port(name, spec)?,
Self::Active(client) =>
client.as_client().register_port(name, spec)?,
})
}
pub fn activate <T: Send + Sync + 'static> (
self,
state: &Arc<RwLock<T>>,
mut process: impl FnMut(&Arc<RwLock<T>>, &Client, &ProcessScope)->Control + Send + 'static
) -> Usually<Self> {
Ok(match self {
Self::Active(_) => self,
Self::Inactive(client) => Self::Active(client.activate_async(
Notifications(Box::new(move|_|{/*TODO*/})
as Box<dyn Fn(AppEvent) + Send + Sync>),
ClosureProcessHandler::new(Box::new({
let state = state.clone();
move|c: &Client, s: &ProcessScope|process(&state, c, s)
}) as BoxedProcessHandler)
)?)
})
}
}
pub type DynamicAsyncClient =
AsyncClient<DynamicNotifications, DynamicProcessHandler>;