46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
use crate::deck::Deck;
|
|
use crate::ManagerMessage;
|
|
use std::path::PathBuf;
|
|
use tokio_actors::{BoxFuture, Context, SendHandle};
|
|
use uuid::Uuid;
|
|
use zbus::Connection;
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub(crate) struct Connector {
|
|
connection: Connection,
|
|
parent: SendHandle<ManagerMessage>,
|
|
}
|
|
|
|
impl Connector {
|
|
pub(crate) fn new(connection: Connection, parent: SendHandle<ManagerMessage>) -> Self {
|
|
println!("new connector");
|
|
Connector { connection, parent }
|
|
}
|
|
|
|
pub(crate) fn turn<'a>(
|
|
&'a mut self,
|
|
path: PathBuf,
|
|
ctx: &'a mut Context<PathBuf>,
|
|
) -> BoxFuture<'a> {
|
|
println!("Connector");
|
|
Box::pin(async move {
|
|
ctx.stop();
|
|
|
|
// TODO: Run connection logic
|
|
let deck = Deck::build(
|
|
self.connection.clone(),
|
|
// TODO: look up device name
|
|
"".to_owned(),
|
|
// TODO: look up device id
|
|
Uuid::new_v4().as_bytes().to_vec(),
|
|
path,
|
|
self.parent.clone(),
|
|
)
|
|
.await?;
|
|
self.parent.send(ManagerMessage::Connected(deck)).await?;
|
|
|
|
Ok(())
|
|
})
|
|
}
|
|
}
|