#[cfg(any(feature = "proxy", feature = "object-manager"))]
use std::borrow::Cow;
use std::collections::HashMap;
#[cfg(feature = "object-manager")]
use super::Error;
#[cfg(any(feature = "proxy", feature = "object-manager"))]
use super::Result;
#[cfg(feature = "object-manager")]
use crate::{Connection, ObjectServer, interface, message::Header, object_server::SignalEmitter};
#[cfg(any(feature = "proxy", feature = "object-manager"))]
use crate::{ObjectPath, Variant, names::InterfaceName};
use crate::{OwnedObjectPath, OwnedVariant, names::OwnedInterfaceName};
#[cfg_attr(
feature = "proxy",
doc = "The type returned by the [`ObjectManagerProxy::get_managed_objects`] method."
)]
#[cfg_attr(
not(feature = "proxy"),
doc = "The type returned by `ObjectManagerProxy::get_managed_objects` (requires the `proxy`",
doc = "feature)."
)]
pub type ManagedObjects =
HashMap<OwnedObjectPath, HashMap<OwnedInterfaceName, HashMap<String, OwnedVariant>>>;
#[cfg(feature = "object-manager")]
#[derive(Debug, Clone)]
pub struct ObjectManager;
#[cfg(feature = "object-manager")]
#[interface(
name = "org.freedesktop.DBus.ObjectManager",
introspection_docs = false
)]
impl ObjectManager {
async fn get_managed_objects(
&self,
#[zbus(object_server)] server: &ObjectServer,
#[zbus(connection)] connection: &Connection,
#[zbus(header)] header: Header<'_>,
) -> Result<ManagedObjects> {
let path = header.path().ok_or(crate::Error::MissingField)?;
let root = server.root().read().await;
let node = root
.get_child(path)
.ok_or_else(|| Error::UnknownObject(format!("Unknown object '{path}'")))?;
node.get_managed_objects(server, connection).await
}
#[zbus(signal)]
pub async fn interfaces_added(
emitter: &SignalEmitter<'_>,
object_path: ObjectPath<'_>,
interfaces_and_properties: HashMap<InterfaceName<'_>, HashMap<&str, Variant<'_>>>,
) -> zbus::Result<()>;
#[zbus(signal)]
pub async fn interfaces_removed(
emitter: &SignalEmitter<'_>,
object_path: ObjectPath<'_>,
interfaces: Cow<'_, [InterfaceName<'_>]>,
) -> zbus::Result<()>;
}
#[cfg(feature = "proxy")]
#[crate::proxy(interface = "org.freedesktop.DBus.ObjectManager")]
pub trait ObjectManager {
fn get_managed_objects(&self) -> Result<ManagedObjects>;
#[zbus(signal)]
fn interfaces_added(
&self,
object_path: ObjectPath<'_>,
interfaces_and_properties: HashMap<InterfaceName<'_>, HashMap<&str, Variant<'_>>>,
) -> zbus::Result<()>;
#[zbus(signal)]
fn interfaces_removed(
&self,
object_path: ObjectPath<'_>,
interfaces: Cow<'_, [InterfaceName<'_>]>,
) -> zbus::Result<()>;
}