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