use std::{
future::Future,
pin::Pin,
sync::{Arc, Mutex},
};
use async_channel::Receiver;
use futures::channel::oneshot;
use mdns_proto::{QueryHandle, QuerySpec, ServiceHandle, ServiceSpec};
use crate::{
error::{RegisterError, StartQueryError},
query::QueryMailbox,
service::ServiceMailbox,
};
pub(crate) struct ServiceRegistered {
pub(crate) handle: ServiceHandle,
pub(crate) mailbox: Arc<Mutex<ServiceMailbox>>,
pub(crate) doorbell: Receiver<()>,
}
pub(crate) struct QueryStarted {
pub(crate) handle: QueryHandle,
pub(crate) mailbox: Arc<Mutex<QueryMailbox>>,
pub(crate) doorbell: Receiver<()>,
}
pub(crate) enum Command {
RegisterService {
spec: ServiceSpec,
reply: oneshot::Sender<Result<ServiceRegistered, RegisterError>>,
},
UnregisterService {
handle: ServiceHandle,
},
StartQuery {
spec: QuerySpec,
reply: oneshot::Sender<Result<QueryStarted, StartQueryError>>,
},
CancelQuery {
handle: QueryHandle,
},
SpawnLookup {
task: Pin<Box<dyn Future<Output = ()> + Send>>,
},
}