Git Product home page Git Product logo

Comments (7)

diwic avatar diwic commented on June 2, 2024

It's possible to have one thread listen and receive D-Bus calls and another thread handle them.

Your D-Bus thread would look like this (rough outline) :

for item in connection.iter() {
    if let MethodCall(m) = item {
        channel.send(m);
        let reply = other_channel.recv();
        for r in reply { connection.send(r); }
    }
}

The main thread can either have a Tree, and handling is then done by calling Tree.handle() and the result back on the channel, or you can handle the message manually by calling methods on the message to figure out what message it is, and construct an appropriate reply using message.method_return().append(/* ... *).

Edit: minor fix to make example work with tree.handle()

from dbus-rs.

meh avatar meh commented on June 2, 2024

Could you elaborate a little on the Tree way please?

from dbus-rs.

diwic avatar diwic commented on June 2, 2024

You would set up the Tree like in the server example but instead of calling tree.run your code would look like (rough outline, add proper error handling) :

loop {
     let msg = channel.recv();
     let reply = tree.handle(msg);
     other_channel.send(reply);
}

from dbus-rs.

meh avatar meh commented on June 2, 2024

Got another related question, how would I go about sending asynchronous signals?

Let's say I want to emit the signals directly from the main thread, is there a way to do it?

I was trying to put the Connection into an Arc but it's not Sync and Send and share the Arc<tree::Signal> between the tree thread and the main thread, but I guess it wouldn't really work.

Any hints?

from dbus-rs.

diwic avatar diwic commented on June 2, 2024

The easiest way is to have two connections. I could see if I could make Connection Send, because I think it should be, but I doubt that will help much in your case.

There is also some stuff written about connection and thread safety in the API indicating that it could maybe even be Sync. That would require some work on my part though as my wrapper currently isn't sync.

from dbus-rs.

meh avatar meh commented on June 2, 2024

Won't the register_name explode because I'm overriding an already existing interface?

from dbus-rs.

diwic avatar diwic commented on June 2, 2024

Won't the register_name explode because I'm overriding an already existing interface?

You don't need to register a name to send signals, AFAIK?

from dbus-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.