use super::*;
pub type WifiSetup = WifiSetupGeneric<32, 32>;
pub struct WifiSetupGeneric<const C: usize = 32, const B: usize = 32> {
wifi: WifiAp,
request_client: RequestClient,
#[allow(unused)]
broadcast_receiver: BroadcastReceiver,
}
impl<const C: usize, const B: usize> WifiSetupGeneric<C, B> {
pub fn new() -> Result<Self> {
let (self_sender, request_receiver) = mpsc::channel(C);
let request_client = RequestClient::new(self_sender.clone());
let (broadcast_sender, broadcast_receiver) = broadcast::channel(B);
Ok(Self {
wifi: WifiAp {
socket_path: PATH_DEFAULT_SERVER.into(),
attach_options: vec![],
request_receiver,
broadcast_sender,
self_sender,
},
request_client,
broadcast_receiver,
})
}
pub fn set_socket_path<S: Into<std::path::PathBuf>>(&mut self, path: S) {
self.wifi.socket_path = path.into();
}
pub fn add_attach_options(&mut self, options: &[&str]) {
for o in options {
self.wifi.attach_options.push(o.to_string());
}
}
pub fn get_broadcast_receiver(&self) -> BroadcastReceiver {
self.wifi.broadcast_sender.subscribe()
}
pub fn get_request_client(&self) -> RequestClient {
self.request_client.clone()
}
pub fn complete(self) -> WifiAp {
self.wifi
}
}