DBus server and notification

yrc yohann at varyoh.com
Tue Oct 4 12:40:42 PDT 2005


Le mardi 04 octobre 2005 à 02:22 -0400, John (J5) Palmieri a écrit :
> Wow, you are going about it the hard way.  Creating a server is if you
> want to do point to point communication which in some cases makes
sense.
> However it is much more secure and common to use the bus to
communicate
> (either the session or the system bus depending on your application).
> Take a look at the example code provided in the DBus sources.  What
you
> want to do is have the server get a name on the bus and emit signals
> when songs change.  You then want to have your clients listen for
those
> signals on the bus.  Most apps work this way so you should be able to
> find code for emitting and receiving signals over the bus. 
> 

Ok thank's for this answer!

I've search in the test directory of the sources of dbus, i don't know
if I'm in the right way now... i can't find a simple example of what i'm
trying to do... If someone can help me more...
I change a part of my code, so now, the server initialisation looks
like:

///////////////
gboolean
vnap_dbus_init_server (void)
{
        ...
        bus_conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
        ...
        dbus_bus_acquire_service (bus_conn, VNAP_DBUS_SERVICE, 0,
&error);
        ...
        if (!dbus_connection_register_object_path (bus_conn, 
                        VNAP_PLAYER_OBJECT, &server_vtable, NULL)) {
                g_warning ("Failed to register server object with the
D-BUS bus
daemon");
                return FALSE;
        }
        ...
}

///////////////

and the client:

gboolean
vnap_dbus_init_client (void)
{
        ...
        bus_conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
        ...
        dbus_connection_setup_with_g_main (bus_conn, NULL);
}

////////////////

Is it ok ? or do I have to make other things (of course, the "..." are
error handling and some other stuff, not realy important here...)



Now i have one more problem:
of course, if I launch the server like this, i have a message:

** (process:4653): WARNING **: Failed to connect to the D-BUS daemon:
Unable to determine the address of the message bus



ok, i can initialize something (I don't know exactly what) with
dbus-launch which is in the tool directory of the sources of dbus, with:

$ /home/varyoh/src/dbus-0.23.4/tools/dbus-launch --sh-syntax
--config-file=../vnap_dbus.config

And then define DBUS_SESSION_BUS_ADDRESS, for example:

$ export DBUS_SESSION_BUS_ADDRESS='unix:abstract=/tmp/dbus-senEFRA5nG'

well, after this, both server and client can start, and run, but not
receive any message...

My client do :
        DBusMessage *message;

        message = dbus_message_new_method_call (NULL, VNAP_PLAYER_PATH,
                        VNAP_PLAYER_INTERFACE, VNAP_PLAYER_PLAY);

        dbus_connection_send (bus_conn, message, NULL);
        dbus_message_unref (message);
        dbus_connection_flush (bus_conn);

and my server don't receive anything....


So now, my questions:
* now, is-it the right way to do something like that ? remember that the
server is a daemon and there can be a lots of clients, all are separate
executables.

* is-it possible to do anything to avoid the use of dbus-launch and
export before to run my program ? dbus-launch is in the sources of dbus,
but it's not realy easy for the end user to use something like that...

* What's append with my message that I don't receive ? lost in the
space ;)

* there is always my question about the method i use for method calls...
make a list of if / else if.... ?

thank you for your invaluable assistance :-) !
I hope to be able to help you later and submitting patches too :-D

Yohann.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/dbus/attachments/20051004/6ed5745d/attachment.pgp


More information about the dbus mailing list