feat: geoclue bindings
This commit is contained in:
parent
5dea929b73
commit
c83767c7e5
3 changed files with 155 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ resolver = "2"
|
|||
|
||||
members = [
|
||||
"cosmic-settings-daemon",
|
||||
"geoclue2",
|
||||
"mpris2",
|
||||
"networkmanager",
|
||||
"switcheroo-control",
|
||||
|
|
@ -15,5 +16,5 @@ members = [
|
|||
serde = { version = "1.0", features = ["derive"] }
|
||||
thiserror = "1.0"
|
||||
time = { version = "0.3", features = ["parsing"] }
|
||||
zbus = { version = "3.14" }
|
||||
zvariant = { version = "3.15"}
|
||||
zbus = { version = "3.15.0" }
|
||||
zvariant = { version = "3.15.0"}
|
||||
|
|
|
|||
13
geoclue2/Cargo.toml
Normal file
13
geoclue2/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "geoclue2"
|
||||
description = "zbus-based bindings for GeoClue2 on Linux"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
serde_repr = "0.1.18"
|
||||
zbus.workspace = true
|
||||
139
geoclue2/src/lib.rs
Normal file
139
geoclue2/src/lib.rs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||
use zbus::{
|
||||
dbus_proxy,
|
||||
zvariant::{ObjectPath, OwnedValue, Type},
|
||||
Result,
|
||||
};
|
||||
|
||||
#[repr(u32)]
|
||||
#[derive(Deserialize_repr, Serialize_repr, Type, Debug, PartialEq, Eq)]
|
||||
pub enum Accuracy {
|
||||
/// Accuracy level unknown or unset
|
||||
None,
|
||||
/// Country level accuracy
|
||||
Country,
|
||||
/// City level accuracy
|
||||
City,
|
||||
/// Neighborhood level accuracy
|
||||
Neighborhood,
|
||||
/// Street level accuracy
|
||||
Street,
|
||||
/// Exact accuracy. Typically requires GPS receiver
|
||||
Exact,
|
||||
}
|
||||
|
||||
impl From<Accuracy> for u32 {
|
||||
fn from(value: Accuracy) -> Self {
|
||||
value as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<OwnedValue> for Accuracy {
|
||||
type Error = <u32 as TryFrom<OwnedValue>>::Error;
|
||||
|
||||
fn try_from(value: OwnedValue) -> std::prelude::v1::Result<Self, Self::Error> {
|
||||
Ok(match <u32>::try_from(value)? {
|
||||
1 => Accuracy::Country,
|
||||
2 => Accuracy::City,
|
||||
3 => Accuracy::Neighborhood,
|
||||
4 => Accuracy::Street,
|
||||
5 => Accuracy::Exact,
|
||||
_ => Accuracy::None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[dbus_proxy(
|
||||
default_service = "org.freedesktop.GeoClue2",
|
||||
interface = "org.freedesktop.GeoClue2.Manager",
|
||||
default_path = "/org/freedesktop/GeoClue2/Manager"
|
||||
)]
|
||||
trait Manager {
|
||||
/// Retrieves a client object which can only be used by the calling application only. On the first call from a specific D-Bus peer, this method will create the client object but subsequent calls will return the path of the existing client.
|
||||
#[dbus_proxy(object = "Client")]
|
||||
fn get_client(&self);
|
||||
|
||||
#[dbus_proxy(object = "Client")]
|
||||
fn delete_client<'a>(&self, client: ObjectPath<'a>);
|
||||
|
||||
/// InUse property
|
||||
#[dbus_proxy(property)]
|
||||
fn in_use(&self) -> Result<bool>;
|
||||
|
||||
/// AvailableAccuracyLevel property
|
||||
#[dbus_proxy(property)]
|
||||
fn available_accuracy_level(&self) -> zbus::Result<Accuracy>;
|
||||
}
|
||||
|
||||
#[dbus_proxy(
|
||||
default_service = "org.freedesktop.GeoClue2",
|
||||
interface = "org.freedesktop.GeoClue2.Client"
|
||||
)]
|
||||
trait Client {
|
||||
/// Start method
|
||||
fn start(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Stop method
|
||||
fn stop(&self) -> zbus::Result<()>;
|
||||
|
||||
/// LocationUpdated signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn location_updated(
|
||||
&self,
|
||||
old: zbus::zvariant::ObjectPath<'_>,
|
||||
new: zbus::zvariant::ObjectPath<'_>,
|
||||
) -> zbus::Result<()>;
|
||||
|
||||
/// Active property
|
||||
#[dbus_proxy(property)]
|
||||
fn active(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// DesktopId property
|
||||
#[dbus_proxy(property)]
|
||||
fn desktop_id(&self) -> zbus::Result<String>;
|
||||
#[dbus_proxy(property)]
|
||||
fn set_desktop_id(&self, value: &str) -> zbus::Result<()>;
|
||||
|
||||
/// DistanceThreshold property
|
||||
#[dbus_proxy(property)]
|
||||
fn distance_threshold(&self) -> zbus::Result<u32>;
|
||||
#[dbus_proxy(property)]
|
||||
fn set_distance_threshold(&self, value: u32) -> zbus::Result<()>;
|
||||
|
||||
/// Location property
|
||||
#[dbus_proxy(property, object = "Location")]
|
||||
fn location(&self) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||
|
||||
/// RequestedAccuracyLevel property
|
||||
#[dbus_proxy(property)]
|
||||
fn requested_accuracy_level(&self) -> zbus::Result<Accuracy>;
|
||||
#[dbus_proxy(property)]
|
||||
fn set_requested_accuracy_level(&self, value: u32) -> zbus::Result<()>;
|
||||
|
||||
/// TimeThreshold property
|
||||
#[dbus_proxy(property)]
|
||||
fn time_threshold(&self) -> zbus::Result<u32>;
|
||||
fn set_time_threshold(&self, value: u32) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
#[dbus_proxy(
|
||||
default_service = "org.freedesktop.GeoClue2",
|
||||
interface = "org.freedesktop.GeoClue2.Location"
|
||||
)]
|
||||
trait Location {
|
||||
#[dbus_proxy(property)]
|
||||
fn latitude(&self) -> Result<f64>;
|
||||
#[dbus_proxy(property)]
|
||||
fn longitude(&self) -> Result<f64>;
|
||||
#[dbus_proxy(property)]
|
||||
fn accuracy(&self) -> Result<f64>;
|
||||
#[dbus_proxy(property)]
|
||||
fn altitude(&self) -> Result<f64>;
|
||||
/// Speed in meters per second.
|
||||
/// When unknown, it's set to -1.0.
|
||||
#[dbus_proxy(property)]
|
||||
fn speed(&self) -> Result<f64>;
|
||||
/// The heading direction in degrees with respect to North direction, in clockwise order. That means North becomes 0 degree, East: 90 degrees, South: 180 degrees, West: 270 degrees and so on. When unknown, it's set to -1.0.
|
||||
#[dbus_proxy(property)]
|
||||
fn heading(&self) -> Result<f64>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue