aboutsummaryrefslogtreecommitdiffstats
path: root/src/dbusbind.c
diff options
context:
space:
mode:
authorMichael Albinus2010-07-09 11:05:47 +0200
committerMichael Albinus2010-07-09 11:05:47 +0200
commit2536a4b7d8b7e662db3d54a9eb8fae63ceebfc14 (patch)
tree2c8d50d57ca38c624d1cb1a0badf513ac72ca0f5 /src/dbusbind.c
parentb88746ba3f819730cc761c3cc72a3c0ee523fb4f (diff)
downloademacs-2536a4b7d8b7e662db3d54a9eb8fae63ceebfc14.tar.gz
emacs-2536a4b7d8b7e662db3d54a9eb8fae63ceebfc14.zip
* dbusbind.c (xd_initialize): Add new argument RAISE_ERROR, which
allows to suppress errors when polling in Emacs' main loop. (Fdbus_init_bus, Fdbus_get_unique_name, Fdbus_call_method) (Fdbus_call_method_asynchronously, Fdbus_method_return_internal) (Fdbus_method_error_internal, Fdbus_send_signal) (xd_get_dispatch_status, xd_read_message, Fdbus_register_signal) (Fdbus_register_method): Use it. (Bug#6579)
Diffstat (limited to 'src/dbusbind.c')
-rw-r--r--src/dbusbind.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 005b04950b9..c5dbb62aed9 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -714,9 +714,11 @@ xd_retrieve_arg (unsigned int dtype, DBusMessageIter *iter)
714} 714}
715 715
716/* Initialize D-Bus connection. BUS is a Lisp symbol, either :system 716/* Initialize D-Bus connection. BUS is a Lisp symbol, either :system
717 or :session. It tells which D-Bus to be initialized. */ 717 or :session. It tells which D-Bus to be initialized. RAISE_ERROR
718 can be TRUE or FALSE, it controls whether an error is signalled in
719 case the connection cannot be initialized. */
718static DBusConnection * 720static DBusConnection *
719xd_initialize (Lisp_Object bus) 721xd_initialize (Lisp_Object bus, int raise_error)
720{ 722{
721 DBusConnection *connection; 723 DBusConnection *connection;
722 DBusError derror; 724 DBusError derror;
@@ -724,12 +726,18 @@ xd_initialize (Lisp_Object bus)
724 /* Parameter check. */ 726 /* Parameter check. */
725 CHECK_SYMBOL (bus); 727 CHECK_SYMBOL (bus);
726 if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus))) 728 if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus)))
727 XD_SIGNAL2 (build_string ("Wrong bus name"), bus); 729 if (raise_error == TRUE)
730 XD_SIGNAL2 (build_string ("Wrong bus name"), bus);
731 else
732 return NULL;
728 733
729 /* We do not want to have an autolaunch for the session bus. */ 734 /* We do not want to have an autolaunch for the session bus. */
730 if (EQ (bus, QCdbus_session_bus) 735 if (EQ (bus, QCdbus_session_bus)
731 && getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL) 736 && getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL)
732 XD_SIGNAL2 (build_string ("No connection to bus"), bus); 737 if (raise_error == TRUE)
738 XD_SIGNAL2 (build_string ("No connection to bus"), bus);
739 else
740 return NULL;
733 741
734 /* Open a connection to the bus. */ 742 /* Open a connection to the bus. */
735 dbus_error_init (&derror); 743 dbus_error_init (&derror);
@@ -740,9 +748,12 @@ xd_initialize (Lisp_Object bus)
740 connection = dbus_bus_get (DBUS_BUS_SESSION, &derror); 748 connection = dbus_bus_get (DBUS_BUS_SESSION, &derror);
741 749
742 if (dbus_error_is_set (&derror)) 750 if (dbus_error_is_set (&derror))
743 XD_ERROR (derror); 751 if (raise_error == TRUE)
752 XD_ERROR (derror);
753 else
754 connection = NULL;
744 755
745 if (connection == NULL) 756 if ((connection == NULL) && (raise_error == TRUE))
746 XD_SIGNAL2 (build_string ("No connection to bus"), bus); 757 XD_SIGNAL2 (build_string ("No connection to bus"), bus);
747 758
748 /* Cleanup. */ 759 /* Cleanup. */
@@ -829,7 +840,7 @@ This is an internal function, it shall not be used outside dbus.el. */)
829 CHECK_SYMBOL (bus); 840 CHECK_SYMBOL (bus);
830 841
831 /* Open a connection to the bus. */ 842 /* Open a connection to the bus. */
832 connection = xd_initialize (bus); 843 connection = xd_initialize (bus, TRUE);
833 844
834 /* Add the watch functions. We pass also the bus as data, in order 845 /* Add the watch functions. We pass also the bus as data, in order
835 to distinguish between the busses in xd_remove_watch. */ 846 to distinguish between the busses in xd_remove_watch. */
@@ -855,7 +866,7 @@ DEFUN ("dbus-get-unique-name", Fdbus_get_unique_name, Sdbus_get_unique_name,
855 CHECK_SYMBOL (bus); 866 CHECK_SYMBOL (bus);
856 867
857 /* Open a connection to the bus. */ 868 /* Open a connection to the bus. */
858 connection = xd_initialize (bus); 869 connection = xd_initialize (bus, TRUE);
859 870
860 /* Request the name. */ 871 /* Request the name. */
861 name = dbus_bus_get_unique_name (connection); 872 name = dbus_bus_get_unique_name (connection);
@@ -970,7 +981,7 @@ usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TI
970 SDATA (method)); 981 SDATA (method));
971 982
972 /* Open a connection to the bus. */ 983 /* Open a connection to the bus. */
973 connection = xd_initialize (bus); 984 connection = xd_initialize (bus, TRUE);
974 985
975 /* Create the message. */ 986 /* Create the message. */
976 dmessage = dbus_message_new_method_call (SDATA (service), 987 dmessage = dbus_message_new_method_call (SDATA (service),
@@ -1153,7 +1164,7 @@ usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLE
1153 SDATA (method)); 1164 SDATA (method));
1154 1165
1155 /* Open a connection to the bus. */ 1166 /* Open a connection to the bus. */
1156 connection = xd_initialize (bus); 1167 connection = xd_initialize (bus, TRUE);
1157 1168
1158 /* Create the message. */ 1169 /* Create the message. */
1159 dmessage = dbus_message_new_method_call (SDATA (service), 1170 dmessage = dbus_message_new_method_call (SDATA (service),
@@ -1268,7 +1279,7 @@ usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */)
1268 XD_DEBUG_MESSAGE ("%lu %s ", (unsigned long) XUINT (serial), SDATA (service)); 1279 XD_DEBUG_MESSAGE ("%lu %s ", (unsigned long) XUINT (serial), SDATA (service));
1269 1280
1270 /* Open a connection to the bus. */ 1281 /* Open a connection to the bus. */
1271 connection = xd_initialize (bus); 1282 connection = xd_initialize (bus, TRUE);
1272 1283
1273 /* Create the message. */ 1284 /* Create the message. */
1274 dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_RETURN); 1285 dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_RETURN);
@@ -1360,7 +1371,7 @@ usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */)
1360 XD_DEBUG_MESSAGE ("%lu %s ", (unsigned long) XUINT (serial), SDATA (service)); 1371 XD_DEBUG_MESSAGE ("%lu %s ", (unsigned long) XUINT (serial), SDATA (service));
1361 1372
1362 /* Open a connection to the bus. */ 1373 /* Open a connection to the bus. */
1363 connection = xd_initialize (bus); 1374 connection = xd_initialize (bus, TRUE);
1364 1375
1365 /* Create the message. */ 1376 /* Create the message. */
1366 dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR); 1377 dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
@@ -1483,7 +1494,7 @@ usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */)
1483 SDATA (signal)); 1494 SDATA (signal));
1484 1495
1485 /* Open a connection to the bus. */ 1496 /* Open a connection to the bus. */
1486 connection = xd_initialize (bus); 1497 connection = xd_initialize (bus, TRUE);
1487 1498
1488 /* Create the message. */ 1499 /* Create the message. */
1489 dmessage = dbus_message_new_signal (SDATA (path), 1500 dmessage = dbus_message_new_signal (SDATA (path),
@@ -1548,7 +1559,8 @@ xd_get_dispatch_status (Lisp_Object bus)
1548 DBusConnection *connection; 1559 DBusConnection *connection;
1549 1560
1550 /* Open a connection to the bus. */ 1561 /* Open a connection to the bus. */
1551 connection = xd_initialize (bus); 1562 connection = xd_initialize (bus, FALSE);
1563 if (connection == NULL) return FALSE;
1552 1564
1553 /* Non blocking read of the next available message. */ 1565 /* Non blocking read of the next available message. */
1554 dbus_connection_read_write (connection, 0); 1566 dbus_connection_read_write (connection, 0);
@@ -1592,7 +1604,7 @@ xd_read_message (Lisp_Object bus)
1592 const char *uname, *path, *interface, *member; 1604 const char *uname, *path, *interface, *member;
1593 1605
1594 /* Open a connection to the bus. */ 1606 /* Open a connection to the bus. */
1595 connection = xd_initialize (bus); 1607 connection = xd_initialize (bus, TRUE);
1596 1608
1597 /* Non blocking read of the next available message. */ 1609 /* Non blocking read of the next available message. */
1598 dbus_connection_read_write (connection, 0); 1610 dbus_connection_read_write (connection, 0);
@@ -1842,7 +1854,7 @@ usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARG
1842 if (NILP (uname) || (SBYTES (uname) > 0)) 1854 if (NILP (uname) || (SBYTES (uname) > 0))
1843 { 1855 {
1844 /* Open a connection to the bus. */ 1856 /* Open a connection to the bus. */
1845 connection = xd_initialize (bus); 1857 connection = xd_initialize (bus, TRUE);
1846 1858
1847 /* Create a rule to receive related signals. */ 1859 /* Create a rule to receive related signals. */
1848 sprintf (rule, 1860 sprintf (rule,
@@ -1932,7 +1944,7 @@ used for composing the returning D-Bus message. */)
1932 a segmentation fault. */ 1944 a segmentation fault. */
1933 1945
1934 /* Open a connection to the bus. */ 1946 /* Open a connection to the bus. */
1935 connection = xd_initialize (bus); 1947 connection = xd_initialize (bus, TRUE);
1936 1948
1937 /* Request the known name from the bus. We can ignore the result, 1949 /* Request the known name from the bus. We can ignore the result,
1938 it is set to -1 if there is an error - kind of redundancy. */ 1950 it is set to -1 if there is an error - kind of redundancy. */