zbus:用目的地捕获信号

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

然后用ZBUS板条箱写了Followng代码:

use futures_util::stream::StreamExt;
use zbus::{zvariant::OwnedObjectPath, proxy, Connection};
use zbus::zvariant::Value;


#[proxy(
    default_service = "it.smartsecurity.dbus",
    default_path = "/test/signal/Object",
    interface = "test.signal.Type",
)]
trait Systemd1Manager {
    // Defines signature for D-Bus signal named `Test`
    #[zbus(signal)]
    fn test(&self, unit: String) -> zbus::Result<()>; // si deve chiamare come il segnale
}

async fn watch_systemd_jobs() -> zbus::Result<()> {
    let connection = Connection::system().await?;
    // `Systemd1ManagerProxy` is generated from `Systemd1Manager` trait
  
    let systemd_proxy = Systemd1ManagerProxy::builder(&connection)
        .destination("it.smartsecurity.dbus")?
        .path("/test/signal/Object")?
        .interface("test.signal.Type")?
        .build().await?;

    // Method `receive_job_new` is generated from `job_new` signal
    let mut new_jobs_stream = systemd_proxy.receive_test().await?;

    while let Some(msg) = new_jobs_stream.next().await {
        //dbg!(&msg);
        // struct `JobNewArgs` is generated from `job_new` signal function arguments
        let args = msg.args();
        dbg!(&args);

        println!("=====================");
        // stampa il nome del servizio e il suo valore
        let x = msg.message().header();
        
        let y = x.member();
        if y.is_some() {
            println!("Header: {}", y.unwrap());
        }

        dbg!(&y);

        let unit = args.unwrap().unit;
        println!("Param: {}", unit);

    }

    panic!("Stream ended unexpectedly");
}

#[tokio::main]
async fn main() {
    watch_systemd_jobs().await.unwrap();
}

我的问题是,这种生锈代码不会捕获信号,我不明白我在做什么错。 感谢您的帮助。

当您将总线消息发送到特定目的地时,它们不再是广播(与您的代码注释相反) - 仅将其发送到该目的地。接收此类信号。

在您的代码中,总线名称由发件人而不是接收器声明,因此发件人实际上将信号发送给本身。

c rust dbus
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.