wifi_ctrl/ap/
setup.rs

1use super::*;
2
3/// A convenient default type for setting up the WiFiAp process.
4pub type WifiSetup = WifiSetupGeneric<32, 32>;
5
6/// The generic WifiSetup struct which has generic constant parameters for adjusting queue size.
7/// WiFiSetup type is provided for convenience.
8pub struct WifiSetupGeneric<const C: usize = 32, const B: usize = 32> {
9    /// Struct for handling runtime process
10    wifi: WifiAp,
11    /// Client for making requests
12    request_client: RequestClient,
13    #[allow(unused)]
14    /// Client for receiving alerts
15    broadcast_receiver: BroadcastReceiver,
16}
17
18impl<const C: usize, const B: usize> WifiSetupGeneric<C, B> {
19    pub fn new() -> Result<Self> {
20        // setup the channel for client requests
21        let (self_sender, request_receiver) = mpsc::channel(C);
22        let request_client = RequestClient::new(self_sender.clone());
23        // setup the channel for broadcasts
24        let (broadcast_sender, broadcast_receiver) = broadcast::channel(B);
25
26        Ok(Self {
27            wifi: WifiAp {
28                socket_path: PATH_DEFAULT_SERVER.into(),
29                attach_options: vec![],
30                request_receiver,
31                broadcast_sender,
32                self_sender,
33            },
34            request_client,
35            broadcast_receiver,
36        })
37    }
38
39    pub fn set_socket_path<S: Into<std::path::PathBuf>>(&mut self, path: S) {
40        self.wifi.socket_path = path.into();
41    }
42
43    pub fn add_attach_options(&mut self, options: &[&str]) {
44        for o in options {
45            self.wifi.attach_options.push(o.to_string());
46        }
47    }
48
49    pub fn get_broadcast_receiver(&self) -> BroadcastReceiver {
50        self.wifi.broadcast_sender.subscribe()
51    }
52    pub fn get_request_client(&self) -> RequestClient {
53        self.request_client.clone()
54    }
55
56    pub fn complete(self) -> WifiAp {
57        self.wifi
58    }
59}