DBus server and notification

John (J5) Palmieri johnp at redhat.com
Mon Oct 3 23:22:04 PDT 2005


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. 

On Tue, 2005-10-04 at 00:29 -0500, yrc wrote:
> Hello!
> 
> I'm trying to make a kind of music player deamon, using DBus. So, the
> deamon is a server, and all of the others GUI or console based clients
> are... clients. They are separated executables. But, I'm a
> dbus-newbee...
> 
> So, my server is initialized with:
> server = dbus_server_listen (VNAP_DBUS_ADRESS, &error);
> ...
> 
> and my clients with;
> connection = dbus_connection_open (VNAP_DBUS_ADRESS, &error);
> ...
> 
> (first optional question: is-it the right way to do it ? I've seen other
> code where they don't use a server, like in jamboree....)
> 
> I can send a message from the client to the server without any problems,
> and from the server to one client to:
> dbus_connection_send (connection, message, NULL);
> 
> What I would like to do is a kind of notification system, for, for
> example, when the song change: All of the clients have to be notified
> for this change.
> 
> So my (second) first question is: is it possible to do something like
> that with DBus ? I think so, since I've read a part of the
> specifications... So, how ? 
> With my dbus_connection_send(...), I have to store a connection pointer
> for each connected client, and make a for.... Is-it possible to do it in
> a better way?
> 
> Second question: to call a method of the server from the client, I
> actualy use something like that:
> 
> void
> send_play_message ()
> {
> 	DBusMessage *message;
> 	message = dbus_message_new_method_call (NULL, VNAP_PLAYER_PATH,
> 			VNAP_PLAYER_INTERFACE, VNAP_PLAYER_PLAY);
> 	dbus_connection_send (connection, message, NULL);
> 	dbus_message_unref (message);
> 	dbus_connection_flush (connection);
> }
> 
> where VNAP_PLAYER_PLAY is a string "play", the function that I wana
> call, and in the server side:
> 
> static DBusHandlerResult
> server_filter (DBusConnection     *connection,
> 	       DBusMessage        *message,
> 	       void               *user_data)
> {
> 	...
> 	if (dbus_message_is_method_call (message,
> 					VNAP_PLAYER_INTERFACE,
> 					VNAP_PLAYER_PLAY))
> 	{
> 		g_print("Play\n");
> 		return DBUS_HANDLER_RESULT_HANDLED;
> 	}
> 	...
> }
> 
> 
> Of course, it works, but is there another way, something like in ORBit
> where we define a function called "play" and we directly call this
> function from the client ? if yes, how can i do ?
> 
> 
> Ok, that's all for the moment :-)
> Of course, my application will be distributed under the GPL, so if
> anyone want more code, there is no problem (ok, now, there is nothing
> else than 200 lines to try to do something with DBus.... because all of
> the application will be based on the client/server...)
> 
> Thank's a lot!
> Have fun,
> Yohann.
> 
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus
-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list