getting off the ground

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


On Fri, 2008-06-13 at 10:43 -0400, John (J5) Palmieri wrote:
> 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 differenceAh
> between a method call, method return, signal and error messages will
> help you debug your application better.

Ah ha.  I now know what your issue is but I am going to let you figure
it out for yourself with a couple of hints.  

1. You need to handle all method calls sent to you even if it means
sending back an "I don't handle this method" error (there is a standard
D-Bus error for this, check
http://dbus.freedesktop.org/doc/api/html/dbus-protocol_8h-source.html
for the proper name).

2. You don't need to add match rules for method calls addressed to you.
Only signals.  This also means you will get all method calls addressed
to you.

3. Your dispatch is fine though not the way I would do things.  If you
need nonblocking at that point it is time to create an actual mainloop.

Hope that helps.  You will understand things much better if you run
through the documentation and figure it out for yourself.

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



More information about the dbus mailing list