extern crate dbus;
use dbus::arg;
#[derive(Debug)]
pub struct ComExampleDbustestHelloHappened {
pub sender: String,
}
impl arg::AppendAll for ComExampleDbustestHelloHappened {
fn append(&self, i: &mut arg::IterAppend) {
arg::RefArg::append(&self.sender, i);
}
}
impl arg::ReadAll for ComExampleDbustestHelloHappened {
fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
Ok(ComExampleDbustestHelloHappened {
sender: i.read()?,
})
}
}
impl dbus::message::SignalArgs for ComExampleDbustestHelloHappened {
const NAME: &'static str = "HelloHappened";
const INTERFACE: &'static str = "com.example.dbustest";
}
use dbus::blocking::Connection;
use std::error::Error;
use std::time::Duration;
fn main() -> Result<(), Box<dyn Error>> {
let mut c = Connection::new_session()?;
{
let proxy = c.with_proxy("com.example.dbustest", "/hello", Duration::from_millis(5000));
let _id = proxy.match_signal(|h: ComExampleDbustestHelloHappened, _: &Connection| {
println!("Hello happened from sender: {}", h.sender);
true
});
let (s,): (String,) = proxy.method_call("com.example.dbustest", "Hello", ("match_signal example",))?;
println!("{}", s);
}
loop { c.process(Duration::from_millis(1000))?; }
}