diff options
| author | Eli Zaretskii | 2013-09-05 11:01:04 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2013-09-05 11:01:04 +0300 |
| commit | 41306318777a942420bc4feadbfacf662ea179dc (patch) | |
| tree | 669e5cca02f95d6064ce73c0d3fbbf91b8c8b563 /src/dbusbind.c | |
| parent | 141f1ff7a40cda10f0558e891dd196a943a5082e (diff) | |
| parent | 257b3b03cb1cff917e0b3b7832ad3eab5b59f257 (diff) | |
| download | emacs-41306318777a942420bc4feadbfacf662ea179dc.tar.gz emacs-41306318777a942420bc4feadbfacf662ea179dc.zip | |
Merge from trunk after a lot of time.
Diffstat (limited to 'src/dbusbind.c')
| -rw-r--r-- | src/dbusbind.c | 238 |
1 files changed, 139 insertions, 99 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c index e506380e607..523544d56ca 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Elisp bindings for D-Bus. | 1 | /* Elisp bindings for D-Bus. |
| 2 | Copyright (C) 2007-2012 Free Software Foundation, Inc. | 2 | Copyright (C) 2007-2013 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This file is part of GNU Emacs. | 4 | This file is part of GNU Emacs. |
| 5 | 5 | ||
| @@ -21,7 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 21 | #ifdef HAVE_DBUS | 21 | #ifdef HAVE_DBUS |
| 22 | #include <stdio.h> | 22 | #include <stdio.h> |
| 23 | #include <dbus/dbus.h> | 23 | #include <dbus/dbus.h> |
| 24 | #include <setjmp.h> | 24 | |
| 25 | #include "lisp.h" | 25 | #include "lisp.h" |
| 26 | #include "frame.h" | 26 | #include "frame.h" |
| 27 | #include "termhooks.h" | 27 | #include "termhooks.h" |
| @@ -32,6 +32,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 32 | #define DBUS_NUM_MESSAGE_TYPES 5 | 32 | #define DBUS_NUM_MESSAGE_TYPES 5 |
| 33 | #endif | 33 | #endif |
| 34 | 34 | ||
| 35 | |||
| 36 | /* Some platforms define the symbol "interface", but we want to use it | ||
| 37 | * as a variable name below. */ | ||
| 38 | |||
| 39 | #ifdef interface | ||
| 40 | #undef interface | ||
| 41 | #endif | ||
| 42 | |||
| 35 | 43 | ||
| 36 | /* Subroutines. */ | 44 | /* Subroutines. */ |
| 37 | static Lisp_Object Qdbus_init_bus; | 45 | static Lisp_Object Qdbus_init_bus; |
| @@ -70,7 +78,7 @@ static Lisp_Object QCdbus_registered_signal; | |||
| 70 | static Lisp_Object xd_registered_buses; | 78 | static Lisp_Object xd_registered_buses; |
| 71 | 79 | ||
| 72 | /* Whether we are reading a D-Bus event. */ | 80 | /* Whether we are reading a D-Bus event. */ |
| 73 | static int xd_in_read_queued_messages = 0; | 81 | static bool xd_in_read_queued_messages = 0; |
| 74 | 82 | ||
| 75 | 83 | ||
| 76 | /* We use "xd_" and "XD_" as prefix for all internal symbols, because | 84 | /* We use "xd_" and "XD_" as prefix for all internal symbols, because |
| @@ -134,7 +142,10 @@ static int xd_in_read_queued_messages = 0; | |||
| 134 | } while (0) | 142 | } while (0) |
| 135 | 143 | ||
| 136 | #else /* !DBUS_DEBUG */ | 144 | #else /* !DBUS_DEBUG */ |
| 137 | #define XD_DEBUG_MESSAGE(...) \ | 145 | # if __STDC_VERSION__ < 199901 |
| 146 | # define XD_DEBUG_MESSAGE (void) /* Pre-C99 compilers cannot debug. */ | ||
| 147 | # else | ||
| 148 | # define XD_DEBUG_MESSAGE(...) \ | ||
| 138 | do { \ | 149 | do { \ |
| 139 | if (!NILP (Vdbus_debug)) \ | 150 | if (!NILP (Vdbus_debug)) \ |
| 140 | { \ | 151 | { \ |
| @@ -143,10 +154,15 @@ static int xd_in_read_queued_messages = 0; | |||
| 143 | message ("%s: %s", __func__, s); \ | 154 | message ("%s: %s", __func__, s); \ |
| 144 | } \ | 155 | } \ |
| 145 | } while (0) | 156 | } while (0) |
| 146 | #define XD_DEBUG_VALID_LISP_OBJECT_P(object) | 157 | # endif |
| 158 | # define XD_DEBUG_VALID_LISP_OBJECT_P(object) | ||
| 147 | #endif | 159 | #endif |
| 148 | 160 | ||
| 149 | /* Check whether TYPE is a basic DBusType. */ | 161 | /* Check whether TYPE is a basic DBusType. */ |
| 162 | #ifdef HAVE_DBUS_TYPE_IS_VALID | ||
| 163 | #define XD_BASIC_DBUS_TYPE(type) \ | ||
| 164 | (dbus_type_is_valid (type) && dbus_type_is_basic (type)) | ||
| 165 | #else | ||
| 150 | #ifdef DBUS_TYPE_UNIX_FD | 166 | #ifdef DBUS_TYPE_UNIX_FD |
| 151 | #define XD_BASIC_DBUS_TYPE(type) \ | 167 | #define XD_BASIC_DBUS_TYPE(type) \ |
| 152 | ((type == DBUS_TYPE_BYTE) \ | 168 | ((type == DBUS_TYPE_BYTE) \ |
| @@ -177,6 +193,7 @@ static int xd_in_read_queued_messages = 0; | |||
| 177 | || (type == DBUS_TYPE_OBJECT_PATH) \ | 193 | || (type == DBUS_TYPE_OBJECT_PATH) \ |
| 178 | || (type == DBUS_TYPE_SIGNATURE)) | 194 | || (type == DBUS_TYPE_SIGNATURE)) |
| 179 | #endif | 195 | #endif |
| 196 | #endif | ||
| 180 | 197 | ||
| 181 | /* This was a macro. On Solaris 2.11 it was said to compile for | 198 | /* This was a macro. On Solaris 2.11 it was said to compile for |
| 182 | hours, when optimization is enabled. So we have transferred it into | 199 | hours, when optimization is enabled. So we have transferred it into |
| @@ -256,6 +273,7 @@ xd_symbol_to_dbus_type (Lisp_Object object) | |||
| 256 | 273 | ||
| 257 | #define XD_DBUS_VALIDATE_BUS_ADDRESS(bus) \ | 274 | #define XD_DBUS_VALIDATE_BUS_ADDRESS(bus) \ |
| 258 | do { \ | 275 | do { \ |
| 276 | char const *session_bus_address = getenv ("DBUS_SESSION_BUS_ADDRESS"); \ | ||
| 259 | if (STRINGP (bus)) \ | 277 | if (STRINGP (bus)) \ |
| 260 | { \ | 278 | { \ |
| 261 | DBusAddressEntry **entries; \ | 279 | DBusAddressEntry **entries; \ |
| @@ -267,6 +285,11 @@ xd_symbol_to_dbus_type (Lisp_Object object) | |||
| 267 | /* Cleanup. */ \ | 285 | /* Cleanup. */ \ |
| 268 | dbus_error_free (&derror); \ | 286 | dbus_error_free (&derror); \ |
| 269 | dbus_address_entries_free (entries); \ | 287 | dbus_address_entries_free (entries); \ |
| 288 | /* Canonicalize session bus address. */ \ | ||
| 289 | if ((session_bus_address != NULL) \ | ||
| 290 | && (!NILP (Fstring_equal \ | ||
| 291 | (bus, build_string (session_bus_address))))) \ | ||
| 292 | bus = QCdbus_session_bus; \ | ||
| 270 | } \ | 293 | } \ |
| 271 | \ | 294 | \ |
| 272 | else \ | 295 | else \ |
| @@ -275,14 +298,13 @@ xd_symbol_to_dbus_type (Lisp_Object object) | |||
| 275 | if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus))) \ | 298 | if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus))) \ |
| 276 | XD_SIGNAL2 (build_string ("Wrong bus name"), bus); \ | 299 | XD_SIGNAL2 (build_string ("Wrong bus name"), bus); \ |
| 277 | /* We do not want to have an autolaunch for the session bus. */ \ | 300 | /* We do not want to have an autolaunch for the session bus. */ \ |
| 278 | if (EQ (bus, QCdbus_session_bus) \ | 301 | if (EQ (bus, QCdbus_session_bus) && session_bus_address == NULL) \ |
| 279 | && getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL) \ | ||
| 280 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); \ | 302 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); \ |
| 281 | } \ | 303 | } \ |
| 282 | } while (0) | 304 | } while (0) |
| 283 | 305 | ||
| 284 | #if (HAVE_DBUS_VALIDATE_BUS_NAME || HAVE_DBUS_VALIDATE_PATH \ | 306 | #if (HAVE_DBUS_VALIDATE_BUS_NAME || HAVE_DBUS_VALIDATE_PATH \ |
| 285 | || XD_DBUS_VALIDATE_OBJECT || HAVE_DBUS_VALIDATE_MEMBER) | 307 | || HAVE_DBUS_VALIDATE_INTERFACE || HAVE_DBUS_VALIDATE_MEMBER) |
| 286 | #define XD_DBUS_VALIDATE_OBJECT(object, func) \ | 308 | #define XD_DBUS_VALIDATE_OBJECT(object, func) \ |
| 287 | do { \ | 309 | do { \ |
| 288 | if (!NILP (object)) \ | 310 | if (!NILP (object)) \ |
| @@ -524,7 +546,7 @@ xd_signature (char *signature, int dtype, int parent_type, Lisp_Object object) | |||
| 524 | 546 | ||
| 525 | /* Convert X to a signed integer with bounds LO and HI. */ | 547 | /* Convert X to a signed integer with bounds LO and HI. */ |
| 526 | static intmax_t | 548 | static intmax_t |
| 527 | extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi) | 549 | xd_extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi) |
| 528 | { | 550 | { |
| 529 | CHECK_NUMBER_OR_FLOAT (x); | 551 | CHECK_NUMBER_OR_FLOAT (x); |
| 530 | if (INTEGERP (x)) | 552 | if (INTEGERP (x)) |
| @@ -552,7 +574,7 @@ extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi) | |||
| 552 | 574 | ||
| 553 | /* Convert X to an unsigned integer with bounds 0 and HI. */ | 575 | /* Convert X to an unsigned integer with bounds 0 and HI. */ |
| 554 | static uintmax_t | 576 | static uintmax_t |
| 555 | extract_unsigned (Lisp_Object x, uintmax_t hi) | 577 | xd_extract_unsigned (Lisp_Object x, uintmax_t hi) |
| 556 | { | 578 | { |
| 557 | CHECK_NUMBER_OR_FLOAT (x); | 579 | CHECK_NUMBER_OR_FLOAT (x); |
| 558 | if (INTEGERP (x)) | 580 | if (INTEGERP (x)) |
| @@ -611,9 +633,10 @@ xd_append_arg (int dtype, Lisp_Object object, DBusMessageIter *iter) | |||
| 611 | 633 | ||
| 612 | case DBUS_TYPE_INT16: | 634 | case DBUS_TYPE_INT16: |
| 613 | { | 635 | { |
| 614 | dbus_int16_t val = extract_signed (object, | 636 | dbus_int16_t val = |
| 615 | TYPE_MINIMUM (dbus_int16_t), | 637 | xd_extract_signed (object, |
| 616 | TYPE_MAXIMUM (dbus_int16_t)); | 638 | TYPE_MINIMUM (dbus_int16_t), |
| 639 | TYPE_MAXIMUM (dbus_int16_t)); | ||
| 617 | int pval = val; | 640 | int pval = val; |
| 618 | XD_DEBUG_MESSAGE ("%c %d", dtype, pval); | 641 | XD_DEBUG_MESSAGE ("%c %d", dtype, pval); |
| 619 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | 642 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) |
| @@ -623,8 +646,9 @@ xd_append_arg (int dtype, Lisp_Object object, DBusMessageIter *iter) | |||
| 623 | 646 | ||
| 624 | case DBUS_TYPE_UINT16: | 647 | case DBUS_TYPE_UINT16: |
| 625 | { | 648 | { |
| 626 | dbus_uint16_t val = extract_unsigned (object, | 649 | dbus_uint16_t val = |
| 627 | TYPE_MAXIMUM (dbus_uint16_t)); | 650 | xd_extract_unsigned (object, |
| 651 | TYPE_MAXIMUM (dbus_uint16_t)); | ||
| 628 | unsigned int pval = val; | 652 | unsigned int pval = val; |
| 629 | XD_DEBUG_MESSAGE ("%c %u", dtype, pval); | 653 | XD_DEBUG_MESSAGE ("%c %u", dtype, pval); |
| 630 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | 654 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) |
| @@ -634,9 +658,10 @@ xd_append_arg (int dtype, Lisp_Object object, DBusMessageIter *iter) | |||
| 634 | 658 | ||
| 635 | case DBUS_TYPE_INT32: | 659 | case DBUS_TYPE_INT32: |
| 636 | { | 660 | { |
| 637 | dbus_int32_t val = extract_signed (object, | 661 | dbus_int32_t val = |
| 638 | TYPE_MINIMUM (dbus_int32_t), | 662 | xd_extract_signed (object, |
| 639 | TYPE_MAXIMUM (dbus_int32_t)); | 663 | TYPE_MINIMUM (dbus_int32_t), |
| 664 | TYPE_MAXIMUM (dbus_int32_t)); | ||
| 640 | int pval = val; | 665 | int pval = val; |
| 641 | XD_DEBUG_MESSAGE ("%c %d", dtype, pval); | 666 | XD_DEBUG_MESSAGE ("%c %d", dtype, pval); |
| 642 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | 667 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) |
| @@ -649,8 +674,9 @@ xd_append_arg (int dtype, Lisp_Object object, DBusMessageIter *iter) | |||
| 649 | case DBUS_TYPE_UNIX_FD: | 674 | case DBUS_TYPE_UNIX_FD: |
| 650 | #endif | 675 | #endif |
| 651 | { | 676 | { |
| 652 | dbus_uint32_t val = extract_unsigned (object, | 677 | dbus_uint32_t val = |
| 653 | TYPE_MAXIMUM (dbus_uint32_t)); | 678 | xd_extract_unsigned (object, |
| 679 | TYPE_MAXIMUM (dbus_uint32_t)); | ||
| 654 | unsigned int pval = val; | 680 | unsigned int pval = val; |
| 655 | XD_DEBUG_MESSAGE ("%c %u", dtype, pval); | 681 | XD_DEBUG_MESSAGE ("%c %u", dtype, pval); |
| 656 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | 682 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) |
| @@ -660,9 +686,10 @@ xd_append_arg (int dtype, Lisp_Object object, DBusMessageIter *iter) | |||
| 660 | 686 | ||
| 661 | case DBUS_TYPE_INT64: | 687 | case DBUS_TYPE_INT64: |
| 662 | { | 688 | { |
| 663 | dbus_int64_t val = extract_signed (object, | 689 | dbus_int64_t val = |
| 664 | TYPE_MINIMUM (dbus_int64_t), | 690 | xd_extract_signed (object, |
| 665 | TYPE_MAXIMUM (dbus_int64_t)); | 691 | TYPE_MINIMUM (dbus_int64_t), |
| 692 | TYPE_MAXIMUM (dbus_int64_t)); | ||
| 666 | printmax_t pval = val; | 693 | printmax_t pval = val; |
| 667 | XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval); | 694 | XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval); |
| 668 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | 695 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) |
| @@ -672,8 +699,9 @@ xd_append_arg (int dtype, Lisp_Object object, DBusMessageIter *iter) | |||
| 672 | 699 | ||
| 673 | case DBUS_TYPE_UINT64: | 700 | case DBUS_TYPE_UINT64: |
| 674 | { | 701 | { |
| 675 | dbus_uint64_t val = extract_unsigned (object, | 702 | dbus_uint64_t val = |
| 676 | TYPE_MAXIMUM (dbus_uint64_t)); | 703 | xd_extract_unsigned (object, |
| 704 | TYPE_MAXIMUM (dbus_uint64_t)); | ||
| 677 | uprintmax_t pval = val; | 705 | uprintmax_t pval = val; |
| 678 | XD_DEBUG_MESSAGE ("%c %"pMu, dtype, pval); | 706 | XD_DEBUG_MESSAGE ("%c %"pMu, dtype, pval); |
| 679 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) | 707 | if (!dbus_message_iter_append_basic (iter, dtype, &val)) |
| @@ -858,7 +886,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter) | |||
| 858 | #endif | 886 | #endif |
| 859 | { | 887 | { |
| 860 | dbus_uint32_t val; | 888 | dbus_uint32_t val; |
| 861 | unsigned int pval = val; | 889 | unsigned int pval; |
| 862 | dbus_message_iter_get_basic (iter, &val); | 890 | dbus_message_iter_get_basic (iter, &val); |
| 863 | pval = val; | 891 | pval = val; |
| 864 | XD_DEBUG_MESSAGE ("%c %u", dtype, pval); | 892 | XD_DEBUG_MESSAGE ("%c %u", dtype, pval); |
| @@ -970,7 +998,7 @@ static int | |||
| 970 | xd_find_watch_fd (DBusWatch *watch) | 998 | xd_find_watch_fd (DBusWatch *watch) |
| 971 | { | 999 | { |
| 972 | #if HAVE_DBUS_WATCH_GET_UNIX_FD | 1000 | #if HAVE_DBUS_WATCH_GET_UNIX_FD |
| 973 | /* TODO: Reverse these on Win32, which prefers the opposite. */ | 1001 | /* TODO: Reverse these on w32, which prefers the opposite. */ |
| 974 | int fd = dbus_watch_get_unix_fd (watch); | 1002 | int fd = dbus_watch_get_unix_fd (watch); |
| 975 | if (fd == -1) | 1003 | if (fd == -1) |
| 976 | fd = dbus_watch_get_socket (watch); | 1004 | fd = dbus_watch_get_socket (watch); |
| @@ -981,8 +1009,7 @@ xd_find_watch_fd (DBusWatch *watch) | |||
| 981 | } | 1009 | } |
| 982 | 1010 | ||
| 983 | /* Prototype. */ | 1011 | /* Prototype. */ |
| 984 | static void | 1012 | static void xd_read_queued_messages (int fd, void *data); |
| 985 | xd_read_queued_messages (int fd, void *data, int for_read); | ||
| 986 | 1013 | ||
| 987 | /* Start monitoring WATCH for possible I/O. */ | 1014 | /* Start monitoring WATCH for possible I/O. */ |
| 988 | static dbus_bool_t | 1015 | static dbus_bool_t |
| @@ -1023,11 +1050,13 @@ xd_remove_watch (DBusWatch *watch, void *data) | |||
| 1023 | return; | 1050 | return; |
| 1024 | 1051 | ||
| 1025 | /* Unset session environment. */ | 1052 | /* Unset session environment. */ |
| 1053 | #if 0 | ||
| 1026 | if (XSYMBOL (QCdbus_session_bus) == data) | 1054 | if (XSYMBOL (QCdbus_session_bus) == data) |
| 1027 | { | 1055 | { |
| 1028 | // XD_DEBUG_MESSAGE ("unsetenv DBUS_SESSION_BUS_ADDRESS"); | 1056 | XD_DEBUG_MESSAGE ("unsetenv DBUS_SESSION_BUS_ADDRESS"); |
| 1029 | // unsetenv ("DBUS_SESSION_BUS_ADDRESS"); | 1057 | unsetenv ("DBUS_SESSION_BUS_ADDRESS"); |
| 1030 | } | 1058 | } |
| 1059 | #endif | ||
| 1031 | 1060 | ||
| 1032 | if (flags & DBUS_WATCH_WRITABLE) | 1061 | if (flags & DBUS_WATCH_WRITABLE) |
| 1033 | delete_write_fd (fd); | 1062 | delete_write_fd (fd); |
| @@ -1060,19 +1089,19 @@ xd_close_bus (Lisp_Object bus) | |||
| 1060 | /* Retrieve bus address. */ | 1089 | /* Retrieve bus address. */ |
| 1061 | connection = xd_get_connection_address (bus); | 1090 | connection = xd_get_connection_address (bus); |
| 1062 | 1091 | ||
| 1063 | /* Close connection, if there isn't another shared application. */ | ||
| 1064 | if (xd_get_connection_references (connection) == 1) | 1092 | if (xd_get_connection_references (connection) == 1) |
| 1065 | { | 1093 | { |
| 1094 | /* Close connection, if there isn't another shared application. */ | ||
| 1066 | XD_DEBUG_MESSAGE ("Close connection to bus %s", | 1095 | XD_DEBUG_MESSAGE ("Close connection to bus %s", |
| 1067 | XD_OBJECT_TO_STRING (bus)); | 1096 | XD_OBJECT_TO_STRING (bus)); |
| 1068 | dbus_connection_close (connection); | 1097 | dbus_connection_close (connection); |
| 1069 | } | ||
| 1070 | 1098 | ||
| 1071 | /* Decrement reference count. */ | 1099 | xd_registered_buses = Fdelete (val, xd_registered_buses); |
| 1072 | dbus_connection_unref (connection); | 1100 | } |
| 1073 | 1101 | ||
| 1074 | /* Remove bus from list of registered buses. */ | 1102 | else |
| 1075 | xd_registered_buses = Fdelete (val, xd_registered_buses); | 1103 | /* Decrement reference count. */ |
| 1104 | dbus_connection_unref (connection); | ||
| 1076 | 1105 | ||
| 1077 | /* Return. */ | 1106 | /* Return. */ |
| 1078 | return; | 1107 | return; |
| @@ -1113,65 +1142,76 @@ this connection to those buses. */) | |||
| 1113 | /* Close bus if it is already open. */ | 1142 | /* Close bus if it is already open. */ |
| 1114 | xd_close_bus (bus); | 1143 | xd_close_bus (bus); |
| 1115 | 1144 | ||
| 1116 | /* Initialize. */ | 1145 | /* Check, whether we are still connected. */ |
| 1117 | dbus_error_init (&derror); | 1146 | val = Fassoc (bus, xd_registered_buses); |
| 1118 | 1147 | if (!NILP (val)) | |
| 1119 | /* Open the connection. */ | 1148 | { |
| 1120 | if (STRINGP (bus)) | 1149 | connection = xd_get_connection_address (bus); |
| 1121 | if (NILP (private)) | 1150 | dbus_connection_ref (connection); |
| 1122 | connection = dbus_connection_open (SSDATA (bus), &derror); | 1151 | } |
| 1123 | else | ||
| 1124 | connection = dbus_connection_open_private (SSDATA (bus), &derror); | ||
| 1125 | 1152 | ||
| 1126 | else | 1153 | else |
| 1127 | if (NILP (private)) | 1154 | { |
| 1128 | connection = dbus_bus_get (EQ (bus, QCdbus_system_bus) | 1155 | /* Initialize. */ |
| 1129 | ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, | 1156 | dbus_error_init (&derror); |
| 1130 | &derror); | ||
| 1131 | else | ||
| 1132 | connection = dbus_bus_get_private (EQ (bus, QCdbus_system_bus) | ||
| 1133 | ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, | ||
| 1134 | &derror); | ||
| 1135 | |||
| 1136 | if (dbus_error_is_set (&derror)) | ||
| 1137 | XD_ERROR (derror); | ||
| 1138 | |||
| 1139 | if (connection == NULL) | ||
| 1140 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); | ||
| 1141 | 1157 | ||
| 1142 | /* If it is not the system or session bus, we must register | 1158 | /* Open the connection. */ |
| 1143 | ourselves. Otherwise, we have called dbus_bus_get, which has | 1159 | if (STRINGP (bus)) |
| 1144 | configured us to exit if the connection closes - we undo this | 1160 | if (NILP (private)) |
| 1145 | setting. */ | 1161 | connection = dbus_connection_open (SSDATA (bus), &derror); |
| 1146 | if (STRINGP (bus)) | 1162 | else |
| 1147 | dbus_bus_register (connection, &derror); | 1163 | connection = dbus_connection_open_private (SSDATA (bus), &derror); |
| 1148 | else | ||
| 1149 | dbus_connection_set_exit_on_disconnect (connection, FALSE); | ||
| 1150 | |||
| 1151 | if (dbus_error_is_set (&derror)) | ||
| 1152 | XD_ERROR (derror); | ||
| 1153 | |||
| 1154 | /* Add the watch functions. We pass also the bus as data, in order | ||
| 1155 | to distinguish between the buses in xd_remove_watch. */ | ||
| 1156 | if (!dbus_connection_set_watch_functions (connection, | ||
| 1157 | xd_add_watch, | ||
| 1158 | xd_remove_watch, | ||
| 1159 | xd_toggle_watch, | ||
| 1160 | SYMBOLP (bus) | ||
| 1161 | ? (void *) XSYMBOL (bus) | ||
| 1162 | : (void *) XSTRING (bus), | ||
| 1163 | NULL)) | ||
| 1164 | XD_SIGNAL1 (build_string ("Cannot add watch functions")); | ||
| 1165 | |||
| 1166 | /* Add bus to list of registered buses. */ | ||
| 1167 | XSETFASTINT (val, (intptr_t) connection); | ||
| 1168 | xd_registered_buses = Fcons (Fcons (bus, val), xd_registered_buses); | ||
| 1169 | |||
| 1170 | /* We do not want to abort. */ | ||
| 1171 | putenv ((char *) "DBUS_FATAL_WARNINGS=0"); | ||
| 1172 | 1164 | ||
| 1173 | /* Cleanup. */ | 1165 | else |
| 1174 | dbus_error_free (&derror); | 1166 | if (NILP (private)) |
| 1167 | connection = dbus_bus_get (EQ (bus, QCdbus_system_bus) | ||
| 1168 | ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, | ||
| 1169 | &derror); | ||
| 1170 | else | ||
| 1171 | connection = dbus_bus_get_private (EQ (bus, QCdbus_system_bus) | ||
| 1172 | ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, | ||
| 1173 | &derror); | ||
| 1174 | |||
| 1175 | if (dbus_error_is_set (&derror)) | ||
| 1176 | XD_ERROR (derror); | ||
| 1177 | |||
| 1178 | if (connection == NULL) | ||
| 1179 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); | ||
| 1180 | |||
| 1181 | /* If it is not the system or session bus, we must register | ||
| 1182 | ourselves. Otherwise, we have called dbus_bus_get, which has | ||
| 1183 | configured us to exit if the connection closes - we undo this | ||
| 1184 | setting. */ | ||
| 1185 | if (STRINGP (bus)) | ||
| 1186 | dbus_bus_register (connection, &derror); | ||
| 1187 | else | ||
| 1188 | dbus_connection_set_exit_on_disconnect (connection, FALSE); | ||
| 1189 | |||
| 1190 | if (dbus_error_is_set (&derror)) | ||
| 1191 | XD_ERROR (derror); | ||
| 1192 | |||
| 1193 | /* Add the watch functions. We pass also the bus as data, in | ||
| 1194 | order to distinguish between the buses in xd_remove_watch. */ | ||
| 1195 | if (!dbus_connection_set_watch_functions (connection, | ||
| 1196 | xd_add_watch, | ||
| 1197 | xd_remove_watch, | ||
| 1198 | xd_toggle_watch, | ||
| 1199 | SYMBOLP (bus) | ||
| 1200 | ? (void *) XSYMBOL (bus) | ||
| 1201 | : (void *) XSTRING (bus), | ||
| 1202 | NULL)) | ||
| 1203 | XD_SIGNAL1 (build_string ("Cannot add watch functions")); | ||
| 1204 | |||
| 1205 | /* Add bus to list of registered buses. */ | ||
| 1206 | XSETFASTINT (val, (intptr_t) connection); | ||
| 1207 | xd_registered_buses = Fcons (Fcons (bus, val), xd_registered_buses); | ||
| 1208 | |||
| 1209 | /* We do not want to abort. */ | ||
| 1210 | xputenv ("DBUS_FATAL_WARNINGS=0"); | ||
| 1211 | |||
| 1212 | /* Cleanup. */ | ||
| 1213 | dbus_error_free (&derror); | ||
| 1214 | } | ||
| 1175 | 1215 | ||
| 1176 | /* Return reference counter. */ | 1216 | /* Return reference counter. */ |
| 1177 | refcount = xd_get_connection_references (connection); | 1217 | refcount = xd_get_connection_references (connection); |
| @@ -1271,7 +1311,7 @@ usage: (dbus-message-internal &rest REST) */) | |||
| 1271 | } | 1311 | } |
| 1272 | else /* DBUS_MESSAGE_TYPE_METHOD_RETURN, DBUS_MESSAGE_TYPE_ERROR */ | 1312 | else /* DBUS_MESSAGE_TYPE_METHOD_RETURN, DBUS_MESSAGE_TYPE_ERROR */ |
| 1273 | { | 1313 | { |
| 1274 | serial = extract_unsigned (args[3], TYPE_MAXIMUM (dbus_uint32_t)); | 1314 | serial = xd_extract_unsigned (args[3], TYPE_MAXIMUM (dbus_uint32_t)); |
| 1275 | count = 4; | 1315 | count = 4; |
| 1276 | } | 1316 | } |
| 1277 | 1317 | ||
| @@ -1657,7 +1697,7 @@ xd_read_message (Lisp_Object bus) | |||
| 1657 | 1697 | ||
| 1658 | /* Callback called when something is ready to read or write. */ | 1698 | /* Callback called when something is ready to read or write. */ |
| 1659 | static void | 1699 | static void |
| 1660 | xd_read_queued_messages (int fd, void *data, int for_read) | 1700 | xd_read_queued_messages (int fd, void *data) |
| 1661 | { | 1701 | { |
| 1662 | Lisp_Object busp = xd_registered_buses; | 1702 | Lisp_Object busp = xd_registered_buses; |
| 1663 | Lisp_Object bus = Qnil; | 1703 | Lisp_Object bus = Qnil; |
| @@ -1701,7 +1741,7 @@ syms_of_dbusbind (void) | |||
| 1701 | Fput (Qdbus_error, Qerror_conditions, | 1741 | Fput (Qdbus_error, Qerror_conditions, |
| 1702 | list2 (Qdbus_error, Qerror)); | 1742 | list2 (Qdbus_error, Qerror)); |
| 1703 | Fput (Qdbus_error, Qerror_message, | 1743 | Fput (Qdbus_error, Qerror_message, |
| 1704 | make_pure_c_string ("D-Bus error")); | 1744 | build_pure_c_string ("D-Bus error")); |
| 1705 | 1745 | ||
| 1706 | DEFSYM (QCdbus_system_bus, ":system"); | 1746 | DEFSYM (QCdbus_system_bus, ":system"); |
| 1707 | DEFSYM (QCdbus_session_bus, ":session"); | 1747 | DEFSYM (QCdbus_session_bus, ":session"); |
| @@ -1733,7 +1773,7 @@ syms_of_dbusbind (void) | |||
| 1733 | Vdbus_compiled_version, | 1773 | Vdbus_compiled_version, |
| 1734 | doc: /* The version of D-Bus Emacs is compiled against. */); | 1774 | doc: /* The version of D-Bus Emacs is compiled against. */); |
| 1735 | #ifdef DBUS_VERSION_STRING | 1775 | #ifdef DBUS_VERSION_STRING |
| 1736 | Vdbus_compiled_version = make_pure_c_string (DBUS_VERSION_STRING); | 1776 | Vdbus_compiled_version = build_pure_c_string (DBUS_VERSION_STRING); |
| 1737 | #else | 1777 | #else |
| 1738 | Vdbus_compiled_version = Qnil; | 1778 | Vdbus_compiled_version = Qnil; |
| 1739 | #endif | 1779 | #endif |
| @@ -1746,8 +1786,8 @@ syms_of_dbusbind (void) | |||
| 1746 | int major, minor, micro; | 1786 | int major, minor, micro; |
| 1747 | char s[sizeof ".." + 3 * INT_STRLEN_BOUND (int)]; | 1787 | char s[sizeof ".." + 3 * INT_STRLEN_BOUND (int)]; |
| 1748 | dbus_get_version (&major, &minor, µ); | 1788 | dbus_get_version (&major, &minor, µ); |
| 1749 | sprintf (s, "%d.%d.%d", major, minor, micro); | 1789 | Vdbus_runtime_version |
| 1750 | Vdbus_runtime_version = build_string (s); | 1790 | = make_formatted_string (s, "%d.%d.%d", major, minor, micro); |
| 1751 | #else | 1791 | #else |
| 1752 | Vdbus_runtime_version = Qnil; | 1792 | Vdbus_runtime_version = Qnil; |
| 1753 | #endif | 1793 | #endif |