diff options
| author | Michael Albinus | 2007-12-30 15:41:47 +0000 |
|---|---|---|
| committer | Michael Albinus | 2007-12-30 15:41:47 +0000 |
| commit | 17bc8f9494e3166211fad1c6c044b1a2e00dd0e7 (patch) | |
| tree | 4ef091ea770f2ae5ffb17f27d98ad057f77940a8 /src | |
| parent | dd6f28023d432785758b7e5ac12f0b1748fbdea7 (diff) | |
| download | emacs-17bc8f9494e3166211fad1c6c044b1a2e00dd0e7.tar.gz emacs-17bc8f9494e3166211fad1c6c044b1a2e00dd0e7.zip | |
* dbusbind.c: Fix several errors and compiler warnings. Reported
by Tom Tromey <tromey@redhat.com>
(XD_ERROR, XD_DEBUG_MESSAGE)
(XD_DEBUG_VALID_LISP_OBJECT_P): Wrap code with "do ... while (0)".
(xd_append_arg): Part for basic D-Bus types rewitten.
(xd_retrieve_arg): Split implementation of DBUS_TYPE_BYTE and
DBUS_TYPE_(U)INT16. Don't call XD_DEBUG_MESSAGE with "%f" if not
appropriate.
(xd_read_message): Return Qnil. Don't signal an error; it is not
useful during event reading.
(Fdbus_register_signal): Signal an error if the check for
FUNCTIONP fails.
(Fdbus_register_method): New function. The implementation is not
complete, the call of the function signals an error therefore.
(Fdbus_unregister_object): New function, renamed from
Fdbus_unregister_signal. The initial check signals an error, if
it the objct is not well formed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 20 | ||||
| -rw-r--r-- | src/dbusbind.c | 345 |
2 files changed, 249 insertions, 116 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index cc29a16b1d0..ea71350b2e6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,23 @@ | |||
| 1 | 2007-12-30 Michael Albinus <michael.albinus@gmx.de> | ||
| 2 | |||
| 3 | * dbusbind.c: Fix several errors and compiler warnings. Reported | ||
| 4 | by Tom Tromey <tromey@redhat.com> | ||
| 5 | (XD_ERROR, XD_DEBUG_MESSAGE) | ||
| 6 | (XD_DEBUG_VALID_LISP_OBJECT_P): Wrap code with "do ... while (0)". | ||
| 7 | (xd_append_arg): Part for basic D-Bus types rewitten. | ||
| 8 | (xd_retrieve_arg): Split implementation of DBUS_TYPE_BYTE and | ||
| 9 | DBUS_TYPE_(U)INT16. Don't call XD_DEBUG_MESSAGE with "%f" if not | ||
| 10 | appropriate. | ||
| 11 | (xd_read_message): Return Qnil. Don't signal an error; it is not | ||
| 12 | useful during event reading. | ||
| 13 | (Fdbus_register_signal): Signal an error if the check for | ||
| 14 | FUNCTIONP fails. | ||
| 15 | (Fdbus_register_method): New function. The implementation is not | ||
| 16 | complete, the call of the function signals an error therefore. | ||
| 17 | (Fdbus_unregister_object): New function, renamed from | ||
| 18 | Fdbus_unregister_signal. The initial check signals an error, if | ||
| 19 | it the objct is not well formed. | ||
| 20 | |||
| 1 | 2007-12-30 Richard Stallman <rms@gnu.org> | 21 | 2007-12-30 Richard Stallman <rms@gnu.org> |
| 2 | 22 | ||
| 3 | * textprop.c (get_char_property_and_overlay): | 23 | * textprop.c (get_char_property_and_overlay): |
diff --git a/src/dbusbind.c b/src/dbusbind.c index 88f2ccdb3eb..e4d7f5d95ed 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -35,7 +35,8 @@ Lisp_Object Qdbus_get_unique_name; | |||
| 35 | Lisp_Object Qdbus_call_method; | 35 | Lisp_Object Qdbus_call_method; |
| 36 | Lisp_Object Qdbus_send_signal; | 36 | Lisp_Object Qdbus_send_signal; |
| 37 | Lisp_Object Qdbus_register_signal; | 37 | Lisp_Object Qdbus_register_signal; |
| 38 | Lisp_Object Qdbus_unregister_signal; | 38 | Lisp_Object Qdbus_register_method; |
| 39 | Lisp_Object Qdbus_unregister_object; | ||
| 39 | 40 | ||
| 40 | /* D-Bus error symbol. */ | 41 | /* D-Bus error symbol. */ |
| 41 | Lisp_Object Qdbus_error; | 42 | Lisp_Object Qdbus_error; |
| @@ -65,7 +66,7 @@ Lisp_Object Vdbus_debug; | |||
| 65 | 66 | ||
| 66 | /* Raise a Lisp error from a D-Bus ERROR. */ | 67 | /* Raise a Lisp error from a D-Bus ERROR. */ |
| 67 | #define XD_ERROR(error) \ | 68 | #define XD_ERROR(error) \ |
| 68 | { \ | 69 | do { \ |
| 69 | char s[1024]; \ | 70 | char s[1024]; \ |
| 70 | strcpy (s, error.message); \ | 71 | strcpy (s, error.message); \ |
| 71 | dbus_error_free (&error); \ | 72 | dbus_error_free (&error); \ |
| @@ -73,33 +74,37 @@ Lisp_Object Vdbus_debug; | |||
| 73 | if (strchr (s, '\n') != NULL) \ | 74 | if (strchr (s, '\n') != NULL) \ |
| 74 | s[strlen (s) - 1] = '\0'; \ | 75 | s[strlen (s) - 1] = '\0'; \ |
| 75 | xsignal1 (Qdbus_error, build_string (s)); \ | 76 | xsignal1 (Qdbus_error, build_string (s)); \ |
| 76 | } | 77 | } while (0) |
| 77 | 78 | ||
| 78 | /* Macros for debugging. In order to enable them, build with | 79 | /* Macros for debugging. In order to enable them, build with |
| 79 | "make MYCPPFLAGS='-DDBUS_DEBUG'". */ | 80 | "make MYCPPFLAGS='-DDBUS_DEBUG -Wall'". */ |
| 80 | #ifdef DBUS_DEBUG | 81 | #ifdef DBUS_DEBUG |
| 81 | #define XD_DEBUG_MESSAGE(...) \ | 82 | #define XD_DEBUG_MESSAGE(...) \ |
| 82 | { \ | 83 | do { \ |
| 83 | char s[1024]; \ | 84 | char s[1024]; \ |
| 84 | sprintf (s, __VA_ARGS__); \ | 85 | sprintf (s, __VA_ARGS__); \ |
| 85 | printf ("%s: %s\n", __func__, s); \ | 86 | printf ("%s: %s\n", __func__, s); \ |
| 86 | message ("%s: %s", __func__, s); \ | 87 | message ("%s: %s", __func__, s); \ |
| 87 | } | 88 | } while (0) |
| 88 | #define XD_DEBUG_VALID_LISP_OBJECT_P(object) \ | 89 | #define XD_DEBUG_VALID_LISP_OBJECT_P(object) \ |
| 89 | if (!valid_lisp_object_p (object)) \ | 90 | do { \ |
| 90 | { \ | 91 | if (!valid_lisp_object_p (object)) \ |
| 91 | XD_DEBUG_MESSAGE ("%s Assertion failure", __LINE__); \ | 92 | { \ |
| 92 | xsignal1 (Qdbus_error, build_string ("Assertion failure")); \ | 93 | XD_DEBUG_MESSAGE ("%d Assertion failure", __LINE__); \ |
| 93 | } | 94 | xsignal1 (Qdbus_error, build_string ("Assertion failure")); \ |
| 95 | } \ | ||
| 96 | } while (0) | ||
| 94 | 97 | ||
| 95 | #else /* !DBUS_DEBUG */ | 98 | #else /* !DBUS_DEBUG */ |
| 96 | #define XD_DEBUG_MESSAGE(...) \ | 99 | #define XD_DEBUG_MESSAGE(...) \ |
| 97 | if (!NILP (Vdbus_debug)) \ | 100 | do { \ |
| 98 | { \ | 101 | if (!NILP (Vdbus_debug)) \ |
| 99 | char s[1024]; \ | 102 | { \ |
| 100 | sprintf (s, __VA_ARGS__); \ | 103 | char s[1024]; \ |
| 101 | message ("%s: %s", __func__, s); \ | 104 | sprintf (s, __VA_ARGS__); \ |
| 102 | } | 105 | message ("%s: %s", __func__, s); \ |
| 106 | } | ||
| 107 | } while (0) | ||
| 103 | #define XD_DEBUG_VALID_LISP_OBJECT_P(object) | 108 | #define XD_DEBUG_VALID_LISP_OBJECT_P(object) |
| 104 | #endif | 109 | #endif |
| 105 | 110 | ||
| @@ -328,75 +333,112 @@ xd_append_arg (dtype, object, iter) | |||
| 328 | Lisp_Object object; | 333 | Lisp_Object object; |
| 329 | DBusMessageIter *iter; | 334 | DBusMessageIter *iter; |
| 330 | { | 335 | { |
| 331 | Lisp_Object elt; | ||
| 332 | char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; | 336 | char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; |
| 333 | DBusMessageIter subiter; | 337 | DBusMessageIter subiter; |
| 334 | char *value; | ||
| 335 | |||
| 336 | XD_DEBUG_MESSAGE ("%c %s", dtype, SDATA (format2 ("%s", object, Qnil))); | ||
| 337 | 338 | ||
| 338 | if (XD_BASIC_DBUS_TYPE (dtype)) | 339 | if (XD_BASIC_DBUS_TYPE (dtype)) |
| 339 | { | 340 | switch (dtype) |
| 340 | switch (dtype) | 341 | { |
| 342 | case DBUS_TYPE_BYTE: | ||
| 341 | { | 343 | { |
| 342 | case DBUS_TYPE_BYTE: | 344 | unsigned int val = XUINT (object) & 0xFF; |
| 343 | XD_DEBUG_MESSAGE ("%c %u", dtype, XUINT (object)); | 345 | XD_DEBUG_MESSAGE ("%c %d", dtype, val); |
| 344 | value = (unsigned char *) XUINT (object); | 346 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) |
| 345 | break; | 347 | xsignal2 (Qdbus_error, |
| 346 | 348 | build_string ("Unable to append argument"), object); | |
| 347 | case DBUS_TYPE_BOOLEAN: | 349 | return; |
| 348 | XD_DEBUG_MESSAGE ("%c %s", dtype, (NILP (object)) ? "false" : "true"); | 350 | } |
| 349 | value = (NILP (object)) | ||
| 350 | ? (unsigned char *) FALSE : (unsigned char *) TRUE; | ||
| 351 | break; | ||
| 352 | |||
| 353 | case DBUS_TYPE_INT16: | ||
| 354 | XD_DEBUG_MESSAGE ("%c %d", dtype, XINT (object)); | ||
| 355 | value = (char *) (dbus_int16_t *) XINT (object); | ||
| 356 | break; | ||
| 357 | 351 | ||
| 358 | case DBUS_TYPE_UINT16: | 352 | case DBUS_TYPE_BOOLEAN: |
| 359 | XD_DEBUG_MESSAGE ("%c %u", dtype, XUINT (object)); | 353 | { |
| 360 | value = (char *) (dbus_uint16_t *) XUINT (object); | 354 | dbus_bool_t val = (NILP (object)) ? FALSE : TRUE; |
| 361 | break; | 355 | XD_DEBUG_MESSAGE ("%c %s", dtype, (val == FALSE) ? "false" : "true"); |
| 356 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | ||
| 357 | xsignal2 (Qdbus_error, | ||
| 358 | build_string ("Unable to append argument"), object); | ||
| 359 | return; | ||
| 360 | } | ||
| 362 | 361 | ||
| 363 | case DBUS_TYPE_INT32: | 362 | case DBUS_TYPE_INT16: |
| 364 | XD_DEBUG_MESSAGE ("%c %d", dtype, XINT (object)); | 363 | { |
| 365 | value = (char *) (dbus_int32_t *) XINT (object); | 364 | dbus_int16_t val = XINT (object); |
| 366 | break; | 365 | XD_DEBUG_MESSAGE ("%c %d", dtype, (int) val); |
| 366 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | ||
| 367 | xsignal2 (Qdbus_error, | ||
| 368 | build_string ("Unable to append argument"), object); | ||
| 369 | return; | ||
| 370 | } | ||
| 367 | 371 | ||
| 368 | case DBUS_TYPE_UINT32: | 372 | case DBUS_TYPE_UINT16: |
| 369 | XD_DEBUG_MESSAGE ("%c %u", dtype, XUINT (object)); | 373 | { |
| 370 | value = (char *) (dbus_uint32_t *) XUINT (object); | 374 | dbus_uint16_t val = XUINT (object); |
| 371 | break; | 375 | XD_DEBUG_MESSAGE ("%c %u", dtype, (unsigned int) val); |
| 376 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | ||
| 377 | xsignal2 (Qdbus_error, | ||
| 378 | build_string ("Unable to append argument"), object); | ||
| 379 | return; | ||
| 380 | } | ||
| 372 | 381 | ||
| 373 | case DBUS_TYPE_INT64: | 382 | case DBUS_TYPE_INT32: |
| 374 | XD_DEBUG_MESSAGE ("%c %d", dtype, XINT (object)); | 383 | { |
| 375 | value = (char *) (dbus_int64_t *) XINT (object); | 384 | dbus_int32_t val = XINT (object); |
| 376 | break; | 385 | XD_DEBUG_MESSAGE ("%c %d", dtype, val); |
| 386 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | ||
| 387 | xsignal2 (Qdbus_error, | ||
| 388 | build_string ("Unable to append argument"), object); | ||
| 389 | return; | ||
| 390 | } | ||
| 377 | 391 | ||
| 378 | case DBUS_TYPE_UINT64: | 392 | case DBUS_TYPE_UINT32: |
| 379 | XD_DEBUG_MESSAGE ("%c %u", dtype, XUINT (object)); | 393 | { |
| 380 | value = (char *) (dbus_int64_t *) XUINT (object); | 394 | dbus_uint32_t val = XUINT (object); |
| 381 | break; | 395 | XD_DEBUG_MESSAGE ("%c %u", dtype, val); |
| 396 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | ||
| 397 | xsignal2 (Qdbus_error, | ||
| 398 | build_string ("Unable to append argument"), object); | ||
| 399 | return; | ||
| 400 | } | ||
| 382 | 401 | ||
| 383 | case DBUS_TYPE_DOUBLE: | 402 | case DBUS_TYPE_INT64: |
| 384 | XD_DEBUG_MESSAGE ("%c %f", dtype, XFLOAT (object)); | 403 | { |
| 385 | value = (char *) (float *) XFLOAT (object); | 404 | dbus_int64_t val = XINT (object); |
| 386 | break; | 405 | XD_DEBUG_MESSAGE ("%c %d", dtype, (int) val); |
| 406 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | ||
| 407 | xsignal2 (Qdbus_error, | ||
| 408 | build_string ("Unable to append argument"), object); | ||
| 409 | return; | ||
| 410 | } | ||
| 387 | 411 | ||
| 388 | case DBUS_TYPE_STRING: | 412 | case DBUS_TYPE_UINT64: |
| 389 | case DBUS_TYPE_OBJECT_PATH: | 413 | { |
| 390 | case DBUS_TYPE_SIGNATURE: | 414 | dbus_uint64_t val = XUINT (object); |
| 391 | XD_DEBUG_MESSAGE ("%c %s", dtype, SDATA (object)); | 415 | XD_DEBUG_MESSAGE ("%c %u", dtype, (unsigned int) val); |
| 392 | value = SDATA (object); | 416 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) |
| 393 | break; | 417 | xsignal2 (Qdbus_error, |
| 418 | build_string ("Unable to append argument"), object); | ||
| 419 | return; | ||
| 394 | } | 420 | } |
| 395 | 421 | ||
| 396 | if (!dbus_message_iter_append_basic (iter, dtype, &value)) | 422 | case DBUS_TYPE_DOUBLE: |
| 397 | xsignal2 (Qdbus_error, | 423 | XD_DEBUG_MESSAGE ("%c %f", dtype, XFLOAT_DATA (object)); |
| 398 | build_string ("Unable to append argument"), object); | 424 | if (!dbus_message_iter_append_basic (iter, dtype, |
| 399 | } | 425 | &XFLOAT_DATA (object))) |
| 426 | xsignal2 (Qdbus_error, | ||
| 427 | build_string ("Unable to append argument"), object); | ||
| 428 | return; | ||
| 429 | |||
| 430 | case DBUS_TYPE_STRING: | ||
| 431 | case DBUS_TYPE_OBJECT_PATH: | ||
| 432 | case DBUS_TYPE_SIGNATURE: | ||
| 433 | { | ||
| 434 | char *val = SDATA (object); | ||
| 435 | XD_DEBUG_MESSAGE ("%c %s", dtype, val); | ||
| 436 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | ||
| 437 | xsignal2 (Qdbus_error, | ||
| 438 | build_string ("Unable to append argument"), object); | ||
| 439 | return; | ||
| 440 | } | ||
| 441 | } | ||
| 400 | 442 | ||
| 401 | else /* Compound types. */ | 443 | else /* Compound types. */ |
| 402 | { | 444 | { |
| @@ -470,11 +512,10 @@ xd_retrieve_arg (dtype, iter) | |||
| 470 | switch (dtype) | 512 | switch (dtype) |
| 471 | { | 513 | { |
| 472 | case DBUS_TYPE_BYTE: | 514 | case DBUS_TYPE_BYTE: |
| 473 | case DBUS_TYPE_INT16: | ||
| 474 | case DBUS_TYPE_UINT16: | ||
| 475 | { | 515 | { |
| 476 | dbus_uint16_t val; | 516 | unsigned int val; |
| 477 | dbus_message_iter_get_basic (iter, &val); | 517 | dbus_message_iter_get_basic (iter, &val); |
| 518 | val = val & 0xFF; | ||
| 478 | XD_DEBUG_MESSAGE ("%c %d", dtype, val); | 519 | XD_DEBUG_MESSAGE ("%c %d", dtype, val); |
| 479 | return make_number (val); | 520 | return make_number (val); |
| 480 | } | 521 | } |
| @@ -487,15 +528,21 @@ xd_retrieve_arg (dtype, iter) | |||
| 487 | return (val == FALSE) ? Qnil : Qt; | 528 | return (val == FALSE) ? Qnil : Qt; |
| 488 | } | 529 | } |
| 489 | 530 | ||
| 531 | case DBUS_TYPE_INT16: | ||
| 532 | case DBUS_TYPE_UINT16: | ||
| 533 | { | ||
| 534 | dbus_uint16_t val; | ||
| 535 | dbus_message_iter_get_basic (iter, &val); | ||
| 536 | XD_DEBUG_MESSAGE ("%c %d", dtype, val); | ||
| 537 | return make_number (val); | ||
| 538 | } | ||
| 539 | |||
| 490 | case DBUS_TYPE_INT32: | 540 | case DBUS_TYPE_INT32: |
| 491 | case DBUS_TYPE_UINT32: | 541 | case DBUS_TYPE_UINT32: |
| 492 | { | 542 | { |
| 493 | dbus_uint32_t val; | 543 | dbus_uint32_t val; |
| 494 | dbus_message_iter_get_basic (iter, &val); | 544 | dbus_message_iter_get_basic (iter, &val); |
| 495 | if (FIXNUM_OVERFLOW_P (val)) | 545 | XD_DEBUG_MESSAGE ("%c %d", dtype, val); |
| 496 | XD_DEBUG_MESSAGE ("%c %f", dtype, val) | ||
| 497 | else | ||
| 498 | XD_DEBUG_MESSAGE ("%c %d", dtype, val); | ||
| 499 | return make_fixnum_or_float (val); | 546 | return make_fixnum_or_float (val); |
| 500 | } | 547 | } |
| 501 | 548 | ||
| @@ -504,10 +551,7 @@ xd_retrieve_arg (dtype, iter) | |||
| 504 | { | 551 | { |
| 505 | dbus_uint64_t val; | 552 | dbus_uint64_t val; |
| 506 | dbus_message_iter_get_basic (iter, &val); | 553 | dbus_message_iter_get_basic (iter, &val); |
| 507 | if (FIXNUM_OVERFLOW_P (val)) | 554 | XD_DEBUG_MESSAGE ("%c %d", dtype, (int) val); |
| 508 | XD_DEBUG_MESSAGE ("%c %f", dtype, val) | ||
| 509 | else | ||
| 510 | XD_DEBUG_MESSAGE ("%c %d", dtype, val); | ||
| 511 | return make_fixnum_or_float (val); | 555 | return make_fixnum_or_float (val); |
| 512 | } | 556 | } |
| 513 | 557 | ||
| @@ -923,6 +967,7 @@ xd_read_message (bus) | |||
| 923 | DBusMessage *dmessage; | 967 | DBusMessage *dmessage; |
| 924 | DBusMessageIter iter; | 968 | DBusMessageIter iter; |
| 925 | unsigned int dtype; | 969 | unsigned int dtype; |
| 970 | int mtype; | ||
| 926 | char uname[DBUS_MAXIMUM_NAME_LENGTH]; | 971 | char uname[DBUS_MAXIMUM_NAME_LENGTH]; |
| 927 | char path[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; /* Unlimited in D-Bus spec. */ | 972 | char path[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; /* Unlimited in D-Bus spec. */ |
| 928 | char interface[DBUS_MAXIMUM_NAME_LENGTH]; | 973 | char interface[DBUS_MAXIMUM_NAME_LENGTH]; |
| @@ -937,38 +982,37 @@ xd_read_message (bus) | |||
| 937 | 982 | ||
| 938 | /* Return if there is no queued message. */ | 983 | /* Return if there is no queued message. */ |
| 939 | if (dmessage == NULL) | 984 | if (dmessage == NULL) |
| 940 | return; | 985 | return Qnil; |
| 941 | |||
| 942 | XD_DEBUG_MESSAGE ("Event received"); | ||
| 943 | 986 | ||
| 944 | /* Collect the parameters. */ | 987 | /* Collect the parameters. */ |
| 945 | args = Qnil; | 988 | args = Qnil; |
| 946 | GCPRO1 (args); | 989 | GCPRO1 (args); |
| 947 | 990 | ||
| 948 | if (!dbus_message_iter_init (dmessage, &iter)) | ||
| 949 | { | ||
| 950 | UNGCPRO; | ||
| 951 | XD_DEBUG_MESSAGE ("Cannot read event"); | ||
| 952 | return; | ||
| 953 | } | ||
| 954 | |||
| 955 | /* Loop over the resulting parameters. Construct a list. */ | 991 | /* Loop over the resulting parameters. Construct a list. */ |
| 956 | while ((dtype = dbus_message_iter_get_arg_type (&iter)) != DBUS_TYPE_INVALID) | 992 | if (dbus_message_iter_init (dmessage, &iter)) |
| 957 | { | 993 | { |
| 958 | args = Fcons (xd_retrieve_arg (dtype, &iter), args); | 994 | while ((dtype = dbus_message_iter_get_arg_type (&iter)) |
| 959 | dbus_message_iter_next (&iter); | 995 | != DBUS_TYPE_INVALID) |
| 996 | { | ||
| 997 | args = Fcons (xd_retrieve_arg (dtype, &iter), args); | ||
| 998 | dbus_message_iter_next (&iter); | ||
| 999 | } | ||
| 1000 | /* The arguments are stored in reverse order. Reorder them. */ | ||
| 1001 | args = Fnreverse (args); | ||
| 960 | } | 1002 | } |
| 961 | 1003 | ||
| 962 | /* The arguments are stored in reverse order. Reorder them. */ | 1004 | /* Read message type, unique name, object path, interface and member |
| 963 | args = Fnreverse (args); | 1005 | from the message. */ |
| 964 | 1006 | mtype = dbus_message_get_type (dmessage); | |
| 965 | /* Read unique name, object path, interface and member from the | ||
| 966 | message. */ | ||
| 967 | strcpy (uname, dbus_message_get_sender (dmessage)); | 1007 | strcpy (uname, dbus_message_get_sender (dmessage)); |
| 968 | strcpy (path, dbus_message_get_path (dmessage)); | 1008 | strcpy (path, dbus_message_get_path (dmessage)); |
| 969 | strcpy (interface, dbus_message_get_interface (dmessage)); | 1009 | strcpy (interface, dbus_message_get_interface (dmessage)); |
| 970 | strcpy (member, dbus_message_get_member (dmessage)); | 1010 | strcpy (member, dbus_message_get_member (dmessage)); |
| 971 | 1011 | ||
| 1012 | XD_DEBUG_MESSAGE ("Event received: %d %s %s %s %s %s", | ||
| 1013 | mtype, uname, path, interface, member, | ||
| 1014 | SDATA (format2 ("%s", args, Qnil))); | ||
| 1015 | |||
| 972 | /* Search for a registered function of the message. */ | 1016 | /* Search for a registered function of the message. */ |
| 973 | key = list3 (bus, build_string (interface), build_string (member)); | 1017 | key = list3 (bus, build_string (interface), build_string (member)); |
| 974 | value = Fgethash (key, Vdbus_registered_functions_table, Qnil); | 1018 | value = Fgethash (key, Vdbus_registered_functions_table, Qnil); |
| @@ -1013,7 +1057,7 @@ xd_read_message (bus) | |||
| 1013 | 1057 | ||
| 1014 | /* Cleanup. */ | 1058 | /* Cleanup. */ |
| 1015 | dbus_message_unref (dmessage); | 1059 | dbus_message_unref (dmessage); |
| 1016 | UNGCPRO; | 1060 | RETURN_UNGCPRO (Qnil); |
| 1017 | } | 1061 | } |
| 1018 | 1062 | ||
| 1019 | /* Read queued incoming messages from the system and session buses. */ | 1063 | /* Read queued incoming messages from the system and session buses. */ |
| @@ -1064,11 +1108,11 @@ SIGNAL and HANDLER must not be nil. Example: | |||
| 1064 | ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager" my-signal-handler)) | 1108 | ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager" my-signal-handler)) |
| 1065 | 1109 | ||
| 1066 | `dbus-register-signal' returns an object, which can be used in | 1110 | `dbus-register-signal' returns an object, which can be used in |
| 1067 | `dbus-unregister-signal' for removing the registration. */) | 1111 | `dbus-unregister-object' for removing the registration. */) |
| 1068 | (bus, service, path, interface, signal, handler) | 1112 | (bus, service, path, interface, signal, handler) |
| 1069 | Lisp_Object bus, service, path, interface, signal, handler; | 1113 | Lisp_Object bus, service, path, interface, signal, handler; |
| 1070 | { | 1114 | { |
| 1071 | Lisp_Object uname, key, value; | 1115 | Lisp_Object uname, key, key1, value; |
| 1072 | DBusConnection *connection; | 1116 | DBusConnection *connection; |
| 1073 | char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; | 1117 | char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; |
| 1074 | DBusError derror; | 1118 | DBusError derror; |
| @@ -1079,7 +1123,8 @@ SIGNAL and HANDLER must not be nil. Example: | |||
| 1079 | if (!NILP (path)) CHECK_STRING (path); | 1123 | if (!NILP (path)) CHECK_STRING (path); |
| 1080 | CHECK_STRING (interface); | 1124 | CHECK_STRING (interface); |
| 1081 | CHECK_STRING (signal); | 1125 | CHECK_STRING (signal); |
| 1082 | FUNCTIONP (handler); | 1126 | if (!FUNCTIONP (handler)) |
| 1127 | wrong_type_argument (intern ("functionp"), handler); | ||
| 1083 | 1128 | ||
| 1084 | /* Retrieve unique name of service. If service is a known name, we | 1129 | /* Retrieve unique name of service. If service is a known name, we |
| 1085 | will register for the corresponding unique name, if any. Signals | 1130 | will register for the corresponding unique name, if any. Signals |
| @@ -1130,21 +1175,84 @@ SIGNAL and HANDLER must not be nil. Example: | |||
| 1130 | 1175 | ||
| 1131 | /* Create a hash table entry. */ | 1176 | /* Create a hash table entry. */ |
| 1132 | key = list3 (bus, interface, signal); | 1177 | key = list3 (bus, interface, signal); |
| 1178 | key1 = list4 (uname, service, path, handler); | ||
| 1179 | value = Fgethash (key, Vdbus_registered_functions_table, Qnil); | ||
| 1180 | |||
| 1181 | if (NILP (Fmember (key1, value))) | ||
| 1182 | Fputhash (key, Fcons (key1, value), Vdbus_registered_functions_table); | ||
| 1183 | |||
| 1184 | /* Return object. */ | ||
| 1185 | return list2 (key, list3 (service, path, handler)); | ||
| 1186 | } | ||
| 1187 | |||
| 1188 | DEFUN ("dbus-register-method", Fdbus_register_method, Sdbus_register_method, | ||
| 1189 | 6, 6, 0, | ||
| 1190 | doc: /* Register for method METHOD on the D-Bus BUS. | ||
| 1191 | |||
| 1192 | BUS is either the symbol `:system' or the symbol `:session'. | ||
| 1193 | |||
| 1194 | SERVICE is the D-Bus service name of the D-Bus object METHOD is | ||
| 1195 | registered for. It must be a known name. | ||
| 1196 | |||
| 1197 | PATH is the D-Bus object path SERVICE is registered. INTERFACE is the | ||
| 1198 | interface offered by SERVICE. It must provide METHOD. HANDLER is a | ||
| 1199 | Lisp function to be called when a method call is received. It must | ||
| 1200 | accept the input arguments of METHOD. The return value of HANDLER is | ||
| 1201 | used for composing the returning D-Bus message. | ||
| 1202 | |||
| 1203 | The function is not fully implemented and documented. Don't use it. */) | ||
| 1204 | (bus, service, path, interface, method, handler) | ||
| 1205 | Lisp_Object bus, service, path, interface, method, handler; | ||
| 1206 | { | ||
| 1207 | Lisp_Object key, key1, value; | ||
| 1208 | DBusConnection *connection; | ||
| 1209 | int result; | ||
| 1210 | DBusError derror; | ||
| 1211 | |||
| 1212 | if (NILP (Vdbus_debug)) | ||
| 1213 | xsignal1 (Qdbus_error, build_string ("Not implemented yet")); | ||
| 1214 | |||
| 1215 | /* Check parameters. */ | ||
| 1216 | CHECK_SYMBOL (bus); | ||
| 1217 | CHECK_STRING (service); | ||
| 1218 | CHECK_STRING (path); | ||
| 1219 | CHECK_STRING (interface); | ||
| 1220 | CHECK_STRING (method); | ||
| 1221 | if (!FUNCTIONP (handler)) | ||
| 1222 | wrong_type_argument (intern ("functionp"), handler); | ||
| 1223 | /* TODO: We must check for a valid service name, otherwise there is | ||
| 1224 | a segmentation fault. */ | ||
| 1225 | |||
| 1226 | /* Open a connection to the bus. */ | ||
| 1227 | connection = xd_initialize (bus); | ||
| 1228 | |||
| 1229 | /* Request the known name from the bus. We can ignore the result, | ||
| 1230 | it is set to -1 if there is an error - kind of redundancy. */ | ||
| 1231 | dbus_error_init (&derror); | ||
| 1232 | result = dbus_bus_request_name (connection, SDATA (service), 0, &derror); | ||
| 1233 | if (dbus_error_is_set (&derror)) | ||
| 1234 | XD_ERROR (derror); | ||
| 1235 | |||
| 1236 | /* Create a hash table entry. */ | ||
| 1237 | key = list3 (bus, interface, method); | ||
| 1238 | key1 = list4 (Qnil, service, path, handler); | ||
| 1133 | value = Fgethash (key, Vdbus_registered_functions_table, Qnil); | 1239 | value = Fgethash (key, Vdbus_registered_functions_table, Qnil); |
| 1134 | 1240 | ||
| 1135 | if (NILP (Fmember (list4 (uname, service, path, handler), value))) | 1241 | /* We use nil for the unique name, because the method might be |
| 1136 | Fputhash (key, | 1242 | called from everybody. */ |
| 1137 | Fcons (list4 (uname, service, path, handler), value), | 1243 | if (NILP (Fmember (key1, value))) |
| 1138 | Vdbus_registered_functions_table); | 1244 | Fputhash (key, Fcons (key1, value), Vdbus_registered_functions_table); |
| 1139 | 1245 | ||
| 1140 | /* Return object. */ | 1246 | /* Return object. */ |
| 1141 | return list2 (key, list3 (service, path, handler)); | 1247 | return list2 (key, list3 (service, path, handler)); |
| 1142 | } | 1248 | } |
| 1143 | 1249 | ||
| 1144 | DEFUN ("dbus-unregister-signal", Fdbus_unregister_signal, Sdbus_unregister_signal, | 1250 | DEFUN ("dbus-unregister-object", Fdbus_unregister_object, Sdbus_unregister_object, |
| 1145 | 1, 1, 0, | 1251 | 1, 1, 0, |
| 1146 | doc: /* Unregister OBJECT from the D-Bus. | 1252 | doc: /* Unregister OBJECT from the D-Bus. |
| 1147 | OBJECT must be the result of a preceding `dbus-register-signal' call. */) | 1253 | OBJECT must be the result of a preceding `dbus-register-signal' or |
| 1254 | `dbus-register-method' call. It returns t if OBJECT has been | ||
| 1255 | unregistered, nil otherwise. */) | ||
| 1148 | (object) | 1256 | (object) |
| 1149 | Lisp_Object object; | 1257 | Lisp_Object object; |
| 1150 | { | 1258 | { |
| @@ -1152,7 +1260,8 @@ OBJECT must be the result of a preceding `dbus-register-signal' call. */) | |||
| 1152 | struct gcpro gcpro1; | 1260 | struct gcpro gcpro1; |
| 1153 | 1261 | ||
| 1154 | /* Check parameter. */ | 1262 | /* Check parameter. */ |
| 1155 | CONSP (object) && (!NILP (XCAR (object))) && CONSP (XCDR (object)); | 1263 | if (!(CONSP (object) && (!NILP (XCAR (object))) && CONSP (XCDR (object)))) |
| 1264 | wrong_type_argument (intern ("D-Bus"), object); | ||
| 1156 | 1265 | ||
| 1157 | /* Find the corresponding entry in the hash table. */ | 1266 | /* Find the corresponding entry in the hash table. */ |
| 1158 | value = Fgethash (XCAR (object), Vdbus_registered_functions_table, Qnil); | 1267 | value = Fgethash (XCAR (object), Vdbus_registered_functions_table, Qnil); |
| @@ -1205,9 +1314,13 @@ syms_of_dbusbind () | |||
| 1205 | staticpro (&Qdbus_register_signal); | 1314 | staticpro (&Qdbus_register_signal); |
| 1206 | defsubr (&Sdbus_register_signal); | 1315 | defsubr (&Sdbus_register_signal); |
| 1207 | 1316 | ||
| 1208 | Qdbus_unregister_signal = intern ("dbus-unregister-signal"); | 1317 | Qdbus_register_method = intern ("dbus-register-method"); |
| 1209 | staticpro (&Qdbus_unregister_signal); | 1318 | staticpro (&Qdbus_register_method); |
| 1210 | defsubr (&Sdbus_unregister_signal); | 1319 | defsubr (&Sdbus_register_method); |
| 1320 | |||
| 1321 | Qdbus_unregister_object = intern ("dbus-unregister-object"); | ||
| 1322 | staticpro (&Qdbus_unregister_object); | ||
| 1323 | defsubr (&Sdbus_unregister_object); | ||
| 1211 | 1324 | ||
| 1212 | Qdbus_error = intern ("dbus-error"); | 1325 | Qdbus_error = intern ("dbus-error"); |
| 1213 | staticpro (&Qdbus_error); | 1326 | staticpro (&Qdbus_error); |