Implement AccessPoint::last_seen, using procfs to get the boot time.
This commit is contained in:
parent
8df68611fe
commit
df6070b75c
4 changed files with 23 additions and 10 deletions
|
|
@ -7,6 +7,8 @@ license = "MPL-2.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.3.2"
|
bitflags = "1.3.2"
|
||||||
derive_builder = "0.10.2"
|
derive_builder = "0.10.2"
|
||||||
|
procfs = { version = "0.12.0", default-features = false }
|
||||||
|
time = "0.3.7"
|
||||||
zbus = "2.0.1"
|
zbus = "2.0.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,23 @@
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
use crate::interface::{
|
use crate::{
|
||||||
access_point::AccessPointProxy,
|
interface::{
|
||||||
enums::{ApFlags, ApSecurityFlags},
|
access_point::AccessPointProxy,
|
||||||
|
enums::{ApFlags, ApSecurityFlags},
|
||||||
|
},
|
||||||
|
util::clock_boottime_to_time,
|
||||||
};
|
};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use time::OffsetDateTime;
|
||||||
use zbus::Result;
|
use zbus::Result;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AccessPoint<'a>(AccessPointProxy<'a>);
|
pub struct AccessPoint<'a>(AccessPointProxy<'a>);
|
||||||
|
|
||||||
impl<'a> AccessPoint<'a> {
|
impl<'a> AccessPoint<'a> {
|
||||||
/* TODO: figure out how to convert CLOCK_BOOTTIME to SystemTime, as CLOCK_BOOTTIME's starting point is arbritary and not guaranteed to match up with the UNIX Epoch
|
pub async fn last_seen(&self) -> Result<Option<OffsetDateTime>> {
|
||||||
pub async fn last_seen(&self) -> Result<Option<SystemTime>> {
|
Ok(clock_boottime_to_time(self.0.last_seen().await?))
|
||||||
let last_seen = self.0.last_seen().await?;
|
}
|
||||||
if !last_seen.is_positive() {
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
pub async fn flags(&self) -> Result<ApFlags> {
|
pub async fn flags(&self) -> Result<ApFlags> {
|
||||||
self.0.flags().await.map(ApFlags::from_bits_truncate)
|
self.0.flags().await.map(ApFlags::from_bits_truncate)
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,4 @@ pub mod device;
|
||||||
pub mod interface;
|
pub mod interface;
|
||||||
pub mod nm;
|
pub mod nm;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
|
pub(crate) mod util;
|
||||||
|
|
|
||||||
10
networkmanager/src/util.rs
Normal file
10
networkmanager/src/util.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
|
pub fn clock_boottime_to_time(time: i32) -> Option<OffsetDateTime> {
|
||||||
|
let boot_time = procfs::boot_time_secs()
|
||||||
|
.ok()
|
||||||
|
.and_then(|boot_time| i64::try_from(boot_time).ok())?;
|
||||||
|
OffsetDateTime::from_unix_timestamp(boot_time + time as i64).ok()
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue