diff options
| author | Michael Albinus | 2008-07-31 18:56:51 +0000 |
|---|---|---|
| committer | Michael Albinus | 2008-07-31 18:56:51 +0000 |
| commit | 13ecc6dc5310a953887b5c22cb51b3ff6f716da7 (patch) | |
| tree | f45e6224891045e6a68109dbe42480a93ec72f9f /src/dbusbind.c | |
| parent | 21956b56a583d669cce2ef8967a80f4918e484d7 (diff) | |
| download | emacs-13ecc6dc5310a953887b5c22cb51b3ff6f716da7.tar.gz emacs-13ecc6dc5310a953887b5c22cb51b3ff6f716da7.zip | |
* dbusbind.c (Fdbus_call_method_asynchronously)
(Fdbus_method_error_internal): New defuns.
(xd_read_message): Handle also reply messages.
(Vdbus_registered_functions_table): Extend docstring.
Diffstat (limited to 'src/dbusbind.c')
| -rw-r--r-- | src/dbusbind.c | 428 |
1 files changed, 372 insertions, 56 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c index eec91c00b4a..21e3f83a509 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -31,7 +31,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 31 | /* Subroutines. */ | 31 | /* Subroutines. */ |
| 32 | Lisp_Object Qdbus_get_unique_name; | 32 | Lisp_Object Qdbus_get_unique_name; |
| 33 | Lisp_Object Qdbus_call_method; | 33 | Lisp_Object Qdbus_call_method; |
| 34 | Lisp_Object Qdbus_call_method_asynchronously; | ||
| 34 | Lisp_Object Qdbus_method_return_internal; | 35 | Lisp_Object Qdbus_method_return_internal; |
| 36 | Lisp_Object Qdbus_method_error_internal; | ||
| 35 | Lisp_Object Qdbus_send_signal; | 37 | Lisp_Object Qdbus_send_signal; |
| 36 | Lisp_Object Qdbus_register_signal; | 38 | Lisp_Object Qdbus_register_signal; |
| 37 | Lisp_Object Qdbus_register_method; | 39 | Lisp_Object Qdbus_register_method; |
| @@ -920,6 +922,163 @@ usage: (dbus-call-method | |||
| 920 | RETURN_UNGCPRO (Fnreverse (result)); | 922 | RETURN_UNGCPRO (Fnreverse (result)); |
| 921 | } | 923 | } |
| 922 | 924 | ||
| 925 | DEFUN ("dbus-call-method-asynchronously", Fdbus_call_method_asynchronously, | ||
| 926 | Sdbus_call_method_asynchronously, 6, MANY, 0, | ||
| 927 | doc: /* Call METHOD on the D-Bus BUS asynchronously. | ||
| 928 | |||
| 929 | BUS is either the symbol `:system' or the symbol `:session'. | ||
| 930 | |||
| 931 | SERVICE is the D-Bus service name to be used. PATH is the D-Bus | ||
| 932 | object path SERVICE is registered at. INTERFACE is an interface | ||
| 933 | offered by SERVICE. It must provide METHOD. | ||
| 934 | |||
| 935 | HANDLER is a Lisp function, which is called when the corresponding | ||
| 936 | return message has arrived. | ||
| 937 | |||
| 938 | If the parameter `:timeout' is given, the following integer TIMEOUT | ||
| 939 | specifies the maximun number of milliseconds the method call must | ||
| 940 | return. The default value is 25.000. If the method call doesn't | ||
| 941 | return in time, a D-Bus error is raised. | ||
| 942 | |||
| 943 | All other arguments ARGS are passed to METHOD as arguments. They are | ||
| 944 | converted into D-Bus types via the following rules: | ||
| 945 | |||
| 946 | t and nil => DBUS_TYPE_BOOLEAN | ||
| 947 | number => DBUS_TYPE_UINT32 | ||
| 948 | integer => DBUS_TYPE_INT32 | ||
| 949 | float => DBUS_TYPE_DOUBLE | ||
| 950 | string => DBUS_TYPE_STRING | ||
| 951 | list => DBUS_TYPE_ARRAY | ||
| 952 | |||
| 953 | All arguments can be preceded by a type symbol. For details about | ||
| 954 | type symbols, see Info node `(dbus)Type Conversion'. | ||
| 955 | |||
| 956 | The function returns a key into the hash table | ||
| 957 | `dbus-registered-functions-table'. The corresponding entry in the | ||
| 958 | hash table is removed, when the return message has been arrived, and | ||
| 959 | HANDLER is called. | ||
| 960 | |||
| 961 | Example: | ||
| 962 | |||
| 963 | \(dbus-call-method-asynchronously | ||
| 964 | :system "org.freedesktop.Hal" "/org/freedesktop/Hal/devices/computer" | ||
| 965 | "org.freedesktop.Hal.Device" "GetPropertyString" 'message | ||
| 966 | "system.kernel.machine") | ||
| 967 | |||
| 968 | => (:system 2) | ||
| 969 | |||
| 970 | -| i686 | ||
| 971 | |||
| 972 | usage: (dbus-call-method-asynchronously | ||
| 973 | BUS SERVICE PATH INTERFACE METHOD HANDLER | ||
| 974 | &optional :timeout TIMEOUT &rest ARGS) */) | ||
| 975 | (nargs, args) | ||
| 976 | int nargs; | ||
| 977 | register Lisp_Object *args; | ||
| 978 | { | ||
| 979 | Lisp_Object bus, service, path, interface, method, handler; | ||
| 980 | Lisp_Object result; | ||
| 981 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; | ||
| 982 | DBusConnection *connection; | ||
| 983 | DBusMessage *dmessage; | ||
| 984 | DBusMessageIter iter; | ||
| 985 | unsigned int dtype; | ||
| 986 | int timeout = -1; | ||
| 987 | int i = 6; | ||
| 988 | char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; | ||
| 989 | |||
| 990 | /* Check parameters. */ | ||
| 991 | bus = args[0]; | ||
| 992 | service = args[1]; | ||
| 993 | path = args[2]; | ||
| 994 | interface = args[3]; | ||
| 995 | method = args[4]; | ||
| 996 | handler = args[5]; | ||
| 997 | |||
| 998 | CHECK_SYMBOL (bus); | ||
| 999 | CHECK_STRING (service); | ||
| 1000 | CHECK_STRING (path); | ||
| 1001 | CHECK_STRING (interface); | ||
| 1002 | CHECK_STRING (method); | ||
| 1003 | if (!FUNCTIONP (handler)) | ||
| 1004 | wrong_type_argument (intern ("functionp"), handler); | ||
| 1005 | GCPRO6 (bus, service, path, interface, method, handler); | ||
| 1006 | |||
| 1007 | XD_DEBUG_MESSAGE ("%s %s %s %s", | ||
| 1008 | SDATA (service), | ||
| 1009 | SDATA (path), | ||
| 1010 | SDATA (interface), | ||
| 1011 | SDATA (method)); | ||
| 1012 | |||
| 1013 | /* Open a connection to the bus. */ | ||
| 1014 | connection = xd_initialize (bus); | ||
| 1015 | |||
| 1016 | /* Create the message. */ | ||
| 1017 | dmessage = dbus_message_new_method_call (SDATA (service), | ||
| 1018 | SDATA (path), | ||
| 1019 | SDATA (interface), | ||
| 1020 | SDATA (method)); | ||
| 1021 | if (dmessage == NULL) | ||
| 1022 | xsignal1 (Qdbus_error, build_string ("Unable to create a new message")); | ||
| 1023 | |||
| 1024 | /* Check for timeout parameter. */ | ||
| 1025 | if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout))) | ||
| 1026 | { | ||
| 1027 | CHECK_NATNUM (args[i+1]); | ||
| 1028 | timeout = XUINT (args[i+1]); | ||
| 1029 | i = i+2; | ||
| 1030 | } | ||
| 1031 | |||
| 1032 | /* Initialize parameter list of message. */ | ||
| 1033 | dbus_message_iter_init_append (dmessage, &iter); | ||
| 1034 | |||
| 1035 | /* Append parameters to the message. */ | ||
| 1036 | for (; i < nargs; ++i) | ||
| 1037 | { | ||
| 1038 | dtype = XD_OBJECT_TO_DBUS_TYPE (args[i]); | ||
| 1039 | if (XD_DBUS_TYPE_P (args[i])) | ||
| 1040 | { | ||
| 1041 | XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); | ||
| 1042 | XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]); | ||
| 1043 | XD_DEBUG_MESSAGE ("Parameter%d %s %s", i-4, | ||
| 1044 | SDATA (format2 ("%s", args[i], Qnil)), | ||
| 1045 | SDATA (format2 ("%s", args[i+1], Qnil))); | ||
| 1046 | ++i; | ||
| 1047 | } | ||
| 1048 | else | ||
| 1049 | { | ||
| 1050 | XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); | ||
| 1051 | XD_DEBUG_MESSAGE ("Parameter%d %s", i-4, | ||
| 1052 | SDATA (format2 ("%s", args[i], Qnil))); | ||
| 1053 | } | ||
| 1054 | |||
| 1055 | /* Check for valid signature. We use DBUS_TYPE_INVALID as | ||
| 1056 | indication that there is no parent type. */ | ||
| 1057 | xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]); | ||
| 1058 | |||
| 1059 | xd_append_arg (dtype, args[i], &iter); | ||
| 1060 | } | ||
| 1061 | |||
| 1062 | /* Send the message. The message is just added to the outgoing | ||
| 1063 | message queue. */ | ||
| 1064 | if (!dbus_connection_send_with_reply (connection, dmessage, NULL, timeout)) | ||
| 1065 | xsignal1 (Qdbus_error, build_string ("Cannot send message")); | ||
| 1066 | |||
| 1067 | XD_DEBUG_MESSAGE ("Message sent"); | ||
| 1068 | |||
| 1069 | /* The result is the key in Vdbus_registered_functions_table. */ | ||
| 1070 | result = (list2 (bus, make_number (dbus_message_get_serial (dmessage)))); | ||
| 1071 | |||
| 1072 | /* Create a hash table entry. */ | ||
| 1073 | Fputhash (result, handler, Vdbus_registered_functions_table); | ||
| 1074 | |||
| 1075 | /* Cleanup. */ | ||
| 1076 | dbus_message_unref (dmessage); | ||
| 1077 | |||
| 1078 | /* Return the result. */ | ||
| 1079 | RETURN_UNGCPRO (result); | ||
| 1080 | } | ||
| 1081 | |||
| 923 | DEFUN ("dbus-method-return-internal", Fdbus_method_return_internal, | 1082 | DEFUN ("dbus-method-return-internal", Fdbus_method_return_internal, |
| 924 | Sdbus_method_return_internal, | 1083 | Sdbus_method_return_internal, |
| 925 | 3, MANY, 0, | 1084 | 3, MANY, 0, |
| @@ -1015,6 +1174,102 @@ usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */) | |||
| 1015 | return Qt; | 1174 | return Qt; |
| 1016 | } | 1175 | } |
| 1017 | 1176 | ||
| 1177 | DEFUN ("dbus-method-error-internal", Fdbus_method_error_internal, | ||
| 1178 | Sdbus_method_error_internal, | ||
| 1179 | 3, MANY, 0, | ||
| 1180 | doc: /* Return error message for message SERIAL on the D-Bus BUS. | ||
| 1181 | This is an internal function, it shall not be used outside dbus.el. | ||
| 1182 | |||
| 1183 | usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */) | ||
| 1184 | (nargs, args) | ||
| 1185 | int nargs; | ||
| 1186 | register Lisp_Object *args; | ||
| 1187 | { | ||
| 1188 | Lisp_Object bus, serial, service; | ||
| 1189 | struct gcpro gcpro1, gcpro2, gcpro3; | ||
| 1190 | DBusConnection *connection; | ||
| 1191 | DBusMessage *dmessage; | ||
| 1192 | DBusMessageIter iter; | ||
| 1193 | unsigned int dtype; | ||
| 1194 | int i; | ||
| 1195 | char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH]; | ||
| 1196 | |||
| 1197 | /* Check parameters. */ | ||
| 1198 | bus = args[0]; | ||
| 1199 | serial = args[1]; | ||
| 1200 | service = args[2]; | ||
| 1201 | |||
| 1202 | CHECK_SYMBOL (bus); | ||
| 1203 | CHECK_NUMBER (serial); | ||
| 1204 | CHECK_STRING (service); | ||
| 1205 | GCPRO3 (bus, serial, service); | ||
| 1206 | |||
| 1207 | XD_DEBUG_MESSAGE ("%d %s ", XUINT (serial), SDATA (service)); | ||
| 1208 | |||
| 1209 | /* Open a connection to the bus. */ | ||
| 1210 | connection = xd_initialize (bus); | ||
| 1211 | |||
| 1212 | /* Create the message. */ | ||
| 1213 | dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR); | ||
| 1214 | if ((dmessage == NULL) | ||
| 1215 | || (!dbus_message_set_error_name (dmessage, DBUS_ERROR_FAILED)) | ||
| 1216 | || (!dbus_message_set_reply_serial (dmessage, XUINT (serial))) | ||
| 1217 | || (!dbus_message_set_destination (dmessage, SDATA (service)))) | ||
| 1218 | { | ||
| 1219 | UNGCPRO; | ||
| 1220 | xsignal1 (Qdbus_error, | ||
| 1221 | build_string ("Unable to create a error message")); | ||
| 1222 | } | ||
| 1223 | |||
| 1224 | UNGCPRO; | ||
| 1225 | |||
| 1226 | /* Initialize parameter list of message. */ | ||
| 1227 | dbus_message_iter_init_append (dmessage, &iter); | ||
| 1228 | |||
| 1229 | /* Append parameters to the message. */ | ||
| 1230 | for (i = 3; i < nargs; ++i) | ||
| 1231 | { | ||
| 1232 | dtype = XD_OBJECT_TO_DBUS_TYPE (args[i]); | ||
| 1233 | if (XD_DBUS_TYPE_P (args[i])) | ||
| 1234 | { | ||
| 1235 | XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); | ||
| 1236 | XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]); | ||
| 1237 | XD_DEBUG_MESSAGE ("Parameter%d %s %s", i-2, | ||
| 1238 | SDATA (format2 ("%s", args[i], Qnil)), | ||
| 1239 | SDATA (format2 ("%s", args[i+1], Qnil))); | ||
| 1240 | ++i; | ||
| 1241 | } | ||
| 1242 | else | ||
| 1243 | { | ||
| 1244 | XD_DEBUG_VALID_LISP_OBJECT_P (args[i]); | ||
| 1245 | XD_DEBUG_MESSAGE ("Parameter%d %s", i-2, | ||
| 1246 | SDATA (format2 ("%s", args[i], Qnil))); | ||
| 1247 | } | ||
| 1248 | |||
| 1249 | /* Check for valid signature. We use DBUS_TYPE_INVALID as | ||
| 1250 | indication that there is no parent type. */ | ||
| 1251 | xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]); | ||
| 1252 | |||
| 1253 | xd_append_arg (dtype, args[i], &iter); | ||
| 1254 | } | ||
| 1255 | |||
| 1256 | /* Send the message. The message is just added to the outgoing | ||
| 1257 | message queue. */ | ||
| 1258 | if (!dbus_connection_send (connection, dmessage, NULL)) | ||
| 1259 | xsignal1 (Qdbus_error, build_string ("Cannot send message")); | ||
| 1260 | |||
| 1261 | /* Flush connection to ensure the message is handled. */ | ||
| 1262 | dbus_connection_flush (connection); | ||
| 1263 | |||
| 1264 | XD_DEBUG_MESSAGE ("Message sent"); | ||
| 1265 | |||
| 1266 | /* Cleanup. */ | ||
| 1267 | dbus_message_unref (dmessage); | ||
| 1268 | |||
| 1269 | /* Return. */ | ||
| 1270 | return Qt; | ||
| 1271 | } | ||
| 1272 | |||
| 1018 | DEFUN ("dbus-send-signal", Fdbus_send_signal, Sdbus_send_signal, 5, MANY, 0, | 1273 | DEFUN ("dbus-send-signal", Fdbus_send_signal, Sdbus_send_signal, 5, MANY, 0, |
| 1019 | doc: /* Send signal SIGNAL on the D-Bus BUS. | 1274 | doc: /* Send signal SIGNAL on the D-Bus BUS. |
| 1020 | 1275 | ||
| @@ -1148,7 +1403,7 @@ xd_read_message (bus) | |||
| 1148 | DBusMessage *dmessage; | 1403 | DBusMessage *dmessage; |
| 1149 | DBusMessageIter iter; | 1404 | DBusMessageIter iter; |
| 1150 | unsigned int dtype; | 1405 | unsigned int dtype; |
| 1151 | int mtype; | 1406 | int mtype, serial; |
| 1152 | const char *uname, *path, *interface, *member; | 1407 | const char *uname, *path, *interface, *member; |
| 1153 | 1408 | ||
| 1154 | /* Open a connection to the bus. */ | 1409 | /* Open a connection to the bus. */ |
| @@ -1179,69 +1434,111 @@ xd_read_message (bus) | |||
| 1179 | args = Fnreverse (args); | 1434 | args = Fnreverse (args); |
| 1180 | } | 1435 | } |
| 1181 | 1436 | ||
| 1182 | /* Read message type, unique name, object path, interface and member | 1437 | /* Read message type, message serial, unique name, object path, |
| 1183 | from the message. */ | 1438 | interface and member from the message. */ |
| 1184 | mtype = dbus_message_get_type (dmessage); | 1439 | mtype = dbus_message_get_type (dmessage); |
| 1440 | serial = (mtype == DBUS_MESSAGE_TYPE_METHOD_RETURN ? | ||
| 1441 | dbus_message_get_reply_serial (dmessage) : | ||
| 1442 | dbus_message_get_serial (dmessage)); | ||
| 1185 | uname = dbus_message_get_sender (dmessage); | 1443 | uname = dbus_message_get_sender (dmessage); |
| 1186 | path = dbus_message_get_path (dmessage); | 1444 | path = dbus_message_get_path (dmessage); |
| 1187 | interface = dbus_message_get_interface (dmessage); | 1445 | interface = dbus_message_get_interface (dmessage); |
| 1188 | member = dbus_message_get_member (dmessage); | 1446 | member = dbus_message_get_member (dmessage); |
| 1189 | 1447 | ||
| 1190 | /* Vdbus_registered_functions_table requires non-nil interface and member. */ | 1448 | XD_DEBUG_MESSAGE ("Event received: %s %d %s %s %s %s %s", |
| 1191 | if ((NULL == interface) || (NULL == member)) | 1449 | (mtype == DBUS_MESSAGE_TYPE_INVALID) ? |
| 1192 | goto cleanup; | 1450 | "DBUS_MESSAGE_TYPE_INVALID" : |
| 1193 | 1451 | (mtype == DBUS_MESSAGE_TYPE_METHOD_CALL) ? | |
| 1194 | XD_DEBUG_MESSAGE ("Event received: %d %s %s %s %s %s", | 1452 | "DBUS_MESSAGE_TYPE_METHOD_CALL" : |
| 1195 | mtype, uname, path, interface, member, | 1453 | (mtype == DBUS_MESSAGE_TYPE_METHOD_RETURN) ? |
| 1454 | "DBUS_MESSAGE_TYPE_METHOD_RETURN" : | ||
| 1455 | (mtype == DBUS_MESSAGE_TYPE_ERROR) ? | ||
| 1456 | "DBUS_MESSAGE_TYPE_METHOD_ERROR" : | ||
| 1457 | "DBUS_MESSAGE_TYPE_METHOD_SIGNAL", | ||
| 1458 | serial, uname, path, interface, member, | ||
| 1196 | SDATA (format2 ("%s", args, Qnil))); | 1459 | SDATA (format2 ("%s", args, Qnil))); |
| 1197 | 1460 | ||
| 1198 | /* Search for a registered function of the message. */ | 1461 | if (mtype == DBUS_MESSAGE_TYPE_METHOD_RETURN) |
| 1199 | key = list3 (bus, build_string (interface), build_string (member)); | 1462 | { |
| 1200 | value = Fgethash (key, Vdbus_registered_functions_table, Qnil); | 1463 | /* Search for a registered function of the message. */ |
| 1464 | key = list2 (bus, make_number (serial)); | ||
| 1465 | value = Fgethash (key, Vdbus_registered_functions_table, Qnil); | ||
| 1466 | |||
| 1467 | /* There shall be exactly one entry. Construct an event. */ | ||
| 1468 | if (NILP (value)) | ||
| 1469 | goto cleanup; | ||
| 1470 | |||
| 1471 | /* Remove the entry. */ | ||
| 1472 | Fremhash (key, Vdbus_registered_functions_table); | ||
| 1473 | |||
| 1474 | /* Construct an event. */ | ||
| 1475 | EVENT_INIT (event); | ||
| 1476 | event.kind = DBUS_EVENT; | ||
| 1477 | event.frame_or_window = Qnil; | ||
| 1478 | event.arg = Fcons (value, args); | ||
| 1479 | } | ||
| 1201 | 1480 | ||
| 1202 | /* Loop over the registered functions. Construct an event. */ | 1481 | else /* (mtype != DBUS_MESSAGE_TYPE_METHOD_RETURN) */ |
| 1203 | while (!NILP (value)) | ||
| 1204 | { | 1482 | { |
| 1205 | key = CAR_SAFE (value); | 1483 | /* Vdbus_registered_functions_table requires non-nil interface |
| 1206 | /* key has the structure (UNAME SERVICE PATH HANDLER). */ | 1484 | and member. */ |
| 1207 | if (((uname == NULL) | 1485 | if ((interface == NULL) || (member == NULL)) |
| 1208 | || (NILP (CAR_SAFE (key))) | 1486 | goto cleanup; |
| 1209 | || (strcmp (uname, SDATA (CAR_SAFE (key))) == 0)) | 1487 | |
| 1210 | && ((path == NULL) | 1488 | /* Search for a registered function of the message. */ |
| 1211 | || (NILP (CAR_SAFE (CDR_SAFE (CDR_SAFE (key))))) | 1489 | key = list3 (bus, build_string (interface), build_string (member)); |
| 1212 | || (strcmp (path, SDATA (CAR_SAFE (CDR_SAFE (CDR_SAFE (key))))) | 1490 | value = Fgethash (key, Vdbus_registered_functions_table, Qnil); |
| 1213 | == 0)) | 1491 | |
| 1214 | && (!NILP (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (key))))))) | 1492 | /* Loop over the registered functions. Construct an event. */ |
| 1493 | while (!NILP (value)) | ||
| 1215 | { | 1494 | { |
| 1216 | EVENT_INIT (event); | 1495 | key = CAR_SAFE (value); |
| 1217 | event.kind = DBUS_EVENT; | 1496 | /* key has the structure (UNAME SERVICE PATH HANDLER). */ |
| 1218 | event.frame_or_window = Qnil; | 1497 | if (((uname == NULL) |
| 1219 | event.arg = Fcons (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (key)))), | 1498 | || (NILP (CAR_SAFE (key))) |
| 1220 | args); | 1499 | || (strcmp (uname, SDATA (CAR_SAFE (key))) == 0)) |
| 1221 | 1500 | && ((path == NULL) | |
| 1222 | /* Add uname, path, interface and member to the event. */ | 1501 | || (NILP (CAR_SAFE (CDR_SAFE (CDR_SAFE (key))))) |
| 1223 | event.arg = Fcons (build_string (member), event.arg); | 1502 | || (strcmp (path, |
| 1224 | event.arg = Fcons (build_string (interface), event.arg); | 1503 | SDATA (CAR_SAFE (CDR_SAFE (CDR_SAFE (key))))) |
| 1225 | event.arg = Fcons ((path == NULL ? Qnil : build_string (path)), | 1504 | == 0)) |
| 1226 | event.arg); | 1505 | && (!NILP (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (key))))))) |
| 1227 | event.arg = Fcons ((uname == NULL ? Qnil : build_string (uname)), | 1506 | { |
| 1228 | event.arg); | 1507 | EVENT_INIT (event); |
| 1229 | 1508 | event.kind = DBUS_EVENT; | |
| 1230 | /* Add the message serial if needed, or nil. */ | 1509 | event.frame_or_window = Qnil; |
| 1231 | event.arg = Fcons ((mtype == DBUS_MESSAGE_TYPE_METHOD_CALL | 1510 | event.arg = Fcons (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (key)))), |
| 1232 | ? make_number (dbus_message_get_serial (dmessage)) | 1511 | args); |
| 1233 | : Qnil), | 1512 | break; |
| 1234 | event.arg); | 1513 | } |
| 1235 | 1514 | value = CDR_SAFE (value); | |
| 1236 | /* Add the bus symbol to the event. */ | ||
| 1237 | event.arg = Fcons (bus, event.arg); | ||
| 1238 | |||
| 1239 | /* Store it into the input event queue. */ | ||
| 1240 | kbd_buffer_store_event (&event); | ||
| 1241 | } | 1515 | } |
| 1242 | value = CDR_SAFE (value); | 1516 | |
| 1517 | if (NILP (value)) | ||
| 1518 | goto cleanup; | ||
| 1243 | } | 1519 | } |
| 1244 | 1520 | ||
| 1521 | /* Add type, serial, uname, path, interface and member to the event. */ | ||
| 1522 | event.arg = Fcons ((member == NULL ? Qnil : build_string (member)), | ||
| 1523 | event.arg); | ||
| 1524 | event.arg = Fcons ((interface == NULL ? Qnil : build_string (interface)), | ||
| 1525 | event.arg); | ||
| 1526 | event.arg = Fcons ((path == NULL ? Qnil : build_string (path)), | ||
| 1527 | event.arg); | ||
| 1528 | event.arg = Fcons ((uname == NULL ? Qnil : build_string (uname)), | ||
| 1529 | event.arg); | ||
| 1530 | event.arg = Fcons (make_number (serial), event.arg); | ||
| 1531 | event.arg = Fcons (make_number (mtype), event.arg); | ||
| 1532 | |||
| 1533 | /* Add the bus symbol to the event. */ | ||
| 1534 | event.arg = Fcons (bus, event.arg); | ||
| 1535 | |||
| 1536 | /* Store it into the input event queue. */ | ||
| 1537 | kbd_buffer_store_event (&event); | ||
| 1538 | |||
| 1539 | XD_DEBUG_MESSAGE ("Event stored: %s", | ||
| 1540 | SDATA (format2 ("%s", event.arg, Qnil))); | ||
| 1541 | |||
| 1245 | cleanup: | 1542 | cleanup: |
| 1246 | dbus_message_unref (dmessage); | 1543 | dbus_message_unref (dmessage); |
| 1247 | RETURN_UNGCPRO (Qnil); | 1544 | RETURN_UNGCPRO (Qnil); |
| @@ -1481,10 +1778,18 @@ syms_of_dbusbind () | |||
| 1481 | staticpro (&Qdbus_call_method); | 1778 | staticpro (&Qdbus_call_method); |
| 1482 | defsubr (&Sdbus_call_method); | 1779 | defsubr (&Sdbus_call_method); |
| 1483 | 1780 | ||
| 1781 | Qdbus_call_method_asynchronously = intern ("dbus-call-method-asynchronously"); | ||
| 1782 | staticpro (&Qdbus_call_method_asynchronously); | ||
| 1783 | defsubr (&Sdbus_call_method_asynchronously); | ||
| 1784 | |||
| 1484 | Qdbus_method_return_internal = intern ("dbus-method-return-internal"); | 1785 | Qdbus_method_return_internal = intern ("dbus-method-return-internal"); |
| 1485 | staticpro (&Qdbus_method_return_internal); | 1786 | staticpro (&Qdbus_method_return_internal); |
| 1486 | defsubr (&Sdbus_method_return_internal); | 1787 | defsubr (&Sdbus_method_return_internal); |
| 1487 | 1788 | ||
| 1789 | Qdbus_method_error_internal = intern ("dbus-method-error-internal"); | ||
| 1790 | staticpro (&Qdbus_method_error_internal); | ||
| 1791 | defsubr (&Sdbus_method_error_internal); | ||
| 1792 | |||
| 1488 | Qdbus_send_signal = intern ("dbus-send-signal"); | 1793 | Qdbus_send_signal = intern ("dbus-send-signal"); |
| 1489 | staticpro (&Qdbus_send_signal); | 1794 | staticpro (&Qdbus_send_signal); |
| 1490 | defsubr (&Sdbus_send_signal); | 1795 | defsubr (&Sdbus_send_signal); |
| @@ -1564,11 +1869,15 @@ syms_of_dbusbind () | |||
| 1564 | DEFVAR_LISP ("dbus-registered-functions-table", | 1869 | DEFVAR_LISP ("dbus-registered-functions-table", |
| 1565 | &Vdbus_registered_functions_table, | 1870 | &Vdbus_registered_functions_table, |
| 1566 | doc: /* Hash table of registered functions for D-Bus. | 1871 | doc: /* Hash table of registered functions for D-Bus. |
| 1567 | The key in the hash table is the list (BUS INTERFACE MEMBER). BUS is | 1872 | There are two different uses of the hash table: for calling registered |
| 1568 | either the symbol `:system' or the symbol `:session'. INTERFACE is a | 1873 | functions, targeted by signals or method calls, and for calling |
| 1569 | string which denotes a D-Bus interface, and MEMBER, also a string, is | 1874 | handlers in case of non-blocking method call returns. |
| 1570 | either a method or a signal INTERFACE is offering. All arguments but | 1875 | |
| 1571 | BUS must not be nil. | 1876 | In the first case, the key in the hash table is the list (BUS |
| 1877 | INTERFACE MEMBER). BUS is either the symbol `:system' or the symbol | ||
| 1878 | `:session'. INTERFACE is a string which denotes a D-Bus interface, | ||
| 1879 | and MEMBER, also a string, is either a method or a signal INTERFACE is | ||
| 1880 | offering. All arguments but BUS must not be nil. | ||
| 1572 | 1881 | ||
| 1573 | The value in the hash table is a list of quadruple lists | 1882 | The value in the hash table is a list of quadruple lists |
| 1574 | \((UNAME SERVICE PATH HANDLER) (UNAME SERVICE PATH HANDLER) ...). | 1883 | \((UNAME SERVICE PATH HANDLER) (UNAME SERVICE PATH HANDLER) ...). |
| @@ -1576,7 +1885,14 @@ SERVICE is the service name as registered, UNAME is the corresponding | |||
| 1576 | unique name. PATH is the object path of the sending object. All of | 1885 | unique name. PATH is the object path of the sending object. All of |
| 1577 | them can be nil, which means a wildcard then. HANDLER is the function | 1886 | them can be nil, which means a wildcard then. HANDLER is the function |
| 1578 | to be called when a D-Bus message, which matches the key criteria, | 1887 | to be called when a D-Bus message, which matches the key criteria, |
| 1579 | arrives. */); | 1888 | arrives. |
| 1889 | |||
| 1890 | In the second case, the key in the hash table is the list (BUS SERIAL). | ||
| 1891 | BUS is either the symbol `:system' or the symbol `:session'. SERIAL | ||
| 1892 | is the serial number of the non-blocking method call, a reply is | ||
| 1893 | expected. Both arguments must not be nil. The value in the hash | ||
| 1894 | table is HANDLER, the function to be called when the D-Bus reply | ||
| 1895 | message arrives. */); | ||
| 1580 | /* We initialize Vdbus_registered_functions_table in dbus.el, | 1896 | /* We initialize Vdbus_registered_functions_table in dbus.el, |
| 1581 | because we need to define a hash table function first. */ | 1897 | because we need to define a hash table function first. */ |
| 1582 | Vdbus_registered_functions_table = Qnil; | 1898 | Vdbus_registered_functions_table = Qnil; |