DBus server and notification

John (J5) Palmieri johnp at redhat.com
Tue Oct 4 13:19:14 PDT 2005


On Tue, 2005-10-04 at 14:40 -0500, yrc wrote:

Great, you are on the right track.  You now want to set up signal
handlers in your clients.  To do this you want to add a match rule to
the bus similar to this:

 dbus_bus_add_match (connection,
                      "type='signal',member='SongChange',
interface='my.songchange.Interface',path='/my/songchange/object/path'",
                      &error);

and you will need to hook up a filter function to catch all the signals
calls:

dbus_connection_add_filter (connection, filter_func, NULL, NULL);

static DBusHandlerResult
filter_func (DBusConnection     *connection,
             DBusMessage        *message,
             void               *user_data)
{

  if (dbus_message_is_signal (message,
                              "my.songchange.Interface",
                              "SongChange"))
    {
      /* do stuff */

      return DBUS_HANDLER_RESULT_HANDLED;
    }

  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}


You would then construct a signal message in your server in a similar
way you construct method calls.

Hope this helps. 

> 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.
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus
-- 



More information about the dbus mailing list