/* This example creates a D-Bus server with the following functionality: Itregistersthe"com.example.dbustest"name,createsa"/hello"objectpath, whichhasan"com.example.dbustest"interface.
use std::sync::Arc; use dbus::{Connection, BusType, NameFlag}; use dbus::tree::Factory;
fn main() { // Let's start by starting up a connection to the session bus and register a name. let c = Connection::get_private(BusType::Session).unwrap();
c.register_name("com.example.dbustest", NameFlag::ReplaceExisting as u32).unwrap();
// The choice of factory tells us what type of tree we want, // and if we want any extra data inside. We pick the simplest variant. let f = Factory::new_fn::<()>();
// We create the signal first, since we'll need it in both inside the method callback // and when creating the tree. let signal = Arc::new(f.signal("HelloHappened", ()).sarg::<&str,_>("sender")); let signal2 = signal.clone();
// We create a tree with one object path inside and make that path introspectable. let tree = f.tree(()).add(f.object_path("/hello", ()).introspectable().add(
// We add an interface to the object path...
f.interface("com.example.dbustest", ()).add_m(
// ...and a method inside the interface.
f.method("Hello", (), move |m| {
// This is the callback that will be called when another peer on the bus calls our method. // the callback receives "MethodInfo" struct and can return either an error, or a list of // messages to send back.
let name: &str = m.msg.read1()?; let s = format!("Hello {}!", name); let mret = m.msg.method_return().append1(s);
let sig = signal.msg(m.path.get_name(), m.iface.get_name())
.append1(&*name);
// Two messages will be returned - one is the method return (and should always be there), // and in our case we also have a signal we want to send at the same time.
Ok(vec!(mret, sig))
// Our method has one output argument and one input argument.
}).outarg::<&str,_>("reply")
.inarg::<&str,_>("name")
// We also add the signal to the interface. This is mainly for introspection.
).add_s(signal2)
));
// We register all object paths in the tree.
tree.set_registered(&c, true).unwrap();
// We add the tree to the connection so that incoming method calls will be handled // automatically during calls to "incoming".
c.add_handler(tree);
// Serve other peers forever. loop { c.incoming(1000).next(); }
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.19 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.