aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog12
-rw-r--r--src/dbusbind.c135
2 files changed, 85 insertions, 62 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index f55e4ac786c..962c95dbdf2 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,15 @@
12007-12-07 Michael Albinus <michael.albinus@gmx.de>
2
3 * dbusbind.c (Fdbus_get_unique_name, xd_read_message)
4 (Fdbus_register_signal): Use DBUS_MAXIMUM_NAME_LENGTH and
5 DBUS_MAXIMUM_MATCH_RULE_LENGTH for string lengths.
6 (Fdbus_call_method, Fdbus_send_signal, Fdbus_register_signal):
7 Unify argument lists.
8 (xd_read_message, Fdbus_register_signal) Reorder and extend event
9 arguments and hash table keys. Use unique name for service.
10 (Fdbus_unregister_signal): Remove checks.
11 (Vdbus_registered_functions_table): Fix doc string.
12
12007-12-05 Magnus Henoch <mange@freemail.hu> 132007-12-05 Magnus Henoch <mange@freemail.hu>
2 14
3 * process.c (make_process): Initialize pty_flag to 0. 15 * process.c (make_process): Initialize pty_flag to 0.
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,
241 Lisp_Object bus; 241 Lisp_Object bus;
242{ 242{
243 DBusConnection *connection; 243 DBusConnection *connection;
244 char name[1024]; 244 char name[DBUS_MAXIMUM_NAME_LENGTH];
245 245
246 /* Check parameters. */ 246 /* Check parameters. */
247 CHECK_SYMBOL (bus); 247 CHECK_SYMBOL (bus);
@@ -287,8 +287,8 @@ are converted into a list of Lisp objects which correspond to the
287elements of the D-Bus container. Example: 287elements of the D-Bus container. Example:
288 288
289\(dbus-call-method 289\(dbus-call-method
290 :session "GetKeyField" "org.gnome.seahorse" 290 :session "org.gnome.seahorse" "/org/gnome/seahorse/keys/openpgp"
291 "/org/gnome/seahorse/keys/openpgp" "org.gnome.seahorse.Keys" 291 "org.gnome.seahorse.Keys" "GetKeyField"
292 "openpgp:657984B8C7A966DD" "simple-name") 292 "openpgp:657984B8C7A966DD" "simple-name")
293 293
294 => (t ("Philip R. Zimmermann")) 294 => (t ("Philip R. Zimmermann"))
@@ -297,18 +297,18 @@ If the result of the METHOD call is just one value, the converted Lisp
297object is returned instead of a list containing this single Lisp object. 297object is returned instead of a list containing this single Lisp object.
298 298
299\(dbus-call-method 299\(dbus-call-method
300 :system "GetPropertyString" "org.freedesktop.Hal" 300 :system "org.freedesktop.Hal" "/org/freedesktop/Hal/devices/computer"
301 "/org/freedesktop/Hal/devices/computer" "org.freedesktop.Hal.Device" 301 "org.freedesktop.Hal.Device" "GetPropertyString"
302 "system.kernel.machine") 302 "system.kernel.machine")
303 303
304 => "i686" 304 => "i686"
305 305
306usage: (dbus-call-method BUS METHOD SERVICE PATH INTERFACE &rest ARGS) */) 306usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &rest ARGS) */)
307 (nargs, args) 307 (nargs, args)
308 int nargs; 308 int nargs;
309 register Lisp_Object *args; 309 register Lisp_Object *args;
310{ 310{
311 Lisp_Object bus, method, service, path, interface; 311 Lisp_Object bus, service, path, interface, method;
312 Lisp_Object result; 312 Lisp_Object result;
313 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 313 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
314 DBusConnection *connection; 314 DBusConnection *connection;
@@ -322,23 +322,23 @@ usage: (dbus-call-method BUS METHOD SERVICE PATH INTERFACE &rest ARGS) */)
322 322
323 /* Check parameters. */ 323 /* Check parameters. */
324 bus = args[0]; 324 bus = args[0];
325 method = args[1]; 325 service = args[1];
326 service = args[2]; 326 path = args[2];
327 path = args[3]; 327 interface = args[3];
328 interface = args[4]; 328 method = args[4];
329 329
330 CHECK_SYMBOL (bus); 330 CHECK_SYMBOL (bus);
331 CHECK_STRING (method);
332 CHECK_STRING (service); 331 CHECK_STRING (service);
333 CHECK_STRING (path); 332 CHECK_STRING (path);
334 CHECK_STRING (interface); 333 CHECK_STRING (interface);
335 GCPRO5 (bus, method, service, path, interface); 334 CHECK_STRING (method);
335 GCPRO5 (bus, service, path, interface, method);
336 336
337 XD_DEBUG_MESSAGE ("%s %s %s %s", 337 XD_DEBUG_MESSAGE ("%s %s %s %s",
338 SDATA (method),
339 SDATA (service), 338 SDATA (service),
340 SDATA (path), 339 SDATA (path),
341 SDATA (interface)); 340 SDATA (interface),
341 SDATA (method));
342 342
343 /* Open a connection to the bus. */ 343 /* Open a connection to the bus. */
344 connection = xd_initialize (bus); 344 connection = xd_initialize (bus);
@@ -447,14 +447,15 @@ Other Lisp objects are not supported as arguments of SIGNAL.
447Example: 447Example:
448 448
449\(dbus-send-signal 449\(dbus-send-signal
450 :session "Started" "org.gnu.emacs" "/org/gnu/emacs" "org.gnu.emacs"))) 450 :session "org.gnu.Emacs" "/org/gnu/Emacs"
451 "org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs")
451 452
452usage: (dbus-send-signal BUS SIGNAL SERVICE PATH INTERFACE &rest ARGS) */) 453usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */)
453 (nargs, args) 454 (nargs, args)
454 int nargs; 455 int nargs;
455 register Lisp_Object *args; 456 register Lisp_Object *args;
456{ 457{
457 Lisp_Object bus, signal, service, path, interface; 458 Lisp_Object bus, service, path, interface, signal;
458 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 459 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
459 DBusConnection *connection; 460 DBusConnection *connection;
460 DBusMessage *dmessage; 461 DBusMessage *dmessage;
@@ -464,23 +465,23 @@ usage: (dbus-send-signal BUS SIGNAL SERVICE PATH INTERFACE &rest ARGS) */)
464 465
465 /* Check parameters. */ 466 /* Check parameters. */
466 bus = args[0]; 467 bus = args[0];
467 signal = args[1]; 468 service = args[1];
468 service = args[2]; 469 path = args[2];
469 path = args[3]; 470 interface = args[3];
470 interface = args[4]; 471 signal = args[4];
471 472
472 CHECK_SYMBOL (bus); 473 CHECK_SYMBOL (bus);
473 CHECK_STRING (signal);
474 CHECK_STRING (service); 474 CHECK_STRING (service);
475 CHECK_STRING (path); 475 CHECK_STRING (path);
476 CHECK_STRING (interface); 476 CHECK_STRING (interface);
477 GCPRO5 (bus, signal, service, path, interface); 477 CHECK_STRING (signal);
478 GCPRO5 (bus, service, path, interface, signal);
478 479
479 XD_DEBUG_MESSAGE ("%s %s %s %s", 480 XD_DEBUG_MESSAGE ("%s %s %s %s",
480 SDATA (signal),
481 SDATA (service), 481 SDATA (service),
482 SDATA (path), 482 SDATA (path),
483 SDATA (interface)); 483 SDATA (interface),
484 SDATA (signal));
484 485
485 /* Open a connection to the bus. */ 486 /* Open a connection to the bus. */
486 connection = xd_initialize (bus); 487 connection = xd_initialize (bus);
@@ -549,7 +550,10 @@ xd_read_message (bus)
549 DBusMessage *dmessage; 550 DBusMessage *dmessage;
550 DBusMessageIter iter; 551 DBusMessageIter iter;
551 uint dtype; 552 uint dtype;
552 char service[1024], path[1024], interface[1024], member[1024]; 553 char service[DBUS_MAXIMUM_NAME_LENGTH];
554 char path[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; /* Unlimited in D-Bus spec. */
555 char interface[DBUS_MAXIMUM_NAME_LENGTH];
556 char member[DBUS_MAXIMUM_NAME_LENGTH];
553 557
554 /* Open a connection to the bus. */ 558 /* Open a connection to the bus. */
555 connection = xd_initialize (bus); 559 connection = xd_initialize (bus);
@@ -590,14 +594,23 @@ xd_read_message (bus)
590 /* The arguments are stored in reverse order. Reorder them. */ 594 /* The arguments are stored in reverse order. Reorder them. */
591 event.arg = Fnreverse (event.arg); 595 event.arg = Fnreverse (event.arg);
592 596
593 /* Read service, object path interface and member from the 597 /* Read service, object path, interface and member from the message.
594 message. */ 598 The service is always the unique name of the sending object. */
595 strcpy (service, dbus_message_get_sender (dmessage)); 599 strcpy (service, dbus_message_get_sender (dmessage));
596 strcpy (path, dbus_message_get_path (dmessage)); 600 strcpy (path, dbus_message_get_path (dmessage));
597 strcpy (interface, dbus_message_get_interface (dmessage)); 601 strcpy (interface, dbus_message_get_interface (dmessage));
598 strcpy (member, dbus_message_get_member (dmessage)); 602 strcpy (member, dbus_message_get_member (dmessage));
599 603
600 /* Add them to the event. */ 604 /* Add the registered function of the message. */
605 key = list5 (bus,
606 (service == NULL ? Qnil : build_string (service)),
607 (path == NULL ? Qnil : build_string (path)),
608 (interface == NULL ? Qnil : build_string (interface)),
609 (member == NULL ? Qnil : build_string (member)));
610 event.arg = Fcons (Fgethash (key, Vdbus_registered_functions_table, Qnil),
611 event.arg);
612
613 /* Add service, path, interface and member to the event. */
601 event.arg = Fcons ((member == NULL ? Qnil : build_string (member)), 614 event.arg = Fcons ((member == NULL ? Qnil : build_string (member)),
602 event.arg); 615 event.arg);
603 event.arg = Fcons ((interface == NULL ? Qnil : build_string (interface)), 616 event.arg = Fcons ((interface == NULL ? Qnil : build_string (interface)),
@@ -610,13 +623,6 @@ xd_read_message (bus)
610 /* Add the bus symbol to the event. */ 623 /* Add the bus symbol to the event. */
611 event.arg = Fcons (bus, event.arg); 624 event.arg = Fcons (bus, event.arg);
612 625
613 /* Add the registered function of the message. */
614 key = list3 (bus,
615 (interface == NULL ? Qnil : build_string (interface)),
616 (member == NULL ? Qnil : build_string (member)));
617 event.arg = Fcons (Fgethash (key, Vdbus_registered_functions_table, Qnil),
618 event.arg);
619
620 /* Store it into the input event queue. */ 626 /* Store it into the input event queue. */
621 kbd_buffer_store_event (&event); 627 kbd_buffer_store_event (&event);
622 628
@@ -666,31 +672,41 @@ SIGNAL and HANDLER must not be nil. Example:
666 (message "Device %s added" device)) 672 (message "Device %s added" device))
667 673
668\(dbus-register-signal 674\(dbus-register-signal
669 :system "DeviceAdded" 675 :system "org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
670 (dbus-get-name-owner :system "org.freedesktop.Hal") 676 "org.freedesktop.Hal.Manager" "DeviceAdded" 'my-signal-handler)
671 "/org/freedesktop/Hal/Manager" "org.freedesktop.Hal.Manager"
672 'my-signal-handler)
673 677
674 => (:system "org.freedesktop.Hal.Manager" "DeviceAdded") 678 => (:system ":1.3" "/org/freedesktop/Hal/Manager"
679 "org.freedesktop.Hal.Manager" "DeviceAdded")
675 680
676`dbus-register-signal' returns an object, which can be used in 681`dbus-register-signal' returns an object, which can be used in
677`dbus-unregister-signal' for removing the registration. */) 682`dbus-unregister-signal' for removing the registration. */)
678 (bus, signal, service, path, interface, handler) 683 (bus, service, path, interface, signal, handler)
679 Lisp_Object bus, signal, service, path, interface, handler; 684 Lisp_Object bus, service, path, interface, signal, handler;
680{ 685{
681 Lisp_Object key; 686 Lisp_Object unique_name, key;
682 DBusConnection *connection; 687 DBusConnection *connection;
683 char rule[1024]; 688 char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
684 DBusError derror; 689 DBusError derror;
685 690
686 /* Check parameters. */ 691 /* Check parameters. */
687 CHECK_SYMBOL (bus); 692 CHECK_SYMBOL (bus);
688 CHECK_STRING (signal);
689 if (!NILP (service)) CHECK_STRING (service); 693 if (!NILP (service)) CHECK_STRING (service);
690 if (!NILP (path)) CHECK_STRING (path); 694 if (!NILP (path)) CHECK_STRING (path);
691 CHECK_STRING (interface); 695 CHECK_STRING (interface);
696 CHECK_STRING (signal);
692 CHECK_SYMBOL (handler); 697 CHECK_SYMBOL (handler);
693 698
699 /* Retrieve unique name of service. If service is a known name, we
700 will register for the corresponding unique name, if any. Signals
701 are sent always with the unique name as sender. Note: the unique
702 name of "org.freedesktop.DBus" is that string itself. */
703 if ((!NILP (service)) &&
704 (strcmp (SDATA (service), DBUS_SERVICE_DBUS) != 0) &&
705 (strncmp (SDATA (service), ":", 1) != 0))
706 unique_name = call2 (intern ("dbus-get-name-owner"), bus, service);
707 else
708 unique_name = service;
709
694 /* Open a connection to the bus. */ 710 /* Open a connection to the bus. */
695 connection = xd_initialize (bus); 711 connection = xd_initialize (bus);
696 712
@@ -700,9 +716,9 @@ SIGNAL and HANDLER must not be nil. Example:
700 SDATA (interface), 716 SDATA (interface),
701 SDATA (signal)); 717 SDATA (signal));
702 718
703 /* Add service and path to the rule if they are non-nil. */ 719 /* Add unique name and path to the rule if they are non-nil. */
704 if (!NILP (service)) 720 if (!NILP (unique_name))
705 sprintf (rule, "%s,sender='%s'%", rule, SDATA (service)); 721 sprintf (rule, "%s,sender='%s'%", rule, SDATA (unique_name));
706 722
707 if (!NILP (path)) 723 if (!NILP (path))
708 sprintf (rule, "%s,path='%s'", rule, SDATA (path)); 724 sprintf (rule, "%s,path='%s'", rule, SDATA (path));
@@ -716,7 +732,7 @@ SIGNAL and HANDLER must not be nil. Example:
716 XD_DEBUG_MESSAGE ("Matching rule \"%s\" created", rule); 732 XD_DEBUG_MESSAGE ("Matching rule \"%s\" created", rule);
717 733
718 /* Create a hash table entry. */ 734 /* Create a hash table entry. */
719 key = list3 (bus, interface, signal); 735 key = list5 (bus, unique_name, path, interface, signal);
720 Fputhash (key, handler, Vdbus_registered_functions_table); 736 Fputhash (key, handler, Vdbus_registered_functions_table);
721 XD_DEBUG_MESSAGE ("\"%s\" registered with handler \"%s\"", 737 XD_DEBUG_MESSAGE ("\"%s\" registered with handler \"%s\"",
722 SDATA (format2 ("%s", key, Qnil)), 738 SDATA (format2 ("%s", key, Qnil)),
@@ -734,13 +750,6 @@ OBJECT must be the result of a preceding `dbus-register-signal' call. */)
734 Lisp_Object object; 750 Lisp_Object object;
735{ 751{
736 752
737 /* Check parameters. */
738 CHECK_SYMBOL (object);
739
740 XD_DEBUG_MESSAGE ("\"%s\" unregistered with handler \"%s\"",
741 SDATA (format2 ("%s", object, Qnil)),
742 SDATA (format2 ("%s", Fsymbol_function (object), Qnil)));
743
744 /* Unintern the signal symbol. */ 753 /* Unintern the signal symbol. */
745 Fremhash (object, Vdbus_registered_functions_table); 754 Fremhash (object, Vdbus_registered_functions_table);
746 755
@@ -788,10 +797,12 @@ syms_of_dbusbind ()
788 797
789 DEFVAR_LISP ("dbus-registered-functions-table", &Vdbus_registered_functions_table, 798 DEFVAR_LISP ("dbus-registered-functions-table", &Vdbus_registered_functions_table,
790 doc: /* Hash table of registered functions for D-Bus. 799 doc: /* Hash table of registered functions for D-Bus.
791The key in the hash table is the list (BUS INTERFACE MEMBER). BUS is 800The key in the hash table is the list (BUS SERVICE PATH MEMBER INTERFACE).
792either the symbol `:system' or the symbol `:session'. INTERFACE is a 801BUS is either the symbol `:system' or the symbol `:session'. SERVICE
793string which denotes a D-Bus interface, and MEMBER, also a string, is 802and PATH are the unique name and the object path of the sending object.
794either a method or a signal INTERFACE is offering. 803INTERFACE is a string which denotes a D-Bus interface, and MEMBER,
804also a string, is either a method or a signal INTERFACE is offering.
805All arguments but BUS can be nil, which means a wild card then.
795 806
796The value in the hash table a the function to be called when a D-Bus 807The value in the hash table a the function to be called when a D-Bus
797message, which matches the key criteria, arrives. */); 808message, which matches the key criteria, arrives. */);