zbus/fdo/
introspectable.rs

1//! D-Bus standard interfaces.
2//!
3//! The D-Bus specification defines the message bus messages and some standard interfaces that may
4//! be useful across various D-Bus applications. This module provides their proxy.
5
6use super::{Error, Result};
7use crate::{interface, message::Header, ObjectServer};
8
9/// Service-side implementation for the `org.freedesktop.DBus.Introspectable` interface.
10/// This interface is implemented automatically for any object registered to the
11/// [ObjectServer](crate::ObjectServer).
12pub(crate) struct Introspectable;
13
14#[interface(
15    name = "org.freedesktop.DBus.Introspectable",
16    introspection_docs = false,
17    proxy(default_path = "/", visibility = "pub")
18)]
19impl Introspectable {
20    /// Returns an XML description of the object, including its interfaces (with signals and
21    /// methods), objects below it in the object path tree, and its properties.
22    async fn introspect(
23        &self,
24        #[zbus(object_server)] server: &ObjectServer,
25        #[zbus(header)] header: Header<'_>,
26    ) -> Result<String> {
27        let path = header.path().ok_or(crate::Error::MissingField)?;
28        let root = server.root().read().await;
29        let node = root
30            .get_child(path)
31            .ok_or_else(|| Error::UnknownObject(format!("Unknown object '{path}'")))?;
32
33        Ok(node.introspect().await)
34    }
35}