DBus Signal Questions
Derrill Vezina
vezinadj at gmail.com
Tue Dec 20 16:16:15 UTC 2016
Hello!
I have been playing around and writing my own DBus bindings for IPC using C++ to communicate using DBus signals to mimic “socket like” communications on top of the libdbus C API.
This is the situation I am running into that I would like to see if there is some rules or exceptions I can use to work around some functionality:
1. I have 2 processes attached to a session bus named “test.echo” on an object / interface named “pingpong” with a signal called “pingpong”.
2. Each process can read and write to that signal to act as a pipe.
3. Using synchronous reading and writing, process 2 reads the data and echo’s the data back for a ping pong demo.
4. After process 1 sends data, process 2 then reads the data and echo’s it back, in which process 1 waits to read the data.
Eventually, I would like to attach multiple processes to the same signal for broadcasting.
Here is some sudo code
Process 1:
writeSignalData(“pingpong”)
print(“Wrote pingpong”)
while (true) {
message = readSignalData()
if (message.size()) {
print(“Echo received:” + message)
}
}
Process 2:
while (true) {
message = readSignalData()
if (message.size()) {
print(“Echoing: “ + message)
writeSignalData(message)
}
}
The problem that I am running into is that in the echoing process 2 is receiving its own signal after process 2 calls “writeSignalData()” since it is also technically subscribed to the signal…
For example, the output of the sudo code would be:
Process 1 – Wrote pingpong
Process 2 – Echoing: pingpong
Process 1 – Echo received: pingpong
Process 2 – Echoing: pingpong
Process 2 – Echoing: pingpong
Process 2 – Echoing: pingpong
Process 2 – Echoing: pingpong
Process 2 – Echoing: pingpong
Process 2 – Echoing: pingpong
Process 2 – Echoing: pingpong
Process 2 – Echoing: pingpong
…
One way I can think of getting around this is to add a randomly generated serial (the serial functionality in a libdbus message) to each message sent and keep an internal list of ignored serials after echoing. If the serial from the message received is a part of the blacklisted serials, then pop the message, ignore it, and move on.
I didn’t know if there was a better way to do this using rules, or possibly using two signals for bi-directional communications so that I don’t get my own sent data. I found very little for examples on the net for this way of using DBus.
I know I may not be using the DBus the way it was intended… I just like the fact that all of the TCP packet parsing is already done and grouped, also the fact that it is typed data transactions.
Derrill Vezina, PE
vezinadj at gmail.com
207-251-9072
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dbus/attachments/20161220/eb9b561e/attachment.html>
More information about the dbus
mailing list