dbus2 / zbus-old

Rust D-Bus crate.
https://gitlab.freedesktop.org/dbus/zbus
Other
49 stars 13 forks source link

Server example in documentation doesn't work #270

Closed zeenix closed 1 year ago

zeenix commented 2 years ago

In GitLab by @jakobrs on Apr 16, 2022, 15:28

The issue

The documentation gives this as an example of how a basic dbus-based server might be implemented:

use zbus::{Connection, Result};
use futures_util::stream::TryStreamExt;

// Although we use `async-std` here, you can use any async runtime of choice.
#[async_std::main]
async fn main() -> Result<()> {
    let connection = Connection::session()
        .await?;
    connection
        .request_name("org.zbus.MyGreeter")
        .await?;

    let mut stream = zbus::MessageStream::from(&connection);
    while let Some(msg) = stream.try_next().await? {
        let msg_header = msg.header()?;
        dbg!(&msg);

        match msg_header.message_type()? {
            zbus::MessageType::MethodCall => {
                // real code would check msg_header path(), interface() and member()
                // handle invalid calls, introspection, errors etc
                let arg: &str = msg.body()?;
                connection.reply(&msg, &(format!("Hello {}!", arg))).await?;

                break;
            }
            _ => continue,
        }
    }

    Ok(())
}

However, the attempting to make method calls to the dbus interface defined above results in an error, which will look something like this:

Error: org.freedesktop.DBus.Error.UnknownObject: Unknown object '/org/zbus/MyGreeter'

The issue is present with both the async and blocking versions of zbus's API, and has been reproduced using both busctl --user call and zbus::blocking::Connection::call_method.

zeenix commented 2 years ago

In GitLab by @jakobrs on Apr 16, 2022, 21:18

The object server is created because the service calls request_name, which calls self.object_server() on line 525 in connection.rs.

This function call was introduced by https://gitlab.freedesktop.org/dbus/zbus/commit/47c084212fb7157f9a5a5595862f9769fa5f4cdd.

zeenix commented 2 years ago

Right, thanks so much for investigating. I'll look into fixing it soon.

zeenix commented 2 years ago

mentioned in commit 7e1788d219882b40b9d75c9f9f2c02007041988a