comparison src/dbusbind.c @ 99098:35372c2ca5c9

* dbusbind.c (xd_in_read_queued_messages): New variable. (XD_SIGNAL1, XD_SIGNAL2, XD_SIGNAL3): New macros. Throw Qdbus_error. (xd_read_queued_messages): Catch Qdbus_error from the macros. (all): Replace xsignal1, xsignal2, xsignal3 by the respective macro. (Bug#1186).
author Michael Albinus <michael.albinus@gmx.de>
date Fri, 24 Oct 2008 04:19:40 +0000
parents f98d4eaeba07
children e038c1a8307c
comparison
equal deleted inserted replaced
99097:8f4ff9c9a49c 99098:35372c2ca5c9
61 Lisp_Object Vdbus_registered_functions_table; 61 Lisp_Object Vdbus_registered_functions_table;
62 62
63 /* Whether to debug D-Bus. */ 63 /* Whether to debug D-Bus. */
64 Lisp_Object Vdbus_debug; 64 Lisp_Object Vdbus_debug;
65 65
66 /* Whether we are reading a D-Bus event. */
67 int xd_in_read_queued_messages = 0;
68
66 69
67 /* We use "xd_" and "XD_" as prefix for all internal symbols, because 70 /* We use "xd_" and "XD_" as prefix for all internal symbols, because
68 we don't want to poison other namespaces with "dbus_". */ 71 we don't want to poison other namespaces with "dbus_". */
72
73 /* Raise a signal. If we are reading events, we cannot signal; we
74 throw to xd_read_queued_messages then. */
75 #define XD_SIGNAL1(arg) \
76 do { \
77 if (xd_in_read_queued_messages) \
78 Fthrow (Qdbus_error, Qnil); \
79 else \
80 xsignal1 (Qdbus_error, arg); \
81 } while (0)
82
83 #define XD_SIGNAL2(arg1, arg2) \
84 do { \
85 if (xd_in_read_queued_messages) \
86 Fthrow (Qdbus_error, Qnil); \
87 else \
88 xsignal2 (Qdbus_error, arg1, arg2); \
89 } while (0)
90
91 #define XD_SIGNAL3(arg1, arg2, arg3) \
92 do { \
93 if (xd_in_read_queued_messages) \
94 Fthrow (Qdbus_error, Qnil); \
95 else \
96 xsignal3 (Qdbus_error, arg1, arg2, arg3); \
97 } while (0)
69 98
70 /* Raise a Lisp error from a D-Bus ERROR. */ 99 /* Raise a Lisp error from a D-Bus ERROR. */
71 #define XD_ERROR(error) \ 100 #define XD_ERROR(error) \
72 do { \ 101 do { \
73 char s[1024]; \ 102 char s[1024]; \
74 strncpy (s, error.message, 1023); \ 103 strncpy (s, error.message, 1023); \
75 dbus_error_free (&error); \ 104 dbus_error_free (&error); \
76 /* Remove the trailing newline. */ \ 105 /* Remove the trailing newline. */ \
77 if (strchr (s, '\n') != NULL) \ 106 if (strchr (s, '\n') != NULL) \
78 s[strlen (s) - 1] = '\0'; \ 107 s[strlen (s) - 1] = '\0'; \
79 xsignal1 (Qdbus_error, build_string (s)); \ 108 XD_SIGNAL1 (build_string (s)); \
80 } while (0) 109 } while (0)
81 110
82 /* Macros for debugging. In order to enable them, build with 111 /* Macros for debugging. In order to enable them, build with
83 "make MYCPPFLAGS='-DDBUS_DEBUG -Wall'". */ 112 "make MYCPPFLAGS='-DDBUS_DEBUG -Wall'". */
84 #ifdef DBUS_DEBUG 113 #ifdef DBUS_DEBUG
92 #define XD_DEBUG_VALID_LISP_OBJECT_P(object) \ 121 #define XD_DEBUG_VALID_LISP_OBJECT_P(object) \
93 do { \ 122 do { \
94 if (!valid_lisp_object_p (object)) \ 123 if (!valid_lisp_object_p (object)) \
95 { \ 124 { \
96 XD_DEBUG_MESSAGE ("%d Assertion failure", __LINE__); \ 125 XD_DEBUG_MESSAGE ("%d Assertion failure", __LINE__); \
97 xsignal1 (Qdbus_error, build_string ("Assertion failure")); \ 126 XD_SIGNAL1 (build_string ("Assertion failure")); \
98 } \ 127 } \
99 } while (0) 128 } while (0)
100 129
101 #else /* !DBUS_DEBUG */ 130 #else /* !DBUS_DEBUG */
102 #define XD_DEBUG_MESSAGE(...) \ 131 #define XD_DEBUG_MESSAGE(...) \
368 case DBUS_TYPE_BYTE: 397 case DBUS_TYPE_BYTE:
369 { 398 {
370 unsigned char val = XUINT (object) & 0xFF; 399 unsigned char val = XUINT (object) & 0xFF;
371 XD_DEBUG_MESSAGE ("%c %d", dtype, val); 400 XD_DEBUG_MESSAGE ("%c %d", dtype, val);
372 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 401 if (!dbus_message_iter_append_basic (iter, dtype, &val))
373 xsignal2 (Qdbus_error, 402 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
374 build_string ("Unable to append argument"), object);
375 return; 403 return;
376 } 404 }
377 405
378 case DBUS_TYPE_BOOLEAN: 406 case DBUS_TYPE_BOOLEAN:
379 { 407 {
380 dbus_bool_t val = (NILP (object)) ? FALSE : TRUE; 408 dbus_bool_t val = (NILP (object)) ? FALSE : TRUE;
381 XD_DEBUG_MESSAGE ("%c %s", dtype, (val == FALSE) ? "false" : "true"); 409 XD_DEBUG_MESSAGE ("%c %s", dtype, (val == FALSE) ? "false" : "true");
382 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 410 if (!dbus_message_iter_append_basic (iter, dtype, &val))
383 xsignal2 (Qdbus_error, 411 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
384 build_string ("Unable to append argument"), object);
385 return; 412 return;
386 } 413 }
387 414
388 case DBUS_TYPE_INT16: 415 case DBUS_TYPE_INT16:
389 { 416 {
390 dbus_int16_t val = XINT (object); 417 dbus_int16_t val = XINT (object);
391 XD_DEBUG_MESSAGE ("%c %d", dtype, (int) val); 418 XD_DEBUG_MESSAGE ("%c %d", dtype, (int) val);
392 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 419 if (!dbus_message_iter_append_basic (iter, dtype, &val))
393 xsignal2 (Qdbus_error, 420 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
394 build_string ("Unable to append argument"), object);
395 return; 421 return;
396 } 422 }
397 423
398 case DBUS_TYPE_UINT16: 424 case DBUS_TYPE_UINT16:
399 { 425 {
400 dbus_uint16_t val = XUINT (object); 426 dbus_uint16_t val = XUINT (object);
401 XD_DEBUG_MESSAGE ("%c %u", dtype, (unsigned int) val); 427 XD_DEBUG_MESSAGE ("%c %u", dtype, (unsigned int) val);
402 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 428 if (!dbus_message_iter_append_basic (iter, dtype, &val))
403 xsignal2 (Qdbus_error, 429 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
404 build_string ("Unable to append argument"), object);
405 return; 430 return;
406 } 431 }
407 432
408 case DBUS_TYPE_INT32: 433 case DBUS_TYPE_INT32:
409 { 434 {
410 dbus_int32_t val = XINT (object); 435 dbus_int32_t val = XINT (object);
411 XD_DEBUG_MESSAGE ("%c %d", dtype, val); 436 XD_DEBUG_MESSAGE ("%c %d", dtype, val);
412 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 437 if (!dbus_message_iter_append_basic (iter, dtype, &val))
413 xsignal2 (Qdbus_error, 438 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
414 build_string ("Unable to append argument"), object);
415 return; 439 return;
416 } 440 }
417 441
418 case DBUS_TYPE_UINT32: 442 case DBUS_TYPE_UINT32:
419 { 443 {
420 dbus_uint32_t val = XUINT (object); 444 dbus_uint32_t val = XUINT (object);
421 XD_DEBUG_MESSAGE ("%c %u", dtype, val); 445 XD_DEBUG_MESSAGE ("%c %u", dtype, val);
422 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 446 if (!dbus_message_iter_append_basic (iter, dtype, &val))
423 xsignal2 (Qdbus_error, 447 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
424 build_string ("Unable to append argument"), object);
425 return; 448 return;
426 } 449 }
427 450
428 case DBUS_TYPE_INT64: 451 case DBUS_TYPE_INT64:
429 { 452 {
430 dbus_int64_t val = XINT (object); 453 dbus_int64_t val = XINT (object);
431 XD_DEBUG_MESSAGE ("%c %d", dtype, (int) val); 454 XD_DEBUG_MESSAGE ("%c %d", dtype, (int) val);
432 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 455 if (!dbus_message_iter_append_basic (iter, dtype, &val))
433 xsignal2 (Qdbus_error, 456 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
434 build_string ("Unable to append argument"), object);
435 return; 457 return;
436 } 458 }
437 459
438 case DBUS_TYPE_UINT64: 460 case DBUS_TYPE_UINT64:
439 { 461 {
440 dbus_uint64_t val = XUINT (object); 462 dbus_uint64_t val = XUINT (object);
441 XD_DEBUG_MESSAGE ("%c %u", dtype, (unsigned int) val); 463 XD_DEBUG_MESSAGE ("%c %u", dtype, (unsigned int) val);
442 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 464 if (!dbus_message_iter_append_basic (iter, dtype, &val))
443 xsignal2 (Qdbus_error, 465 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
444 build_string ("Unable to append argument"), object);
445 return; 466 return;
446 } 467 }
447 468
448 case DBUS_TYPE_DOUBLE: 469 case DBUS_TYPE_DOUBLE:
449 XD_DEBUG_MESSAGE ("%c %f", dtype, XFLOAT_DATA (object)); 470 XD_DEBUG_MESSAGE ("%c %f", dtype, XFLOAT_DATA (object));
450 if (!dbus_message_iter_append_basic (iter, dtype, 471 if (!dbus_message_iter_append_basic (iter, dtype,
451 &XFLOAT_DATA (object))) 472 &XFLOAT_DATA (object)))
452 xsignal2 (Qdbus_error, 473 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
453 build_string ("Unable to append argument"), object);
454 return; 474 return;
455 475
456 case DBUS_TYPE_STRING: 476 case DBUS_TYPE_STRING:
457 case DBUS_TYPE_OBJECT_PATH: 477 case DBUS_TYPE_OBJECT_PATH:
458 case DBUS_TYPE_SIGNATURE: 478 case DBUS_TYPE_SIGNATURE:
459 { 479 {
460 char *val = SDATA (Fstring_make_unibyte (object)); 480 char *val = SDATA (Fstring_make_unibyte (object));
461 XD_DEBUG_MESSAGE ("%c %s", dtype, val); 481 XD_DEBUG_MESSAGE ("%c %s", dtype, val);
462 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 482 if (!dbus_message_iter_append_basic (iter, dtype, &val))
463 xsignal2 (Qdbus_error, 483 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
464 build_string ("Unable to append argument"), object);
465 return; 484 return;
466 } 485 }
467 } 486 }
468 487
469 else /* Compound types. */ 488 else /* Compound types. */
507 526
508 XD_DEBUG_MESSAGE ("%c %s %s", dtype, signature, 527 XD_DEBUG_MESSAGE ("%c %s %s", dtype, signature,
509 SDATA (format2 ("%s", object, Qnil))); 528 SDATA (format2 ("%s", object, Qnil)));
510 if (!dbus_message_iter_open_container (iter, dtype, 529 if (!dbus_message_iter_open_container (iter, dtype,
511 signature, &subiter)) 530 signature, &subiter))
512 xsignal3 (Qdbus_error, 531 XD_SIGNAL3 (build_string ("Cannot open container"),
513 build_string ("Cannot open container"), 532 make_number (dtype), build_string (signature));
514 make_number (dtype), build_string (signature));
515 break; 533 break;
516 534
517 case DBUS_TYPE_VARIANT: 535 case DBUS_TYPE_VARIANT:
518 /* A variant has just one element. */ 536 /* A variant has just one element. */
519 xd_signature (signature, XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (object)), 537 xd_signature (signature, XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (object)),
521 539
522 XD_DEBUG_MESSAGE ("%c %s %s", dtype, signature, 540 XD_DEBUG_MESSAGE ("%c %s %s", dtype, signature,
523 SDATA (format2 ("%s", object, Qnil))); 541 SDATA (format2 ("%s", object, Qnil)));
524 if (!dbus_message_iter_open_container (iter, dtype, 542 if (!dbus_message_iter_open_container (iter, dtype,
525 signature, &subiter)) 543 signature, &subiter))
526 xsignal3 (Qdbus_error, 544 XD_SIGNAL3 (build_string ("Cannot open container"),
527 build_string ("Cannot open container"), 545 make_number (dtype), build_string (signature));
528 make_number (dtype), build_string (signature));
529 break; 546 break;
530 547
531 case DBUS_TYPE_STRUCT: 548 case DBUS_TYPE_STRUCT:
532 case DBUS_TYPE_DICT_ENTRY: 549 case DBUS_TYPE_DICT_ENTRY:
533 /* These containers do not require a signature. */ 550 /* These containers do not require a signature. */
534 XD_DEBUG_MESSAGE ("%c %s", dtype, 551 XD_DEBUG_MESSAGE ("%c %s", dtype,
535 SDATA (format2 ("%s", object, Qnil))); 552 SDATA (format2 ("%s", object, Qnil)));
536 if (!dbus_message_iter_open_container (iter, dtype, NULL, &subiter)) 553 if (!dbus_message_iter_open_container (iter, dtype, NULL, &subiter))
537 xsignal2 (Qdbus_error, 554 XD_SIGNAL2 (build_string ("Cannot open container"),
538 build_string ("Cannot open container"), 555 make_number (dtype));
539 make_number (dtype));
540 break; 556 break;
541 } 557 }
542 558
543 /* Loop over list elements. */ 559 /* Loop over list elements. */
544 while (!NILP (object)) 560 while (!NILP (object))
551 object = CDR_SAFE (object); 567 object = CDR_SAFE (object);
552 } 568 }
553 569
554 /* Close the subiteration. */ 570 /* Close the subiteration. */
555 if (!dbus_message_iter_close_container (iter, &subiter)) 571 if (!dbus_message_iter_close_container (iter, &subiter))
556 xsignal2 (Qdbus_error, 572 XD_SIGNAL2 (build_string ("Cannot close container"),
557 build_string ("Cannot close container"), 573 make_number (dtype));
558 make_number (dtype));
559 } 574 }
560 } 575 }
561 576
562 /* Retrieve C value from a DBusMessageIter structure ITER, and return 577 /* Retrieve C value from a DBusMessageIter structure ITER, and return
563 a converted Lisp object. The type DTYPE of the argument of the 578 a converted Lisp object. The type DTYPE of the argument of the
675 DBusError derror; 690 DBusError derror;
676 691
677 /* Parameter check. */ 692 /* Parameter check. */
678 CHECK_SYMBOL (bus); 693 CHECK_SYMBOL (bus);
679 if (!((EQ (bus, QCdbus_system_bus)) || (EQ (bus, QCdbus_session_bus)))) 694 if (!((EQ (bus, QCdbus_system_bus)) || (EQ (bus, QCdbus_session_bus))))
680 xsignal2 (Qdbus_error, build_string ("Wrong bus name"), bus); 695 XD_SIGNAL2 (build_string ("Wrong bus name"), bus);
681 696
682 /* Open a connection to the bus. */ 697 /* Open a connection to the bus. */
683 dbus_error_init (&derror); 698 dbus_error_init (&derror);
684 699
685 if (EQ (bus, QCdbus_system_bus)) 700 if (EQ (bus, QCdbus_system_bus))
689 704
690 if (dbus_error_is_set (&derror)) 705 if (dbus_error_is_set (&derror))
691 XD_ERROR (derror); 706 XD_ERROR (derror);
692 707
693 if (connection == NULL) 708 if (connection == NULL)
694 xsignal2 (Qdbus_error, build_string ("No connection"), bus); 709 XD_SIGNAL2 (build_string ("No connection"), bus);
695 710
696 /* Return the result. */ 711 /* Return the result. */
697 return connection; 712 return connection;
698 } 713 }
699 714
713 connection = xd_initialize (bus); 728 connection = xd_initialize (bus);
714 729
715 /* Request the name. */ 730 /* Request the name. */
716 name = dbus_bus_get_unique_name (connection); 731 name = dbus_bus_get_unique_name (connection);
717 if (name == NULL) 732 if (name == NULL)
718 xsignal1 (Qdbus_error, build_string ("No unique name available")); 733 XD_SIGNAL1 (build_string ("No unique name available"));
719 734
720 /* Return. */ 735 /* Return. */
721 return build_string (name); 736 return build_string (name);
722 } 737 }
723 738
834 SDATA (path), 849 SDATA (path),
835 SDATA (interface), 850 SDATA (interface),
836 SDATA (method)); 851 SDATA (method));
837 UNGCPRO; 852 UNGCPRO;
838 if (dmessage == NULL) 853 if (dmessage == NULL)
839 xsignal1 (Qdbus_error, build_string ("Unable to create a new message")); 854 XD_SIGNAL1 (build_string ("Unable to create a new message"));
840 855
841 /* Check for timeout parameter. */ 856 /* Check for timeout parameter. */
842 if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout))) 857 if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout)))
843 { 858 {
844 CHECK_NATNUM (args[i+1]); 859 CHECK_NATNUM (args[i+1]);
885 900
886 if (dbus_error_is_set (&derror)) 901 if (dbus_error_is_set (&derror))
887 XD_ERROR (derror); 902 XD_ERROR (derror);
888 903
889 if (reply == NULL) 904 if (reply == NULL)
890 xsignal1 (Qdbus_error, build_string ("No reply")); 905 XD_SIGNAL1 (build_string ("No reply"));
891 906
892 XD_DEBUG_MESSAGE ("Message sent"); 907 XD_DEBUG_MESSAGE ("Message sent");
893 908
894 /* Collect the results. */ 909 /* Collect the results. */
895 result = Qnil; 910 result = Qnil;
1016 dmessage = dbus_message_new_method_call (SDATA (service), 1031 dmessage = dbus_message_new_method_call (SDATA (service),
1017 SDATA (path), 1032 SDATA (path),
1018 SDATA (interface), 1033 SDATA (interface),
1019 SDATA (method)); 1034 SDATA (method));
1020 if (dmessage == NULL) 1035 if (dmessage == NULL)
1021 xsignal1 (Qdbus_error, build_string ("Unable to create a new message")); 1036 XD_SIGNAL1 (build_string ("Unable to create a new message"));
1022 1037
1023 /* Check for timeout parameter. */ 1038 /* Check for timeout parameter. */
1024 if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout))) 1039 if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout)))
1025 { 1040 {
1026 CHECK_NATNUM (args[i+1]); 1041 CHECK_NATNUM (args[i+1]);
1059 } 1074 }
1060 1075
1061 /* Send the message. The message is just added to the outgoing 1076 /* Send the message. The message is just added to the outgoing
1062 message queue. */ 1077 message queue. */
1063 if (!dbus_connection_send_with_reply (connection, dmessage, NULL, timeout)) 1078 if (!dbus_connection_send_with_reply (connection, dmessage, NULL, timeout))
1064 xsignal1 (Qdbus_error, build_string ("Cannot send message")); 1079 XD_SIGNAL1 (build_string ("Cannot send message"));
1065 1080
1066 XD_DEBUG_MESSAGE ("Message sent"); 1081 XD_DEBUG_MESSAGE ("Message sent");
1067 1082
1068 /* The result is the key in Vdbus_registered_functions_table. */ 1083 /* The result is the key in Vdbus_registered_functions_table. */
1069 result = (list2 (bus, make_number (dbus_message_get_serial (dmessage)))); 1084 result = (list2 (bus, make_number (dbus_message_get_serial (dmessage))));
1118 if ((dmessage == NULL) 1133 if ((dmessage == NULL)
1119 || (!dbus_message_set_reply_serial (dmessage, XUINT (serial))) 1134 || (!dbus_message_set_reply_serial (dmessage, XUINT (serial)))
1120 || (!dbus_message_set_destination (dmessage, SDATA (service)))) 1135 || (!dbus_message_set_destination (dmessage, SDATA (service))))
1121 { 1136 {
1122 UNGCPRO; 1137 UNGCPRO;
1123 xsignal1 (Qdbus_error, 1138 XD_SIGNAL1 (build_string ("Unable to create a return message"));
1124 build_string ("Unable to create a return message"));
1125 } 1139 }
1126 1140
1127 UNGCPRO; 1141 UNGCPRO;
1128 1142
1129 /* Initialize parameter list of message. */ 1143 /* Initialize parameter list of message. */
1157 } 1171 }
1158 1172
1159 /* Send the message. The message is just added to the outgoing 1173 /* Send the message. The message is just added to the outgoing
1160 message queue. */ 1174 message queue. */
1161 if (!dbus_connection_send (connection, dmessage, NULL)) 1175 if (!dbus_connection_send (connection, dmessage, NULL))
1162 xsignal1 (Qdbus_error, build_string ("Cannot send message")); 1176 XD_SIGNAL1 (build_string ("Cannot send message"));
1163 1177
1164 /* Flush connection to ensure the message is handled. */ 1178 /* Flush connection to ensure the message is handled. */
1165 dbus_connection_flush (connection); 1179 dbus_connection_flush (connection);
1166 1180
1167 XD_DEBUG_MESSAGE ("Message sent"); 1181 XD_DEBUG_MESSAGE ("Message sent");
1214 || (!dbus_message_set_error_name (dmessage, DBUS_ERROR_FAILED)) 1228 || (!dbus_message_set_error_name (dmessage, DBUS_ERROR_FAILED))
1215 || (!dbus_message_set_reply_serial (dmessage, XUINT (serial))) 1229 || (!dbus_message_set_reply_serial (dmessage, XUINT (serial)))
1216 || (!dbus_message_set_destination (dmessage, SDATA (service)))) 1230 || (!dbus_message_set_destination (dmessage, SDATA (service))))
1217 { 1231 {
1218 UNGCPRO; 1232 UNGCPRO;
1219 xsignal1 (Qdbus_error, 1233 XD_SIGNAL1 (build_string ("Unable to create a error message"));
1220 build_string ("Unable to create a error message"));
1221 } 1234 }
1222 1235
1223 UNGCPRO; 1236 UNGCPRO;
1224 1237
1225 /* Initialize parameter list of message. */ 1238 /* Initialize parameter list of message. */
1253 } 1266 }
1254 1267
1255 /* Send the message. The message is just added to the outgoing 1268 /* Send the message. The message is just added to the outgoing
1256 message queue. */ 1269 message queue. */
1257 if (!dbus_connection_send (connection, dmessage, NULL)) 1270 if (!dbus_connection_send (connection, dmessage, NULL))
1258 xsignal1 (Qdbus_error, build_string ("Cannot send message")); 1271 XD_SIGNAL1 (build_string ("Cannot send message"));
1259 1272
1260 /* Flush connection to ensure the message is handled. */ 1273 /* Flush connection to ensure the message is handled. */
1261 dbus_connection_flush (connection); 1274 dbus_connection_flush (connection);
1262 1275
1263 XD_DEBUG_MESSAGE ("Message sent"); 1276 XD_DEBUG_MESSAGE ("Message sent");
1338 dmessage = dbus_message_new_signal (SDATA (path), 1351 dmessage = dbus_message_new_signal (SDATA (path),
1339 SDATA (interface), 1352 SDATA (interface),
1340 SDATA (signal)); 1353 SDATA (signal));
1341 UNGCPRO; 1354 UNGCPRO;
1342 if (dmessage == NULL) 1355 if (dmessage == NULL)
1343 xsignal1 (Qdbus_error, build_string ("Unable to create a new message")); 1356 XD_SIGNAL1 (build_string ("Unable to create a new message"));
1344 1357
1345 /* Initialize parameter list of message. */ 1358 /* Initialize parameter list of message. */
1346 dbus_message_iter_init_append (dmessage, &iter); 1359 dbus_message_iter_init_append (dmessage, &iter);
1347 1360
1348 /* Append parameters to the message. */ 1361 /* Append parameters to the message. */
1373 } 1386 }
1374 1387
1375 /* Send the message. The message is just added to the outgoing 1388 /* Send the message. The message is just added to the outgoing
1376 message queue. */ 1389 message queue. */
1377 if (!dbus_connection_send (connection, dmessage, NULL)) 1390 if (!dbus_connection_send (connection, dmessage, NULL))
1378 xsignal1 (Qdbus_error, build_string ("Cannot send message")); 1391 XD_SIGNAL1 (build_string ("Cannot send message"));
1379 1392
1380 /* Flush connection to ensure the message is handled. */ 1393 /* Flush connection to ensure the message is handled. */
1381 dbus_connection_flush (connection); 1394 dbus_connection_flush (connection);
1382 1395
1383 XD_DEBUG_MESSAGE ("Signal sent"); 1396 XD_DEBUG_MESSAGE ("Signal sent");
1555 table in dbus.el. When this package isn't loaded yet, it doesn't 1568 table in dbus.el. When this package isn't loaded yet, it doesn't
1556 make sense to handle D-Bus messages. Furthermore, we ignore all 1569 make sense to handle D-Bus messages. Furthermore, we ignore all
1557 Lisp errors during the call. */ 1570 Lisp errors during the call. */
1558 if (HASH_TABLE_P (Vdbus_registered_functions_table)) 1571 if (HASH_TABLE_P (Vdbus_registered_functions_table))
1559 { 1572 {
1560 internal_condition_case_1 (xd_read_message, QCdbus_system_bus, 1573 xd_in_read_queued_messages = 1;
1561 Qerror, Fidentity); 1574 internal_catch (Qdbus_error, xd_read_message, QCdbus_system_bus);
1562 internal_condition_case_1 (xd_read_message, QCdbus_session_bus, 1575 internal_catch (Qdbus_error, xd_read_message, QCdbus_session_bus);
1563 Qerror, Fidentity); 1576 xd_in_read_queued_messages = 0;
1564 } 1577 }
1565 } 1578 }
1566 1579
1567 DEFUN ("dbus-register-signal", Fdbus_register_signal, Sdbus_register_signal, 1580 DEFUN ("dbus-register-signal", Fdbus_register_signal, Sdbus_register_signal,
1568 6, MANY, 0, 1581 6, MANY, 0,