Zbus 创建没有目的地的代理构建器

问题描述 投票:0回答:1

如何使用 zbus 设置空目的地?我想接收一个具有(空目的地)的信号,但 ProxyBuilder 不允许我这样做。

这就是我发送信号的方式。

dbus-send --system --type=signal / com.example.greeting.GreetingSignal string:"wotcha"

use tokio::runtime::Runtime;
use tokio_stream::StreamExt;
use zbus::{Connection, ProxyBuilder, Proxy, zvariant::NoneValue};

#[tokio::main]
async fn main() -> zbus::Result<()> {
    // Connect to the system bus
    let connection = Connection::system().await?;

    // Create a proxy builder for the signal interface
    let proxy_builder = ProxyBuilder::new(&connection)
        .destination(zbus::names::BusName::null_value())?
        .path("/")?
        .interface("com.example.greeting")?;

    let proxy: Proxy<'_> = proxy_builder.build().await?;

    let mut signal_rec = proxy.receive_signal("GreetingSignal").await?;

    while let Some(msg) = signal_rec.next().await {

        let grt: String = msg.body().deserialize()?;

        println!("{}", grt);
    }

    Ok(())
}

我尝试使用 None 和空字符串,但仍然失败。

rust raspberry-pi dbus
1个回答
0
投票

我遇到了同样的问题并通过

None::<zbus::names::BusName>
解决了它。如果你只是说
None
,编译器会抱怨无法推断可选类型,所以你需要指定它。
dbus-monitor
也这样显示
(null destination)

© www.soinside.com 2019 - 2024. All rights reserved.