Skip to content

Commit

Permalink
sta: refactor remove network all
Browse files Browse the repository at this point in the history
  • Loading branch information
lthiery committed May 22, 2024
1 parent 4303d66 commit 2e60f26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
22 changes: 8 additions & 14 deletions src/sta/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ impl fmt::Display for SelectResult {
}
}

pub enum RemoveNetwork {
Id(usize),
All,
}

#[derive(Debug)]
pub(crate) enum Request {
Custom(String, oneshot::Sender<Result<String>>),
Expand All @@ -44,8 +49,7 @@ pub(crate) enum Request {
AddNetwork(oneshot::Sender<Result<usize>>),
SetNetwork(usize, SetNetwork, oneshot::Sender<Result>),
SaveConfig(oneshot::Sender<Result>),
RemoveNetwork(usize, oneshot::Sender<Result>),
RemoveAllNetworks(oneshot::Sender<Result>),
RemoveNetwork(RemoveNetwork, oneshot::Sender<Result>),

Check failure on line 52 in src/sta/client.rs

View workflow job for this annotation

GitHub Actions / clippy

`sta::client::RemoveNetwork` doesn't implement `std::fmt::Debug`

error[E0277]: `sta::client::RemoveNetwork` doesn't implement `std::fmt::Debug` --> src/sta/client.rs:52:19 | 43 | #[derive(Debug)] | ----- in this derive macro expansion ... 52 | RemoveNetwork(RemoveNetwork, oneshot::Sender<Result>), | ^^^^^^^^^^^^^ `sta::client::RemoveNetwork` cannot be formatted using `{:?}` | = help: the trait `std::fmt::Debug` is not implemented for `sta::client::RemoveNetwork` = note: add `#[derive(Debug)]` to `sta::client::RemoveNetwork` or manually `impl std::fmt::Debug for sta::client::RemoveNetwork` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider annotating `sta::client::RemoveNetwork` with `#[derive(Debug)]` | 38 + #[derive(Debug)] 39 | pub enum RemoveNetwork { |
SelectNetwork(usize, oneshot::Sender<Result<SelectResult>>),
Shutdown,
SelectTimeout,
Expand Down Expand Up @@ -81,9 +85,6 @@ impl ShutdownSignal for Request {
Request::RemoveNetwork(_, response) => {
let _ = response.send(Err(error::Error::StartupAborted));
}
Request::RemoveAllNetworks(response) => {
let _ = response.send(Err(error::Error::StartupAborted));
}
Request::SelectNetwork(_, response) => {
let _ = response.send(Err(error::Error::StartupAborted));
}
Expand Down Expand Up @@ -200,16 +201,9 @@ impl RequestClient {
request.await?
}

pub async fn remove_network(&self, network_id: usize) -> Result {
let (response, request) = oneshot::channel();
self.send_request(Request::RemoveNetwork(network_id, response))
.await?;
request.await?
}

pub async fn remove_all_networks(&self) -> Result {
pub async fn remove_network(&self, remove_network: RemoveNetwork) -> Result {
let (response, request) = oneshot::channel();
self.send_request(Request::RemoveAllNetworks(response))
self.send_request(Request::RemoveNetwork(remove_network, response))
.await?;
request.await?
}
Expand Down
20 changes: 8 additions & 12 deletions src/sta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,17 @@ impl WifiStation {
debug!("wpa_ctrl config saved");
let _ = response.send(Ok(()));
}
Request::RemoveNetwork(id, response) => {
let cmd = format!("REMOVE_NETWORK {id}");
Request::RemoveNetwork(remove_network, response) => {

Check warning on line 250 in src/sta/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `response`

warning: unused variable: `response` --> src/sta/mod.rs:250:52 | 250 | Request::RemoveNetwork(remove_network, response) => { | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_response` | = note: `#[warn(unused_variables)]` on by default
let str = match remove_network {
RemoveNetwork::All => "all".to_string(),
RemoveNetwork::Id(id) => id.to_string(),
};
let cmd = format!("REMOVE_NETWORK {str}");
let bytes = cmd.into_bytes();
if let Err(e) = socket_handle.command(&bytes).await {
warn!("Error while removing network {id}: {e}");
warn!("Error while removing network {str}: {e}");
}
debug!("wpa_ctrl removed network {id}");
let _ = response.send(Ok(()));
}
Request::RemoveAllNetworks(response) => {
if let Err(e) = socket_handle.command(b"REMOVE_NETWORK all").await {
warn!("Error while removing network all: {e}");
}
debug!("wpa_ctrl removed network all");
let _ = response.send(Ok(()));
debug!("wpa_ctrl removed network {str}");
}
Request::SelectNetwork(id, response_sender) => {
let response_sender = match select_request {
Expand Down

0 comments on commit 2e60f26

Please sign in to comment.