summaryrefslogtreecommitdiff
path: root/src/dbusbind.c
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2007-12-07 04:40:28 +0000
committerMichael Albinus <michael.albinus@gmx.de>2007-12-07 04:40:28 +0000
commit52da95fa969125d7fe867b48dda8d80f2cc95660 (patch)
treeeba03d658400a22066d1c72f6dddaeedad354eb4 /src/dbusbind.c
parente74d83ee49cac55f1833d8fba8d735a31a99daa4 (diff)
downloademacs-52da95fa969125d7fe867b48dda8d80f2cc95660.tar.gz
* dbusbind.c (Fdbus_get_unique_name, xd_read_message)
(Fdbus_register_signal): Use DBUS_MAXIMUM_NAME_LENGTH and DBUS_MAXIMUM_MATCH_RULE_LENGTH for string lengths. (Fdbus_call_method, Fdbus_send_signal, Fdbus_register_signal): Unify argument lists. (xd_read_message, Fdbus_register_signal) Reorder and extend event arguments and hash table keys. Use unique name for service. (Fdbus_unregister_signal): Remove checks. (Vdbus_registered_functions_table): Fix doc string.
Diffstat (limited to 'src/dbusbind.c')
-rw-r--r--src/dbusbind.c135
1 files changed, 73 insertions, 62 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 07fc24243d7..73b538cf599 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -241,7 +241,7 @@ DEFUN ("dbus-get-unique-name", Fdbus_get_unique_name, Sdbus_get_unique_name,
Lisp_Object bus;
{
DBusConnection *connection;
- char name[1024];
+ char name[DBUS_MAXIMUM_NAME_LENGTH];
/* Check parameters. */
CHECK_SYMBOL (bus);
@@ -287,8 +287,8 @@ are converted into a list of Lisp objects which correspond to the
elements of the D-Bus container. Example:
\(dbus-call-method
- :session "GetKeyField" "org.gnome.seahorse"
- "/org/gnome/seahorse/keys/openpgp" "org.gnome.seahorse.Keys"
+ :session "org.gnome.seahorse" "/org/gnome/seahorse/keys/openpgp"
+ "org.gnome.seahorse.Keys" "GetKeyField"
"openpgp:657984B8C7A966DD" "simple-name")
=> (t ("Philip R. Zimmermann"))
@@ -297,18 +297,18 @@ If the result of the METHOD call is just one value, the converted Lisp
object is returned instead of a list containing this single Lisp object.
\(dbus-call-method
- :system "GetPropertyString" "org.freedesktop.Hal"
- "/org/freedesktop/Hal/devices/computer" "org.freedesktop.Hal.Device"
+ :system "org.freedesktop.Hal" "/org/freedesktop/Hal/devices/computer"
+ "org.freedesktop.Hal.Device" "GetPropertyString"
"system.kernel.machine")
=> "i686"
-usage: (dbus-call-method BUS METHOD SERVICE PATH INTERFACE &rest ARGS) */)
+usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &rest ARGS) */)
(nargs, args)
int nargs;
register Lisp_Object *args;
{
- Lisp_Object bus, method, service, path, interface;
+ Lisp_Object bus, service, path, interface, method;
Lisp_Object result;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
DBusConnection *connection;
@@ -322,23 +322,23 @@ usage: (dbus-call-method BUS METHOD SERVICE PATH INTERFACE &rest ARGS) */)
/* Check parameters. */
bus = args[0];
- method = args[1];
- service = args[2];
- path = args[3];
- interface = args[4];
+ service = args[1];
+ path = args[2];
+ interface = args[3];
+ method = args[4];
CHECK_SYMBOL (bus);
- CHECK_STRING (method);
CHECK_STRING (service);
CHECK_STRING (path);
CHECK_STRING (interface);
- GCPRO5 (bus, method, service, path, interface);
+ CHECK_STRING (method);
+ GCPRO5 (bus, service, path, interface, method);
XD_DEBUG_MESSAGE ("%s %s %s %s",
- SDATA (method),
SDATA (service),
SDATA (path),
- SDATA (interface));
+ SDATA (interface),
+ SDATA (method));
/* Open a connection to the bus. */
connection = xd_initialize (bus);
@@ -447,14 +447,15 @@ Other Lisp objects are not supported as arguments of SIGNAL.
Example:
\(dbus-send-signal
- :session "Started" "org.gnu.emacs" "/org/gnu/emacs" "org.gnu.emacs")))
+ :session "org.gnu.Emacs" "/org/gnu/Emacs"
+ "org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs")
-usage: (dbus-send-signal BUS SIGNAL SERVICE PATH INTERFACE &rest ARGS) */)
+usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */)
(nargs, args)
int nargs;
register Lisp_Object *args;
{
- Lisp_Object bus, signal, service, path, interface;
+ Lisp_Object bus, service, path, interface, signal;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
DBusConnection *connection;
DBusMessage *dmessage;
@@ -464,23 +465,23 @@ usage: (dbus-send-signal BUS SIGNAL SERVICE PATH INTERFACE &rest ARGS) */)
/* Check parameters. */
bus = args[0];
- signal = args[1];
- service = args[2];
- path = args[3];
- interface = args[4];
+ service = args[1];
+ path = args[2];
+ interface = args[3];
+ signal = args[4];
CHECK_SYMBOL (bus);
- CHECK_STRING (signal);
CHECK_STRING (service);
CHECK_STRING (path);
CHECK_STRING (interface);
- GCPRO5 (bus, signal, service, path, interface);
+ CHECK_STRING (signal);
+ GCPRO5 (bus, service, path, interface, signal);
XD_DEBUG_MESSAGE ("%s %s %s %s",
- SDATA (signal),
SDATA (service),
SDATA (path),
- SDATA (interface));
+ SDATA (interface),
+ SDATA (signal));
/* Open a connection to the bus. */
connection = xd_initialize (bus);
@@ -549,7 +550,10 @@ xd_read_message (bus)
DBusMessage *dmessage;
DBusMessageIter iter;
uint dtype;
- char service[1024], path[1024], interface[1024], member[1024];
+ char service[DBUS_MAXIMUM_NAME_LENGTH];
+ char path[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; /* Unlimited in D-Bus spec. */
+ char interface[DBUS_MAXIMUM_NAME_LENGTH];
+ char member[DBUS_MAXIMUM_NAME_LENGTH];
/* Open a connection to the bus. */
connection = xd_initialize (bus);
@@ -590,14 +594,23 @@ xd_read_message (bus)
/* The arguments are stored in reverse order. Reorder them. */
event.arg = Fnreverse (event.arg);
- /* Read service, object path interface and member from the
- message. */
+ /* Read service, object path, interface and member from the message.
+ The service is always the unique name of the sending object. */
strcpy (service, dbus_message_get_sender (dmessage));
strcpy (path, dbus_message_get_path (dmessage));
strcpy (interface, dbus_message_get_interface (dmessage));
strcpy (member, dbus_message_get_member (dmessage));
- /* Add them to the event. */
+ /* Add the registered function of the message. */
+ key = list5 (bus,
+ (service == NULL ? Qnil : build_string (service)),
+ (path == NULL ? Qnil : build_string (path)),
+ (interface == NULL ? Qnil : build_string (interface)),
+ (member == NULL ? Qnil : build_string (member)));
+ event.arg = Fcons (Fgethash (key, Vdbus_registered_functions_table, Qnil),
+ event.arg);
+
+ /* Add service, path, interface and member to the event. */
event.arg = Fcons ((member == NULL ? Qnil : build_string (member)),
event.arg);
event.arg = Fcons ((interface == NULL ? Qnil : build_string (interface)),
@@ -610,13 +623,6 @@ xd_read_message (bus)
/* Add the bus symbol to the event. */
event.arg = Fcons (bus, event.arg);
- /* Add the registered function of the message. */
- key = list3 (bus,
- (interface == NULL ? Qnil : build_string (interface)),
- (member == NULL ? Qnil : build_string (member)));
- event.arg = Fcons (Fgethash (key, Vdbus_registered_functions_table, Qnil),
- event.arg);
-
/* Store it into the input event queue. */
kbd_buffer_store_event (&event);
@@ -666,31 +672,41 @@ SIGNAL and HANDLER must not be nil. Example:
(message "Device %s added" device))
\(dbus-register-signal
- :system "DeviceAdded"
- (dbus-get-name-owner :system "org.freedesktop.Hal")
- "/org/freedesktop/Hal/Manager" "org.freedesktop.Hal.Manager"
- 'my-signal-handler)
+ :system "org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
+ "org.freedesktop.Hal.Manager" "DeviceAdded" 'my-signal-handler)
- => (:system "org.freedesktop.Hal.Manager" "DeviceAdded")
+ => (:system ":1.3" "/org/freedesktop/Hal/Manager"
+ "org.freedesktop.Hal.Manager" "DeviceAdded")
`dbus-register-signal' returns an object, which can be used in
`dbus-unregister-signal' for removing the registration. */)
- (bus, signal, service, path, interface, handler)
- Lisp_Object bus, signal, service, path, interface, handler;
+ (bus, service, path, interface, signal, handler)
+ Lisp_Object bus, service, path, interface, signal, handler;
{
- Lisp_Object key;
+ Lisp_Object unique_name, key;
DBusConnection *connection;
- char rule[1024];
+ char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
DBusError derror;
/* Check parameters. */
CHECK_SYMBOL (bus);
- CHECK_STRING (signal);
if (!NILP (service)) CHECK_STRING (service);
if (!NILP (path)) CHECK_STRING (path);
CHECK_STRING (interface);
+ CHECK_STRING (signal);
CHECK_SYMBOL (handler);
+ /* Retrieve unique name of service. If service is a known name, we
+ will register for the corresponding unique name, if any. Signals
+ are sent always with the unique name as sender. Note: the unique
+ name of "org.freedesktop.DBus" is that string itself. */
+ if ((!NILP (service)) &&
+ (strcmp (SDATA (service), DBUS_SERVICE_DBUS) != 0) &&
+ (strncmp (SDATA (service), ":", 1) != 0))
+ unique_name = call2 (intern ("dbus-get-name-owner"), bus, service);
+ else
+ unique_name = service;
+
/* Open a connection to the bus. */
connection = xd_initialize (bus);
@@ -700,9 +716,9 @@ SIGNAL and HANDLER must not be nil. Example:
SDATA (interface),
SDATA (signal));
- /* Add service and path to the rule if they are non-nil. */
- if (!NILP (service))
- sprintf (rule, "%s,sender='%s'%", rule, SDATA (service));
+ /* Add unique name and path to the rule if they are non-nil. */
+ if (!NILP (unique_name))
+ sprintf (rule, "%s,sender='%s'%", rule, SDATA (unique_name));
if (!NILP (path))
sprintf (rule, "%s,path='%s'", rule, SDATA (path));
@@ -716,7 +732,7 @@ SIGNAL and HANDLER must not be nil. Example:
XD_DEBUG_MESSAGE ("Matching rule \"%s\" created", rule);
/* Create a hash table entry. */
- key = list3 (bus, interface, signal);
+ key = list5 (bus, unique_name, path, interface, signal);
Fputhash (key, handler, Vdbus_registered_functions_table);
XD_DEBUG_MESSAGE ("\"%s\" registered with handler \"%s\"",
SDATA (format2 ("%s", key, Qnil)),
@@ -734,13 +750,6 @@ OBJECT must be the result of a preceding `dbus-register-signal' call. */)
Lisp_Object object;
{
- /* Check parameters. */
- CHECK_SYMBOL (object);
-
- XD_DEBUG_MESSAGE ("\"%s\" unregistered with handler \"%s\"",
- SDATA (format2 ("%s", object, Qnil)),
- SDATA (format2 ("%s", Fsymbol_function (object), Qnil)));
-
/* Unintern the signal symbol. */
Fremhash (object, Vdbus_registered_functions_table);
@@ -788,10 +797,12 @@ syms_of_dbusbind ()
DEFVAR_LISP ("dbus-registered-functions-table", &Vdbus_registered_functions_table,
doc: /* Hash table of registered functions for D-Bus.
-The key in the hash table is the list (BUS INTERFACE MEMBER). BUS is
-either the symbol `:system' or the symbol `:session'. INTERFACE is a
-string which denotes a D-Bus interface, and MEMBER, also a string, is
-either a method or a signal INTERFACE is offering.
+The key in the hash table is the list (BUS SERVICE PATH MEMBER INTERFACE).
+BUS is either the symbol `:system' or the symbol `:session'. SERVICE
+and PATH are the unique name and the object path of the sending object.
+INTERFACE is a string which denotes a D-Bus interface, and MEMBER,
+also a string, is either a method or a signal INTERFACE is offering.
+All arguments but BUS can be nil, which means a wild card then.
The value in the hash table a the function to be called when a D-Bus
message, which matches the key criteria, arrives. */);