getting off the ground

John (J5) Palmieri johnp at redhat.com
Fri Jun 13 07:43:08 PDT 2008


On Tue, 2008-06-10 at 15:47 -0400, Chris Cole wrote:
> Hey all,
> I really want to use dbus in this custom little application I'm
> developing. The problem is I'm having a little  trouble getting the
> intro examples to work. I'm trying to run a C++ dbus program to receive
> messages and have a python program send messages to it. Attached are my
> two examples, almost straight from the respective C and python
> tutorials....I can compile and run the C++ code with:
> 
> $ g++ dbus_recv.cc -o dbus_recv -I/usr/include/dbus-1.0
> -I/usr/lib/dbus-1.0/include  -ldbus-1
> $ ./dbus_recv
> Listening for signals
> Match rule sent
> 
> But when I run the python code to call a method it just hangs. Any help
> would be greatly appreciated :)

Well of course the python program is hanging.  When calling a method in
python it will use the send_with_reply_and_block() API which as the name
implies will block for a reply.  You are not sending a reply so it
blocks until timeout.  Also you are doing this:

  dbus_connection_read_write(conn, 0);
  msg = dbus_connection_pop_message(conn);

  // loop again if we haven't read a message
  if (NULL == msg)
    { 
      sleep(1);
    }

while personally I'd be doing:

dbus_connection_read_write(conn, 1000);

msg = dbus_connection_pop_message(conn);

while(msg = dbus_connection_pop_message(conn))
  {
    //process here
  }


even better is to use the dbus_connection_read_write_dispatch() API or
an actual mainloop.
http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html has
documentation for the read_write APIs.

In any case I don't see why print "Test" isn't being called or at least
on of the cases isn't being printed out.  Can you verify that msg is
ever getting any data.  I have a sneaking suspicion that the way you are
handling dispatching.  Otherwise it would be the match rule but that
looks right.

BTW a lot of the comments are slightly wrong
// see method calls from the given interface

should read

TO the given interface

and

// loop listening for signals being emmitted

should be 

listening for messages being sent

or in your case you are only listening for methods calls

You refer to your method call as a signal in a couple of other areas
also.  Understanding some of the basic concepts such as the difference
between a method call, method return, signal and error messages will
help you debug your application better.

-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list