aboutsummaryrefslogtreecommitdiffstats
path: root/src/dbusbind.c
diff options
context:
space:
mode:
authorMichael Albinus2008-01-04 21:39:47 +0000
committerMichael Albinus2008-01-04 21:39:47 +0000
commitabe136eecdfa666e748e1d668066a4f9d1529af8 (patch)
treee828db52ac42fb42f2d3cfd6dd067b0d273c048b /src/dbusbind.c
parentd8981dafd6a910520805addd3cff186df78fd9cd (diff)
downloademacs-abe136eecdfa666e748e1d668066a4f9d1529af8.tar.gz
emacs-abe136eecdfa666e748e1d668066a4f9d1529af8.zip
* dbusbind.c (Fdbus_method_return): New function.
(xd_read_message): Add the serial number to the event. (Fdbus_register_method): Activate the function.
Diffstat (limited to 'src/dbusbind.c')
-rw-r--r--src/dbusbind.c108
1 files changed, 100 insertions, 8 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 9afa62ae790..136cea9adb4 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -33,6 +33,7 @@ Boston, MA 02110-1301, USA. */
33/* Subroutines. */ 33/* Subroutines. */
34Lisp_Object Qdbus_get_unique_name; 34Lisp_Object Qdbus_get_unique_name;
35Lisp_Object Qdbus_call_method; 35Lisp_Object Qdbus_call_method;
36Lisp_Object Qdbus_method_return;
36Lisp_Object Qdbus_send_signal; 37Lisp_Object Qdbus_send_signal;
37Lisp_Object Qdbus_register_signal; 38Lisp_Object Qdbus_register_signal;
38Lisp_Object Qdbus_register_method; 39Lisp_Object Qdbus_register_method;
@@ -841,7 +842,7 @@ usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &rest ARGS) */)
841 if (XD_DBUS_TYPE_P (args[i])) 842 if (XD_DBUS_TYPE_P (args[i]))
842 ++i; 843 ++i;
843 844
844 /* Check for valid signature. We use DBUS_TYPE_INVALID is 845 /* Check for valid signature. We use DBUS_TYPE_INVALID as
845 indication that there is no parent type. */ 846 indication that there is no parent type. */
846 xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]); 847 xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]);
847 848
@@ -894,6 +895,92 @@ usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &rest ARGS) */)
894 RETURN_UNGCPRO (Fnreverse (result)); 895 RETURN_UNGCPRO (Fnreverse (result));
895} 896}
896 897
898DEFUN ("dbus-method-return", Fdbus_method_return, Sdbus_method_return,
899 3, MANY, 0,
900 doc: /* Return to method SERIAL on the D-Bus BUS.
901This is an internal function, it shall not be used outside dbus.el.
902
903usage: (dbus-method-return BUS SERIAL SERVICE &rest ARGS) */)
904 (nargs, args)
905 int nargs;
906 register Lisp_Object *args;
907{
908 Lisp_Object bus, serial, service;
909 struct gcpro gcpro1, gcpro2, gcpro3;
910 DBusConnection *connection;
911 DBusMessage *dmessage;
912 DBusMessageIter iter;
913 unsigned int dtype;
914 int i;
915 char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
916
917 /* Check parameters. */
918 bus = args[0];
919 serial = args[1];
920 service = args[2];
921
922 CHECK_SYMBOL (bus);
923 CHECK_NUMBER (serial);
924 CHECK_STRING (service);
925 GCPRO3 (bus, serial, service);
926
927 XD_DEBUG_MESSAGE ("%d %s ", XUINT (serial), SDATA (service));
928
929 /* Open a connection to the bus. */
930 connection = xd_initialize (bus);
931
932 /* Create the message. */
933 dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_RETURN);
934 if ((dmessage == NULL)
935 || (!dbus_message_set_reply_serial (dmessage, XUINT (serial)))
936 || (!dbus_message_set_destination (dmessage, SDATA (service))))
937 {
938 UNGCPRO;
939 xsignal1 (Qdbus_error,
940 build_string ("Unable to create a return message"));
941 }
942
943 UNGCPRO;
944
945 /* Initialize parameter list of message. */
946 dbus_message_iter_init_append (dmessage, &iter);
947
948 /* Append parameters to the message. */
949 for (i = 3; i < nargs; ++i)
950 {
951
952 XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
953 XD_DEBUG_MESSAGE ("Parameter%d %s",
954 i-2, SDATA (format2 ("%s", args[i], Qnil)));
955
956 dtype = XD_OBJECT_TO_DBUS_TYPE (args[i]);
957 if (XD_DBUS_TYPE_P (args[i]))
958 ++i;
959
960 /* Check for valid signature. We use DBUS_TYPE_INVALID as
961 indication that there is no parent type. */
962 xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]);
963
964 xd_append_arg (dtype, args[i], &iter);
965 }
966
967 /* Send the message. The message is just added to the outgoing
968 message queue. */
969 if (!dbus_connection_send (connection, dmessage, NULL))
970 xsignal1 (Qdbus_error, build_string ("Cannot send message"));
971
972 /* Flush connection to ensure the message is handled. */
973 dbus_connection_flush (connection);
974
975 XD_DEBUG_MESSAGE ("Message sent");
976
977 /* Cleanup. */
978 dbus_message_unref (dmessage);
979
980 /* Return. */
981 return Qt;
982}
983
897DEFUN ("dbus-send-signal", Fdbus_send_signal, Sdbus_send_signal, 5, MANY, 0, 984DEFUN ("dbus-send-signal", Fdbus_send_signal, Sdbus_send_signal, 5, MANY, 0,
898 doc: /* Send signal SIGNAL on the D-Bus BUS. 985 doc: /* Send signal SIGNAL on the D-Bus BUS.
899 986
@@ -985,7 +1072,7 @@ usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */)
985 if (XD_DBUS_TYPE_P (args[i])) 1072 if (XD_DBUS_TYPE_P (args[i]))
986 ++i; 1073 ++i;
987 1074
988 /* Check for valid signature. We use DBUS_TYPE_INVALID is 1075 /* Check for valid signature. We use DBUS_TYPE_INVALID as
989 indication that there is no parent type. */ 1076 indication that there is no parent type. */
990 xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]); 1077 xd_signature (signature, dtype, DBUS_TYPE_INVALID, args[i]);
991 1078
@@ -1103,6 +1190,12 @@ xd_read_message (bus)
1103 event.arg = Fcons ((uname == NULL ? Qnil : build_string (uname)), 1190 event.arg = Fcons ((uname == NULL ? Qnil : build_string (uname)),
1104 event.arg); 1191 event.arg);
1105 1192
1193 /* Add the message serial if needed, or nil. */
1194 event.arg = Fcons ((mtype == DBUS_MESSAGE_TYPE_METHOD_CALL
1195 ? make_number (dbus_message_get_serial (dmessage))
1196 : Qnil),
1197 event.arg);
1198
1106 /* Add the bus symbol to the event. */ 1199 /* Add the bus symbol to the event. */
1107 event.arg = Fcons (bus, event.arg); 1200 event.arg = Fcons (bus, event.arg);
1108 1201
@@ -1255,9 +1348,7 @@ PATH is the D-Bus object path SERVICE is registered. INTERFACE is the
1255interface offered by SERVICE. It must provide METHOD. HANDLER is a 1348interface offered by SERVICE. It must provide METHOD. HANDLER is a
1256Lisp function to be called when a method call is received. It must 1349Lisp function to be called when a method call is received. It must
1257accept the input arguments of METHOD. The return value of HANDLER is 1350accept the input arguments of METHOD. The return value of HANDLER is
1258used for composing the returning D-Bus message. 1351used for composing the returning D-Bus message. */)
1259
1260The function is not fully implemented and documented. Don't use it. */)
1261 (bus, service, path, interface, method, handler) 1352 (bus, service, path, interface, method, handler)
1262 Lisp_Object bus, service, path, interface, method, handler; 1353 Lisp_Object bus, service, path, interface, method, handler;
1263{ 1354{
@@ -1266,9 +1357,6 @@ The function is not fully implemented and documented. Don't use it. */)
1266 int result; 1357 int result;
1267 DBusError derror; 1358 DBusError derror;
1268 1359
1269 if (NILP (Vdbus_debug))
1270 xsignal1 (Qdbus_error, build_string ("Not implemented yet"));
1271
1272 /* Check parameters. */ 1360 /* Check parameters. */
1273 CHECK_SYMBOL (bus); 1361 CHECK_SYMBOL (bus);
1274 CHECK_STRING (service); 1362 CHECK_STRING (service);
@@ -1367,6 +1455,10 @@ syms_of_dbusbind ()
1367 staticpro (&Qdbus_call_method); 1455 staticpro (&Qdbus_call_method);
1368 defsubr (&Sdbus_call_method); 1456 defsubr (&Sdbus_call_method);
1369 1457
1458 Qdbus_method_return = intern ("dbus-method-return");
1459 staticpro (&Qdbus_method_return);
1460 defsubr (&Sdbus_method_return);
1461
1370 Qdbus_send_signal = intern ("dbus-send-signal"); 1462 Qdbus_send_signal = intern ("dbus-send-signal");
1371 staticpro (&Qdbus_send_signal); 1463 staticpro (&Qdbus_send_signal);
1372 defsubr (&Sdbus_send_signal); 1464 defsubr (&Sdbus_send_signal);