[−][src]Crate rustbus
Rustbus
Rustbus is a dbus library that allows for RPC on services on the bus or to implement your own service that listens on the bus. There are some examples in the src/bin directory but the gist is:
use rustbus::{get_session_bus_path, standard_messages, Conn, MessageBuilder, connection::Timeout}; fn main() -> Result<(), rustbus::connection::Error> { // Connect to the session bus let session_path = get_session_bus_path()?; let con = Conn::connect_to_bus(session_path, true)?; // Wrap the con in an RpcConnection which provides many convenient functions let mut rpc_con = rustbus::connection::rpc_conn::RpcConn::new(con); // send the obligatory hello message rpc_con.send_message(&mut standard_messages::hello(), Timeout::Infinite)?; // Request a bus name if you want to rpc_con.send_message(&mut standard_messages::request_name( "io.killing.spark".into(), 0, ), Timeout::Infinite)?; // send a signal to all bus members let mut sig = MessageBuilder::new() .signal( "io.killing.spark".into(), "TestSignal".into(), "/io/killing/spark".into(), ) .build(); sig.body.push_param("Signal message!").unwrap(); rpc_con.send_message(&mut sig, Timeout::Infinite)?; Ok(()) }
To add parameters to messages there are currently two possibilities:
- Using the explicit nested structs/enums from rustbus::params
- Using the (Un-)Marshal trait exported as rustbus::(Un-)Marshal
The first will work for any and everything you might want to marshal, but is a bit more work to actually setup. It is also slower than the Marshal trait. So for most applications I would recommend the newer, faster, and more ergonomic trait based approach.
Re-exports
pub use message_builder::MessageType; |
pub use connection::ll_conn::Conn; |
pub use connection::rpc_conn::RpcConn; |
pub use connection::get_session_bus_path; |
pub use connection::get_system_bus_path; |
pub use message_builder::CallBuilder; |
pub use message_builder::MessageBuilder; |
pub use message_builder::SignalBuilder; |
pub use wire::marshal::traits::Marshal; |
pub use wire::marshal::traits::Signature; |
pub use wire::unmarshal::traits::Unmarshal; |
Modules
auth | Deals with authentication to the other side. You probably do not need this. |
connection | |
message_builder | Helps in building messages conveniently |
params | Map dbus concepts 1:1 to enums/structs |
peer | This module implemets the org.freedesktop.DBus.Peer |
signature | Everything needed to deal with dbus signatures |
standard_messages | Some standard messages that are often needed |
wire | Everything that deals with converting from/to raw bytes. You probably do not need this. |
Macros
dbus_variant_sig | This macro provides a convenient way to create enums to represent relatively simple Variants, with fitting marshal/unmarshal implementations. It can be used like this: |
dbus_variant_var | This macro provides a convenient way to create enums to represent relatively simple Variants, with fitting marshal/unmarshal implementations. It can be used like this: |
Enums
ByteOrder | The supported byte orders |
Error | The different errors that can occur when dealing with messages |