1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
//! A [NetworkManager](https://wiki.gnome.org/Projects/NetworkManager) API library using the [D-Bus message bus system](https://www.freedesktop.org/wiki/Software/dbus/)
//!
//! ## Usage
//!
//! ```toml
//! [dependencies]
//! networkmanager = { package = "passcod-networkmanager", version = "=0.7.0-pre.1" }
//! tokio = { version = "1", features = ["full"] }
//! ```
//!
//! ## Example
//!
//! ```rust,no_run
//! # use passcod_networkmanager as networkmanager;
//! use networkmanager::{Error, NetworkManager};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Error> {
//! let nm = NetworkManager::new().await?;
//!
//! for dev in nm.get_devices().await? {
//! if let Some(wifi) = dev.to_wireless().await? {
//! println!("Bitrate: {:?}", wifi.bitrate().await?);
//! wifi.request_scan().await?;
//! for ap in wifi.get_all_access_points().await? {
//! let raw = ap.ssid().await?;
//! println!("SSID: {} {raw:02x?}", String::from_utf8_lossy(&raw));
//! }
//! }
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ## Features
//!
//! - `raw`: Enable access to the raw D-Bus proxies. This is useful if you need to access methods
//! that are not wrapped by this library, or if you need to access the D-Bus signals.
#![deny(rust_2018_idioms)]
mod errors;
mod networkmanager;
mod raw;
mod settings;
// pub mod configs;
// pub mod devices;
pub mod connection;
pub mod device;
pub mod types;
pub use crate::errors::Error;
pub use crate::networkmanager::NetworkManager;
pub use crate::settings::Settings;
#[cfg(feature = "raw")]
pub use raw;
macro_rules! zproxy_unpathed {
($facade:ty, $proxy:ty) => {
impl $facade {
#[cfg(not(feature = "raw"))]
pub(crate) async fn raw(&self) -> Result<$proxy, crate::Error> {
use zbus::ProxyDefault;
<$proxy>::builder(&self.zbus)
.destination(crate::raw::networkmanager::NetworkManagerProxy::DESTINATION)?
.build()
.await
.map_err(crate::Error::ZBus)
}
/// Get the raw D-Bus proxy.
#[cfg(feature = "raw")]
pub async fn raw(&self) -> Result<$proxy, crate::Error> {
use zbus::ProxyDefault;
<$proxy>::builder(&self.zbus)
.destination(crate::raw::networkmanager::NetworkManagerProxy::DESTINATION)?
.build()
.await
.map_err(crate::Error::ZBus)
}
}
};
}
macro_rules! zproxy_pathed {
($facade:ty, $proxy:ty) => {
impl $facade {
#[cfg(not(feature = "raw"))]
pub(crate) async fn raw(&self) -> Result<$proxy, crate::Error> {
use zbus::ProxyDefault;
<$proxy>::builder(&self.zbus)
.path(&self.path)?
.destination(crate::raw::networkmanager::NetworkManagerProxy::DESTINATION)?
.build()
.await
.map_err(crate::Error::ZBus)
}
/// Get the raw D-Bus proxy.
#[cfg(feature = "raw")]
pub async fn raw(&self) -> Result<$proxy, crate::Error> {
use zbus::ProxyDefault;
<$proxy>::builder(&self.zbus)
.path(&self.path)?
.destination(crate::raw::networkmanager::NetworkManagerProxy::DESTINATION)?
.build()
.await
.map_err(crate::Error::ZBus)
}
}
};
}
macro_rules! zproxy_sub {
($parent:ty, $facade:ty, $proxy:ty) => {
impl $facade {
#[cfg(not(feature = "raw"))]
pub(crate) async fn raw(&self) -> Result<$proxy, crate::Error> {
use zbus::ProxyDefault;
<$proxy>::builder(&self.parent.zbus)
.path(&self.parent.path)?
.destination(crate::raw::networkmanager::NetworkManagerProxy::DESTINATION)?
.build()
.await
.map_err(crate::Error::ZBus)
}
/// Get the raw D-Bus proxy.
#[cfg(feature = "raw")]
pub async fn raw(&self) -> Result<$proxy, crate::Error> {
use zbus::ProxyDefault;
<$proxy>::builder(&self.parent.zbus)
.path(&self.parent.path)?
.destination(crate::raw::networkmanager::NetworkManagerProxy::DESTINATION)?
.build()
.await
.map_err(crate::Error::ZBus)
}
pub(crate) fn new(parent: $parent) -> Self {
Self { parent }
}
}
};
}
pub(crate) use zproxy_pathed;
pub(crate) use zproxy_sub;
pub(crate) use zproxy_unpathed;