DBus server and notification
yrc
yohann at varyoh.com
Mon Oct 3 22:29:06 PDT 2005
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.
-------------- 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/971f611e/attachment.pgp
More information about the dbus
mailing list