usecrate::{Message, MessageType, Error, to_c_str, c_str_to_slice}; use std::ptr;
use std::collections::HashMap;
/// [Unstable and Experimental] pubtrait MessageDispatcherConfig: Sized { /// The type of method reply stored inside the dispatcher type Reply;
/// Called when a method call has received a reply. fn on_reply(reply: Self::Reply, msg: Message, dispatcher: &mut MessageDispatcher<Self>);
/// Called when a signal is received. /// /// Defaults to doing nothing. #[allow(unused_variables)] fn on_signal(msg: Message, dispatcher: &mut MessageDispatcher<Self>) {}
/// Called when a method call is received. /// /// Defaults to calling default_dispatch. fn on_method_call(msg: Message, dispatcher: &mut MessageDispatcher<Self>) { iflet Some(reply) = MessageDispatcher::<Self>::default_dispatch(&msg) { Self::on_send(reply, dispatcher);
}
}
/// Called in the other direction, i e, when a message should be sent over the connection. fn on_send(msg: Message, dispatcher: &mut MessageDispatcher<Self>);
}
/// Adds a waiting reply to a method call. func will be called when a method reply is dispatched. pubfn add_reply(&mutself, serial: u32, func: C::Reply) { iflet Some(_) = self.waiting_replies.insert(serial, func) { // panic because we're overwriting something else, or just ignore?
}
}
/// Handles what we need to be a good D-Bus citizen. /// /// Call this if you have not handled the message yourself: /// * It handles calls to org.freedesktop.DBus.Peer. /// * For other method calls, it sends an error reply back that the method was unknown. pubfn default_dispatch(m: &Message) -> Option<Message> { Self::peer(&m)
.or_else(|| Self::unknown_method(&m))
}
/// Replies if this is a call to org.freedesktop.DBus.Peer, otherwise returns None. pubfn peer(m: &Message) -> Option<Message> { iflet Some(intf) = m.interface() { if &*intf != "org.freedesktop.DBus.Peer" { return None; } iflet Some(method) = m.member() { if &*method == "Ping" { return Some(m.method_return()) } if &*method == "GetMachineId" { letmut r = m.method_return(); letmut e = Error::empty(); unsafe { let id = ffi::dbus_try_get_local_machine_id(e.get_mut()); if id != ptr::null_mut() {
r = r.append1(c_str_to_slice(&(id as *const _)).unwrap());
ffi::dbus_free(id as *mut _); return Some(r)
}
}
}
}
Some(m.error(&"org.freedesktop.DBus.Error.UnknownMethod".into(), &to_c_str("Method does not exist")))
} else { None }
}
/// For method calls, it replies that the method was unknown, otherwise returns None. pubfn unknown_method(m: &Message) -> Option<Message> { if m.msg_type() != MessageType::MethodCall { return None; } // if m.get_no_reply() { return None; } // The reference implementation does not do this?
Some(m.error(&"org.freedesktop.DBus.Error.UnknownMethod".into(), &to_c_str("Path, Interface, or Method does not exist")))
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-18)
¤
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.