fix: active connection state
This commit is contained in:
parent
5adeb6dc11
commit
95f6d5e9ac
3 changed files with 50 additions and 29 deletions
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
active_connection::ActiveConnectionProxy,
|
||||
config::{ip4::Ipv4ConfigProxy, ip6::Ipv6ConfigProxy},
|
||||
device::DeviceProxy,
|
||||
enums::{ActivationStateFlags, State},
|
||||
enums::{ActivationStateFlags, ActiveConnectionState},
|
||||
},
|
||||
};
|
||||
use std::ops::Deref;
|
||||
|
|
@ -46,8 +46,8 @@ impl<'a> ActiveConnection<'a> {
|
|||
Ok(Ipv6Config::from(config))
|
||||
}
|
||||
|
||||
pub async fn state(&self) -> Result<State> {
|
||||
self.0.state().await.map(State::from)
|
||||
pub async fn state(&self) -> Result<ActiveConnectionState> {
|
||||
self.0.state().await.map(ActiveConnectionState::from)
|
||||
}
|
||||
|
||||
pub async fn state_flags(&self) -> Result<ActivationStateFlags> {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
use bitflags::bitflags;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum State {
|
||||
pub enum NmState {
|
||||
Asleep,
|
||||
Disconnected,
|
||||
Disconnecting,
|
||||
|
|
@ -13,23 +13,23 @@ pub enum State {
|
|||
Unknown,
|
||||
}
|
||||
|
||||
impl From<u32> for State {
|
||||
fn from(state: u32) -> State {
|
||||
impl From<u32> for NmState {
|
||||
fn from(state: u32) -> NmState {
|
||||
match state {
|
||||
10 => State::Asleep,
|
||||
20 => State::Disconnected,
|
||||
30 => State::Disconnecting,
|
||||
40 => State::Connecting,
|
||||
50 => State::ConnectedLocal,
|
||||
60 => State::ConnectedSite,
|
||||
70 => State::ConnectedGlobal,
|
||||
_ => State::Unknown,
|
||||
10 => NmState::Asleep,
|
||||
20 => NmState::Disconnected,
|
||||
30 => NmState::Disconnecting,
|
||||
40 => NmState::Connecting,
|
||||
50 => NmState::ConnectedLocal,
|
||||
60 => NmState::ConnectedSite,
|
||||
70 => NmState::ConnectedGlobal,
|
||||
_ => NmState::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ConnectivityState {
|
||||
pub enum NmConnectivityState {
|
||||
None,
|
||||
Portal,
|
||||
Loss,
|
||||
|
|
@ -37,14 +37,14 @@ pub enum ConnectivityState {
|
|||
Unknown,
|
||||
}
|
||||
|
||||
impl From<u32> for ConnectivityState {
|
||||
fn from(state: u32) -> ConnectivityState {
|
||||
impl From<u32> for NmConnectivityState {
|
||||
fn from(state: u32) -> NmConnectivityState {
|
||||
match state {
|
||||
1 => ConnectivityState::None,
|
||||
2 => ConnectivityState::Portal,
|
||||
3 => ConnectivityState::Loss,
|
||||
4 => ConnectivityState::Full,
|
||||
_ => ConnectivityState::Unknown,
|
||||
1 => NmConnectivityState::None,
|
||||
2 => NmConnectivityState::Portal,
|
||||
3 => NmConnectivityState::Loss,
|
||||
4 => NmConnectivityState::Full,
|
||||
_ => NmConnectivityState::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -113,6 +113,27 @@ impl From<u32> for DeviceState {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ActiveConnectionState {
|
||||
Unknown,
|
||||
Activating,
|
||||
Activated,
|
||||
Deactivating,
|
||||
Deactivated,
|
||||
}
|
||||
|
||||
impl From<u32> for ActiveConnectionState {
|
||||
fn from(device_state: u32) -> Self {
|
||||
match device_state {
|
||||
1 => ActiveConnectionState::Activating,
|
||||
2 => ActiveConnectionState::Activated,
|
||||
3 => ActiveConnectionState::Deactivating,
|
||||
4 => ActiveConnectionState::Deactivated,
|
||||
_ => ActiveConnectionState::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum WifiMode {
|
||||
AdHoc,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
interface::{
|
||||
active_connection::ActiveConnectionProxy,
|
||||
device::DeviceProxy,
|
||||
enums::{ConnectivityState, State},
|
||||
enums::{NmConnectivityState, NmState},
|
||||
NetworkManagerProxy,
|
||||
},
|
||||
settings::{connection::Connection, NetworkManagerSettings},
|
||||
|
|
@ -62,15 +62,15 @@ impl<'a> NetworkManager<'a> {
|
|||
Ok(out)
|
||||
}
|
||||
|
||||
pub async fn connectivity(&self) -> Result<ConnectivityState> {
|
||||
self.0.connectivity().await.map(ConnectivityState::from)
|
||||
pub async fn connectivity(&self) -> Result<NmConnectivityState> {
|
||||
self.0.connectivity().await.map(NmConnectivityState::from)
|
||||
}
|
||||
|
||||
pub async fn check_connectivity(&self) -> Result<ConnectivityState> {
|
||||
pub async fn check_connectivity(&self) -> Result<NmConnectivityState> {
|
||||
self.0
|
||||
.check_connectivity()
|
||||
.await
|
||||
.map(ConnectivityState::from)
|
||||
.map(NmConnectivityState::from)
|
||||
}
|
||||
|
||||
pub async fn deactivate_connection(&self, connection: &'a ActiveConnection<'a>) -> Result<()> {
|
||||
|
|
@ -103,8 +103,8 @@ impl<'a> NetworkManager<'a> {
|
|||
Ok(out)
|
||||
}
|
||||
|
||||
pub async fn state(&self) -> Result<State> {
|
||||
self.0.state().await.map(State::from)
|
||||
pub async fn state(&self) -> Result<NmState> {
|
||||
self.0.state().await.map(NmState::from)
|
||||
}
|
||||
|
||||
pub async fn settings(&'a self) -> Result<NetworkManagerSettings<'a>> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue