chore: cargo fmt & geoclue docs

This commit is contained in:
Ashley Wulber 2024-02-19 11:28:20 -05:00 committed by Ashley Wulber
parent c83767c7e5
commit 8b9767f6ce
7 changed files with 199 additions and 191 deletions

View file

@ -53,6 +53,9 @@ trait Manager {
#[dbus_proxy(object = "Client")]
fn get_client(&self);
/// Use this method to explicitly destroy a client, created using GetClient() or CreateClient().
///
/// Long-running applications, should either use this to delete associated client(s) when not needed, or disconnect from the D-Bus connection used for communicating with Geoclue (which is implicit on client process termination).
#[dbus_proxy(object = "Client")]
fn delete_client<'a>(&self, client: ObjectPath<'a>);
@ -121,12 +124,17 @@ trait Client {
interface = "org.freedesktop.GeoClue2.Location"
)]
trait Location {
/// The latitude of the location, in degrees.
#[dbus_proxy(property)]
fn latitude(&self) -> Result<f64>;
/// The longitude of the location, in degrees.
#[dbus_proxy(property)]
fn longitude(&self) -> Result<f64>;
/// The accuracy of the location fix, in meters.
#[dbus_proxy(property)]
fn accuracy(&self) -> Result<f64>;
/// The altitude of the location fix, in meters.
/// When unknown, its set to minimum f64 value, -1.7976931348623157e+308.
#[dbus_proxy(property)]
fn altitude(&self) -> Result<f64>;
/// Speed in meters per second.

View file

@ -9,48 +9,48 @@ const CHOICES: &[&str] = &["no", "yes"];
#[tokio::main]
pub async fn main() -> zbus::Result<()> {
let connection = zbus::Connection::system().await?;
let proxy = timedate_zbus::TimeDateProxy::new(&connection).await?;
let connection = zbus::Connection::system().await?;
let proxy = timedate_zbus::TimeDateProxy::new(&connection).await?;
let ntp_service = if proxy.ntp().await? {
"active"
} else {
"inactive"
};
let ntp_service = if proxy.ntp().await? {
"active"
} else {
"inactive"
};
let rtc_in_local = proxy.local_rtc().await?;
let rtc_time_usecs = proxy.rtctime_usec().await?;
let time_usecs = proxy.time_usec().await?;
let timezone = proxy.timezone().await?;
let rtc_in_local = proxy.local_rtc().await?;
let rtc_time_usecs = proxy.rtctime_usec().await?;
let time_usecs = proxy.time_usec().await?;
let timezone = proxy.timezone().await?;
let tz: chrono_tz::Tz = timezone.parse().unwrap();
let tz: chrono_tz::Tz = timezone.parse().unwrap();
let datetime = tz.timestamp_millis_opt((time_usecs / 1000) as i64).unwrap();
let datetime = tz.timestamp_millis_opt((time_usecs / 1000) as i64).unwrap();
let rtc_millis = (rtc_time_usecs / 1000) as i64;
let rtc_time = (if rtc_in_local {
tz.timestamp_millis_opt(rtc_millis).unwrap()
} else {
chrono_tz::UTC.timestamp_millis_opt(rtc_millis).unwrap()
})
.format(RTC_FORMAT);
let rtc_millis = (rtc_time_usecs / 1000) as i64;
let rtc_time = (if rtc_in_local {
tz.timestamp_millis_opt(rtc_millis).unwrap()
} else {
chrono_tz::UTC.timestamp_millis_opt(rtc_millis).unwrap()
})
.format(RTC_FORMAT);
let local = datetime.format(TZ_FORMAT);
let universal = datetime.with_timezone(&chrono_tz::UTC).format(TZ_FORMAT);
let tz_string = datetime.format("%Z, %z");
let local = datetime.format(TZ_FORMAT);
let universal = datetime.with_timezone(&chrono_tz::UTC).format(TZ_FORMAT);
let tz_string = datetime.format("%Z, %z");
let rtc_in_local = CHOICES[usize::from(rtc_in_local)];
let synchronized = CHOICES[usize::from(proxy.ntp_synchronized().await.unwrap_or_default())];
let rtc_in_local = CHOICES[usize::from(rtc_in_local)];
let synchronized = CHOICES[usize::from(proxy.ntp_synchronized().await.unwrap_or_default())];
println!(
" Local time: {local}
println!(
" Local time: {local}
Universal time: {universal}
RTC time: {rtc_time}
Time zone: {timezone} ({tz_string})
System clock synchronized: {synchronized}
NTP Service: {ntp_service}
RTC in local TZ: {rtc_in_local}"
);
);
Ok(())
Ok(())
}

View file

@ -18,58 +18,58 @@
use zbus::dbus_proxy;
#[dbus_proxy(
interface = "org.freedesktop.timedate1",
default_service = "org.freedesktop.timedate1",
default_path = "/org/freedesktop/timedate1"
interface = "org.freedesktop.timedate1",
default_service = "org.freedesktop.timedate1",
default_path = "/org/freedesktop/timedate1"
)]
trait TimeDate {
/// A list of time zones known on the local system as an array of names.
fn list_timezones(&self) -> zbus::Result<Vec<String>>;
/// A list of time zones known on the local system as an array of names.
fn list_timezones(&self) -> zbus::Result<Vec<String>>;
/// Control whether the RTC is in local time zone or UTC.
#[dbus_proxy(name = "SetLocalRTC")]
fn set_local_rtc(
&self,
local_rtc: bool,
fix_system: bool,
interactive: bool,
) -> zbus::Result<()>;
/// Control whether the RTC is in local time zone or UTC.
#[dbus_proxy(name = "SetLocalRTC")]
fn set_local_rtc(
&self,
local_rtc: bool,
fix_system: bool,
interactive: bool,
) -> zbus::Result<()>;
/// Control whether the system clock is synchronized with the network using `systemd-timesyncd`.
#[dbus_proxy(name = "SetNTP")]
fn set_ntp(&self, use_ntp: bool, interactive: bool) -> zbus::Result<()>;
/// Control whether the system clock is synchronized with the network using `systemd-timesyncd`.
#[dbus_proxy(name = "SetNTP")]
fn set_ntp(&self, use_ntp: bool, interactive: bool) -> zbus::Result<()>;
/// Change the system clock.
fn set_time(&self, usec_utc: i64, relative: bool, interactive: bool) -> zbus::Result<()>;
/// Change the system clock.
fn set_time(&self, usec_utc: i64, relative: bool, interactive: bool) -> zbus::Result<()>;
/// Set the system time zone.
fn set_timezone(&self, timezone: &str, interactive: bool) -> zbus::Result<()>;
/// Set the system time zone.
fn set_timezone(&self, timezone: &str, interactive: bool) -> zbus::Result<()>;
/// Shows whether a service to perform time synchronization over network is available.
#[dbus_proxy(property, name = "CanNTP")]
fn can_ntp(&self) -> zbus::Result<bool>;
/// Shows whether a service to perform time synchronization over network is available.
#[dbus_proxy(property, name = "CanNTP")]
fn can_ntp(&self) -> zbus::Result<bool>;
/// Shows whether the RTC is configured to use UTC or the local time zone.
#[dbus_proxy(property, name = "LocalRTC")]
fn local_rtc(&self) -> zbus::Result<bool>;
/// Shows whether the RTC is configured to use UTC or the local time zone.
#[dbus_proxy(property, name = "LocalRTC")]
fn local_rtc(&self) -> zbus::Result<bool>;
/// Shows whether the NTP service is enabled.
#[dbus_proxy(property, name = "NTP")]
fn ntp(&self) -> zbus::Result<bool>;
/// Shows whether the NTP service is enabled.
#[dbus_proxy(property, name = "NTP")]
fn ntp(&self) -> zbus::Result<bool>;
/// Shows whether the kernel reports the time as synchronized.
#[dbus_proxy(property, name = "NTPSynchronized")]
fn ntp_synchronized(&self) -> zbus::Result<bool>;
/// Shows whether the kernel reports the time as synchronized.
#[dbus_proxy(property, name = "NTPSynchronized")]
fn ntp_synchronized(&self) -> zbus::Result<bool>;
/// Shows the current time in RTC.
#[dbus_proxy(property, name = "RTCTimeUSec")]
fn rtctime_usec(&self) -> zbus::Result<u64>;
/// Shows the current time in RTC.
#[dbus_proxy(property, name = "RTCTimeUSec")]
fn rtctime_usec(&self) -> zbus::Result<u64>;
/// Shows the current time.
#[dbus_proxy(property, name = "TimeUSec")]
fn time_usec(&self) -> zbus::Result<u64>;
/// Shows the current time.
#[dbus_proxy(property, name = "TimeUSec")]
fn time_usec(&self) -> zbus::Result<u64>;
/// Shows the currently-configured time zone.
#[dbus_proxy(property)]
fn timezone(&self) -> zbus::Result<String>;
/// Shows the currently-configured time zone.
#[dbus_proxy(property)]
fn timezone(&self) -> zbus::Result<String>;
}

View file

@ -6,21 +6,21 @@ extern crate upower_dbus;
use upower_dbus::UPowerProxy;
fn main() -> zbus::Result<()> {
futures::executor::block_on(async move {
let connection = zbus::Connection::system().await?;
futures::executor::block_on(async move {
let connection = zbus::Connection::system().await?;
let upower = UPowerProxy::new(&connection).await?;
let upower = UPowerProxy::new(&connection).await?;
let device = upower.get_display_device().await?;
let device = upower.get_display_device().await?;
println!("BatteryLevel: {:?}", device.battery_level().await);
println!("IconName: {:?}", device.icon_name().await);
println!("IsPresent: {:?}", device.is_present().await);
println!("Online: {:?}", device.online().await);
println!("Percentage: {:?}", device.percentage().await);
println!("State: {:?}", device.state().await);
println!("Type: {:?}", device.type_().await);
println!("BatteryLevel: {:?}", device.battery_level().await);
println!("IconName: {:?}", device.icon_name().await);
println!("IsPresent: {:?}", device.is_present().await);
println!("Online: {:?}", device.online().await);
println!("Percentage: {:?}", device.percentage().await);
println!("State: {:?}", device.state().await);
println!("Type: {:?}", device.type_().await);
Ok(())
})
Ok(())
})
}

