Problems with dbus_connection_borrow_message

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with dbus_connection_borrow_message

itchy_2390
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with dbus_connection_borrow_message

Simon McVittie-6
Before getting into specifics, did you see the bit in the documentation
that points out that libdbus is a low-level library and is painful to
use? You would probably be better off with GDBus (part of GLib) or
QtDBus (part of Qt), which interoperate with libdbus and are a lot
easier: in particular, they integrate nicely with the main-loop
conventions of their respective frameworks.

On 24/02/15 11:54, itchy_2390 wrote:
>    DBusMessage *pMsg = dbus_connection_pop_message(Conn);
...
>    pMsg = dbus_connection_borrow_message(Conn);

These are low-level functions that you probably shouldn't be using, even
if you are using libdbus. The usual way to receive signals via libdbus
is to add a "filter function", then "dispatch" the connection by either
hooking it up to a main loop or calling
dbus_connection_read_write_dispatch().

>        if (dbus_message_is_signal(pMsg, iface, signal_name))
...
> But now I never get signals.
> What Am I doing wrong?

Are you using the right interface name?

Are you using the right signal name?

Did you ask to receive the signals you wanted, by adding a match rule?

--
Simon McVittie
Collabora Ltd. <http://www.collabora.com/>

_______________________________________________
dbus mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/dbus
Reply | Threaded
Open this post in threaded view
|

Re: Problems with dbus_connection_borrow_message

itchy_2390
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with dbus_connection_borrow_message

Simon McVittie-6
On 24/02/15 15:03, itchy_2390 wrote:
> I think I got a little bit further If I call
> dbus_connection_read_write_dispatch instead of dbus_connection_read_write I
> get the signals. But I'm not sure I understand the difference between these
> two functions.

It's very simple, one of them dispatches and the other one doesn't :-)
But I realise it isn't entirely obvious what "dispatch" means.

"read_write" in this context means doing the actual socket I/O: writing
outgoing messages to the socket until the buffer is full or there is
nothing more to write, and putting incoming messages in a queue inside
the DBusConnection until a limit is reached or there is nothing more to
read.

"dispatch" means draining that queue by handing out messages to their
correct recipients: DBusPendingCall objects that expect replies for
outgoing method calls, the filter functions that I recommended you
should use for signals, and object-path handlers for incoming method calls.

Popping/borrowing/stealing messages from the connection takes them off
the queue directly, bypassing the dispatching code. You probably don't
want that: even the dbus-daemon and the dbus-monitor tool don't do that
(they use filters), and they're quite low-level themselves.

--
Simon McVittie
Collabora Ltd. <http://www.collabora.com/>

_______________________________________________
dbus mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/dbus
Reply | Threaded
Open this post in threaded view
|

Re: Problems with dbus_connection_borrow_message

itchy_2390
CONTENTS DELETED
The author has deleted this message.