comparison src/dbusbind.c @ 109353:d43e7dfda4f1

merge trunk
author Kenichi Handa <handa@etlken>
date Mon, 12 Jul 2010 11:28:50 +0900
parents a0cffb71f267
children bf0e558ade02
comparison
equal deleted inserted replaced
109352:2803d726899d 109353:d43e7dfda4f1
712 return Qnil; 712 return Qnil;
713 } 713 }
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. */
718 static DBusConnection * 720 static DBusConnection *
719 xd_initialize (Lisp_Object bus) 721 xd_initialize (Lisp_Object bus, int raise_error)
720 { 722 {
721 DBusConnection *connection; 723 DBusConnection *connection;
722 DBusError derror; 724 DBusError derror;
723 725
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);
736 744
737 if (EQ (bus, QCdbus_system_bus)) 745 if (EQ (bus, QCdbus_system_bus))
738 connection = dbus_bus_get (DBUS_BUS_SYSTEM, &derror); 746 connection = dbus_bus_get (DBUS_BUS_SYSTEM, &derror);
739 else 747 else
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)
744 752 XD_ERROR (derror);
745 if (connection == NULL) 753 else
754 connection = NULL;
755
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. */
749 dbus_error_free (&derror); 760 dbus_error_free (&derror);
750 761
827 838
828 /* Check parameters. */ 839 /* Check parameters. */
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. */
836 if (!dbus_connection_set_watch_functions (connection, 847 if (!dbus_connection_set_watch_functions (connection,
837 xd_add_watch, 848 xd_add_watch,
853 864
854 /* Check parameters. */ 865 /* Check parameters. */
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);
862 if (name == NULL) 873 if (name == NULL)
863 XD_SIGNAL1 (build_string ("No unique name available")); 874 XD_SIGNAL1 (build_string ("No unique name available"));
968 SDATA (path), 979 SDATA (path),
969 SDATA (interface), 980 SDATA (interface),
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),
977 SDATA (path), 988 SDATA (path),
978 SDATA (interface), 989 SDATA (interface),
1151 SDATA (path), 1162 SDATA (path),
1152 SDATA (interface), 1163 SDATA (interface),
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),
1160 SDATA (path), 1171 SDATA (path),
1161 SDATA (interface), 1172 SDATA (interface),
1266 GCPRO3 (bus, serial, service); 1277 GCPRO3 (bus, serial, service);
1267 1278
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);
1275 if ((dmessage == NULL) 1286 if ((dmessage == NULL)
1276 || (!dbus_message_set_reply_serial (dmessage, XUINT (serial))) 1287 || (!dbus_message_set_reply_serial (dmessage, XUINT (serial)))
1358 GCPRO3 (bus, serial, service); 1369 GCPRO3 (bus, serial, service);
1359 1370
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);
1367 if ((dmessage == NULL) 1378 if ((dmessage == NULL)
1368 || (!dbus_message_set_error_name (dmessage, DBUS_ERROR_FAILED)) 1379 || (!dbus_message_set_error_name (dmessage, DBUS_ERROR_FAILED))
1481 SDATA (path), 1492 SDATA (path),
1482 SDATA (interface), 1493 SDATA (interface),
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),
1490 SDATA (interface), 1501 SDATA (interface),
1491 SDATA (signal)); 1502 SDATA (signal));
1546 xd_get_dispatch_status (Lisp_Object bus) 1557 xd_get_dispatch_status (Lisp_Object bus)
1547 { 1558 {
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);
1555 1567
1556 /* Return. */ 1568 /* Return. */
1590 unsigned int dtype; 1602 unsigned int dtype;
1591 int mtype, serial; 1603 int mtype, serial;
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);
1599 dmessage = dbus_connection_pop_message (connection); 1611 dmessage = dbus_connection_pop_message (connection);
1600 1612
1840 /* Create a matching rule if the unique name exists (when no 1852 /* Create a matching rule if the unique name exists (when no
1841 wildcard). */ 1853 wildcard). */
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,
1849 "type='signal',interface='%s',member='%s'", 1861 "type='signal',interface='%s',member='%s'",
1850 SDATA (interface), 1862 SDATA (interface),
1930 wrong_type_argument (intern ("functionp"), handler); 1942 wrong_type_argument (intern ("functionp"), handler);
1931 /* TODO: We must check for a valid service name, otherwise there is 1943 /* TODO: We must check for a valid service name, otherwise there is
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. */
1939 dbus_error_init (&derror); 1951 dbus_error_init (&derror);
1940 result = dbus_bus_request_name (connection, SDATA (service), 0, &derror); 1952 result = dbus_bus_request_name (connection, SDATA (service), 0, &derror);