#dbus #macro #task

yanked dbus-macros

Convenient macros to use the dbus crate

Uses old Rust 2015

0.2.4 Jul 19, 2020
0.2.3 Feb 27, 2018
0.2.0 Apr 18, 2017
0.1.0 Apr 16, 2017
0.0.6 Sep 22, 2016

#126 in #dbus

Download history 7/week @ 2024-04-22 10/week @ 2024-05-13 14/week @ 2024-05-20 9/week @ 2024-05-27 13/week @ 2024-06-03 13/week @ 2024-06-10 1/week @ 2024-06-17 5/week @ 2024-06-24 9/week @ 2024-07-01 13/week @ 2024-07-08 106/week @ 2024-07-29

119 downloads per month
Used in way-cooler

MIT license

13KB
177 lines


No longer maintained or developed. Dropped in favor of zbus

D-Bus macros for Rust

Dealing with D-Bus in your code can be a bit tedious. These macros makes the task simpler. They are inspired by Vala's awesome D-Bus support.

Examples

Server

This example serves a bunch of methods on an object

extern crate dbus;
#[macro_use]
extern crate dbus_macros;

use dbus::{Connection, BusType};
use std::rc::Rc;

dbus_class!("com.dbus.test", class Hello (variable: i32) {
    fn hello(&this) -> String {
        "Hello!"
    }

    fn hello_with_name(&this, name: &str) -> String {
        format!("Hello, {}!", name)
    }

    fn get_variable(&this) -> i32 {
        this.variable
    }
});

fn main() {
    let variable = 24;
    let session_connection = Connection::get_private(BusType::Session).unwrap();
    let hello = Hello::new(variable);
    hello.run("com.dbus.test", &session_connection, "/Hello");
}

You can try a similar example (which has more methods) by running:

cargo run --example server

Client

This example opens a connection to the server example above and calls its methods.

extern crate dbus;
#[macro_use]
extern crate dbus_macros;

use dbus::{Connection, BusType};
use std::rc::Rc;

dbus_interface!("com.dbus.test", interface Hello {
    fn hello() -> String;
    fn hello_with_name(name: &str) -> String;
    fn get_variable() -> i32;
});

fn main() {
    let session_connection = std::rc::Rc::new(dbus::Connection::get_private(dbus::BusType::Session).unwrap());
    let hello = Hello::new("com.dbus.test", "/Hello", session_connection);

    match hello.hello() {
        Ok(string) => println!("{}", string),
        Err(error) => println!("Error calling DBus service: {}", error),
    }
    println!("{}", hello.hello_with_name("World").unwrap());
    println!("{}", hello.get_variable().unwrap());
}

You can try a similar example (that tries more method calls on the server example) by running:

cargo run --example client

Requirements

dbus 0.5 or higher, but it's handled for you by the cargo system.

Dependencies

~5MB
~114K SLoC