View file

@ -7,19 +7,19 @@ use futures::stream::StreamExt;
use upower_dbus::UPowerProxy;
fn main() -> zbus::Result<()> {
futures::executor::block_on(async move {
let connection = zbus::Connection::system().await?;
futures::executor::block_on(async move {
let connection = zbus::Connection::system().await?;
let upower = UPowerProxy::new(&connection).await?;
let upower = UPowerProxy::new(&connection).await?;
println!("On Battery: {:?}", upower.on_battery().await);
println!("On Battery: {:?}", upower.on_battery().await);
let mut stream = upower.receive_on_battery_changed().await;
let mut stream = upower.receive_on_battery_changed().await;
while let Some(event) = stream.next().await {
eprintln!("{:?}", event.get().await);
}
while let Some(event) = stream.next().await {
eprintln!("{:?}", event.get().await);
}
Ok(())
})
Ok(())
})
}

View file

@ -8,115 +8,115 @@ use zbus::zvariant::OwnedValue;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Deserialize_repr, Serialize_repr, OwnedValue)]
#[repr(u32)]
pub enum BatteryState {
Unknown = 0,
Charging = 1,
Discharging = 2,
Empty = 3,
FullyCharged = 4,
PendingCharge = 5,
PendingDischarge = 6,
Unknown = 0,
Charging = 1,
Discharging = 2,
Empty = 3,
FullyCharged = 4,
PendingCharge = 5,
PendingDischarge = 6,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Deserialize_repr, Serialize_repr, OwnedValue)]
#[repr(u32)]
pub enum BatteryType {
Unknown = 0,
LinePower = 1,
Battery = 2,
Ups = 3,
Monitor = 4,
Mouse = 5,
Keyboard = 6,
Pda = 7,
Phone = 8,
Unknown = 0,
LinePower = 1,
Battery = 2,
Ups = 3,
Monitor = 4,
Mouse = 5,
Keyboard = 6,
Pda = 7,
Phone = 8,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Deserialize_repr, Serialize_repr, OwnedValue)]
#[repr(u32)]
pub enum BatteryLevel {
Unknown = 0,
None = 1,
Low = 3,
Critical = 4,
Normal = 6,
High = 7,
Full = 8,
Unknown = 0,
None = 1,
Low = 3,
Critical = 4,
Normal = 6,
High = 7,
Full = 8,
}
#[dbus_proxy(
interface = "org.freedesktop.UPower.Device",
default_service = "org.freedesktop.UPower",
assume_defaults = false
interface = "org.freedesktop.UPower.Device",
default_service = "org.freedesktop.UPower",
assume_defaults = false
)]
trait Device {
#[dbus_proxy(property)]
fn battery_level(&self) -> zbus::Result<BatteryLevel>;
#[dbus_proxy(property)]
fn battery_level(&self) -> zbus::Result<BatteryLevel>;
#[dbus_proxy(property)]
fn capacity(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn capacity(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn energy(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn energy(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn energy_empty(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn energy_empty(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn energy_full(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn energy_full(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn energy_full_design(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn energy_full_design(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn has_history(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn has_history(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn has_statistics(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn has_statistics(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn icon_name(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn icon_name(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn is_present(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn is_present(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn is_rechargeable(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn is_rechargeable(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn luminosity(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn luminosity(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn model(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn model(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn native_path(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn native_path(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn online(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn online(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn percentage(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn percentage(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn power_supply(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn power_supply(&self) -> zbus::Result<bool>;
fn refresh(&self) -> zbus::Result<()>;
fn refresh(&self) -> zbus::Result<()>;
#[dbus_proxy(property)]
fn serial(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn serial(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn state(&self) -> zbus::Result<BatteryState>;
#[dbus_proxy(property)]
fn state(&self) -> zbus::Result<BatteryState>;
#[dbus_proxy(property)]
fn temperature(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn temperature(&self) -> zbus::Result<f64>;
#[dbus_proxy(property, name = "Type")]
fn type_(&self) -> zbus::Result<BatteryType>;
#[dbus_proxy(property, name = "Type")]
fn type_(&self) -> zbus::Result<BatteryType>;
#[dbus_proxy(property)]
fn vendor(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn vendor(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn voltage(&self) -> zbus::Result<f64>;
#[dbus_proxy(property)]
fn voltage(&self) -> zbus::Result<f64>;
}

View file

@ -7,37 +7,37 @@ use crate::device::{DeviceProxy, DeviceProxyBlocking};
#[dbus_proxy(interface = "org.freedesktop.UPower", assume_defaults = true)]
trait UPower {
/// EnumerateDevices method
fn enumerate_devices(&self) -> zbus::Result<Vec<zbus::zvariant::OwnedObjectPath>>;
/// EnumerateDevices method
fn enumerate_devices(&self) -> zbus::Result<Vec<zbus::zvariant::OwnedObjectPath>>;
/// GetCriticalAction method
fn get_critical_action(&self) -> zbus::Result<String>;
/// GetCriticalAction method
fn get_critical_action(&self) -> zbus::Result<String>;
/// GetDisplayDevice method
#[dbus_proxy(object = "Device")]
fn get_display_device(&self);
/// GetDisplayDevice method
#[dbus_proxy(object = "Device")]
fn get_display_device(&self);
/// DeviceAdded signal
#[dbus_proxy(signal)]
fn device_added(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
/// DeviceAdded signal
#[dbus_proxy(signal)]
fn device_added(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
/// DeviceRemoved signal
#[dbus_proxy(signal)]
fn device_removed(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
/// DeviceRemoved signal
#[dbus_proxy(signal)]
fn device_removed(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
/// DaemonVersion property
#[dbus_proxy(property)]
fn daemon_version(&self) -> zbus::Result<String>;
/// DaemonVersion property
#[dbus_proxy(property)]
fn daemon_version(&self) -> zbus::Result<String>;
/// LidIsClosed property
#[dbus_proxy(property)]
fn lid_is_closed(&self) -> zbus::Result<bool>;
/// LidIsClosed property
#[dbus_proxy(property)]
fn lid_is_closed(&self) -> zbus::Result<bool>;
/// LidIsPresent property
#[dbus_proxy(property)]
fn lid_is_present(&self) -> zbus::Result<bool>;
/// LidIsPresent property
#[dbus_proxy(property)]
fn lid_is_present(&self) -> zbus::Result<bool>;
/// OnBattery property
#[dbus_proxy(property)]
fn on_battery(&self) -> zbus::Result<bool>;
/// OnBattery property
#[dbus_proxy(property)]
fn on_battery(&self) -> zbus::Result<bool>;
}