DBUS hello world service

Rohit Chaudhri rohit.chaudhri at gmail.com
Sun Mar 19 19:34:37 PST 2006


Hello,
Thanks for your help on this. I have now rebuilt dbus with some
modifications to the  build script and the dbus-mainloop.h/c.
dbus-mainloop is now included in the libdbus shared lib and I'm now
exporting some functions (create/run loop add/remove watch, handle
dispatch etc) from it that I call from my service. Is this the right
way to do this? My service will only respond to P2P dbus calls.
After putting in the mainloop I can now establish a connection between
my client & server. However after the connection is established, any
communication from the client to the server, results in a disconnect
signal being generated on the server. The server exports an object
path & on the client I have tried querying the object path, sending a
signal and a METHOD_CALL message. These all result in a disconnect
signal being generated on the server which I see in a filter I've
added on  the server. Any ideas as to why this is happening and how I
should do it right?
After connection set up when I send the message/query from the client
I see the following sequence on the server:
- connection_watch callback is called twice
- remove_connection_watch is called twice (is this expected??) in
which I remove the watch from the mainloop.
- dispatch is called twice,
- the filter is called with a disconnect signal being generated from 
/org/freedesktop/DBus/Local

Would appreciate any help regarding this. src code for my helloworld
service & client are attached with this mail. In the service I've
added comments to indicate where service object, server setup &
connection setup code is implemented.

Thanks,
Rohit


On 3/16/06, John (J5) Palmieri <johnp at redhat.com> wrote:
> On Wed, 2006-03-15 at 16:37 -0600, Rohit Chaudhri wrote:
> > Hi,
> > I want to use DBUS as the IPC mechanism for my applications running on
> > an embedded linux device. I can't use the DBUS Glib or Qt bindings so
> > the implementation will use the DBUS low-level API. Since the
> > communication will be point-to-point, I don't need to route the
> > messages through the bus daemon so the service & clients will talk to
> > each other directly
> > I'm trying to learn the DBUS API, I've read the DBUS tutorial & spec
> > and have written a hello-world DBUS service and client using the 0.60
> > API. The code doesn't do much yet, the service calls the following
> > functions and goes into a loop:
> > dbus_server_listen(DBUS_HELLO_SVC,&error);
> > dbus_server_set_new_connection_function(srv,onConnect,NULL,freeFunction);     dbus_server_set_watch_functions(srv,onWatchAdd,onWatchRemove,onWatchToggled,NULL,freeFunction);
> >
> > On the client I call dbus_connection_open(DBUS_HELLO_SVC,&error), the
> > call succeeds however the onConnect function defined in the service
> > never gets called.
> > I'm attaching my service/client src files with this email.
> > Any idea why the onConnect method is not being called in the service?
> > I've probably not done something correctly or have not initialized the
> > service completely. Would appreciate any help regarding this.
>
>
> You don't have a mainloop.  At the end of your service main you have
> while (1) {}.  You need to have some sort of mainloop that polls,
> processes and dispatches.  This is usually done by say the glib
> mainloop.  You commented out the dbus mainloop.  It is a limited
> mainloop that is not exported in the API.  The idea is to take that code
> and integrate it into the mainloop you would be using or if you want to
> make a pure server that only has to respond to dbus calls you can take
> the mainloop wholesale and just copy and renamespace the API.
>
> --
> John (J5) Palmieri <johnp at redhat.com>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbus-hello-svc.c
Type: text/x-csrc
Size: 6815 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20060319/53ce4587/dbus-hello-svc.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbus-hello-client.c
Type: text/x-csrc
Size: 1608 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20060319/53ce4587/dbus-hello-client.c


More information about the dbus mailing list