diff options
Diffstat (limited to 'src/dbusbind.c')
| -rw-r--r-- | src/dbusbind.c | 234 |
1 files changed, 152 insertions, 82 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c index 683d6f047fa..3b6f0e543bb 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -31,6 +31,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 31 | 31 | ||
| 32 | /* Subroutines. */ | 32 | /* Subroutines. */ |
| 33 | Lisp_Object Qdbus_init_bus; | 33 | Lisp_Object Qdbus_init_bus; |
| 34 | Lisp_Object Qdbus_close_bus; | ||
| 34 | Lisp_Object Qdbus_get_unique_name; | 35 | Lisp_Object Qdbus_get_unique_name; |
| 35 | Lisp_Object Qdbus_call_method; | 36 | Lisp_Object Qdbus_call_method; |
| 36 | Lisp_Object Qdbus_call_method_asynchronously; | 37 | Lisp_Object Qdbus_call_method_asynchronously; |
| @@ -59,6 +60,9 @@ Lisp_Object QCdbus_type_object_path, QCdbus_type_signature; | |||
| 59 | Lisp_Object QCdbus_type_array, QCdbus_type_variant; | 60 | Lisp_Object QCdbus_type_array, QCdbus_type_variant; |
| 60 | Lisp_Object QCdbus_type_struct, QCdbus_type_dict_entry; | 61 | Lisp_Object QCdbus_type_struct, QCdbus_type_dict_entry; |
| 61 | 62 | ||
| 63 | /* Registered buses. */ | ||
| 64 | Lisp_Object Vdbus_registered_buses; | ||
| 65 | |||
| 62 | /* Hash table which keeps function definitions. */ | 66 | /* Hash table which keeps function definitions. */ |
| 63 | Lisp_Object Vdbus_registered_objects_table; | 67 | Lisp_Object Vdbus_registered_objects_table; |
| 64 | 68 | ||
| @@ -111,7 +115,7 @@ int xd_in_read_queued_messages = 0; | |||
| 111 | } while (0) | 115 | } while (0) |
| 112 | 116 | ||
| 113 | /* Macros for debugging. In order to enable them, build with | 117 | /* Macros for debugging. In order to enable them, build with |
| 114 | "make MYCPPFLAGS='-DDBUS_DEBUG -Wall'". */ | 118 | "MYCPPFLAGS='-DDBUS_DEBUG -Wall' make". */ |
| 115 | #ifdef DBUS_DEBUG | 119 | #ifdef DBUS_DEBUG |
| 116 | #define XD_DEBUG_MESSAGE(...) \ | 120 | #define XD_DEBUG_MESSAGE(...) \ |
| 117 | do { \ | 121 | do { \ |
| @@ -713,10 +717,10 @@ xd_retrieve_arg (unsigned int dtype, DBusMessageIter *iter) | |||
| 713 | } | 717 | } |
| 714 | } | 718 | } |
| 715 | 719 | ||
| 716 | /* Initialize D-Bus connection. BUS is a Lisp symbol, either :system | 720 | /* Initialize D-Bus connection. BUS is either a Lisp symbol, :system |
| 717 | or :session. It tells which D-Bus to initialize. If RAISE_ERROR | 721 | or :session, or a string denoting the bus address. It tells which |
| 718 | is non-zero signal an error when the connection cannot be | 722 | D-Bus to initialize. If RAISE_ERROR is non-zero, signal an error |
| 719 | initialized. */ | 723 | when the connection cannot be initialized. */ |
| 720 | static DBusConnection * | 724 | static DBusConnection * |
| 721 | xd_initialize (Lisp_Object bus, int raise_error) | 725 | xd_initialize (Lisp_Object bus, int raise_error) |
| 722 | { | 726 | { |
| @@ -724,34 +728,66 @@ xd_initialize (Lisp_Object bus, int raise_error) | |||
| 724 | DBusError derror; | 728 | DBusError derror; |
| 725 | 729 | ||
| 726 | /* Parameter check. */ | 730 | /* Parameter check. */ |
| 727 | CHECK_SYMBOL (bus); | 731 | if (!STRINGP (bus)) |
| 728 | if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus))) | 732 | { |
| 729 | if (raise_error) | 733 | CHECK_SYMBOL (bus); |
| 730 | XD_SIGNAL2 (build_string ("Wrong bus name"), bus); | 734 | if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus))) |
| 731 | else | 735 | { |
| 732 | return NULL; | 736 | if (raise_error) |
| 737 | XD_SIGNAL2 (build_string ("Wrong bus name"), bus); | ||
| 738 | else | ||
| 739 | return NULL; | ||
| 740 | } | ||
| 733 | 741 | ||
| 734 | /* We do not want to have an autolaunch for the session bus. */ | 742 | /* We do not want to have an autolaunch for the session bus. */ |
| 735 | if (EQ (bus, QCdbus_session_bus) | 743 | if (EQ (bus, QCdbus_session_bus) |
| 736 | && getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL) | 744 | && getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL) |
| 737 | if (raise_error) | 745 | { |
| 738 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); | 746 | if (raise_error) |
| 739 | else | 747 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); |
| 740 | return NULL; | 748 | else |
| 749 | return NULL; | ||
| 750 | } | ||
| 751 | } | ||
| 741 | 752 | ||
| 742 | /* Open a connection to the bus. */ | 753 | /* Open a connection to the bus. */ |
| 743 | dbus_error_init (&derror); | 754 | dbus_error_init (&derror); |
| 744 | 755 | ||
| 745 | if (EQ (bus, QCdbus_system_bus)) | 756 | if (STRINGP (bus)) |
| 746 | connection = dbus_bus_get (DBUS_BUS_SYSTEM, &derror); | 757 | connection = dbus_connection_open (SDATA (bus), &derror); |
| 747 | else | 758 | else |
| 748 | connection = dbus_bus_get (DBUS_BUS_SESSION, &derror); | 759 | if (EQ (bus, QCdbus_system_bus)) |
| 760 | connection = dbus_bus_get (DBUS_BUS_SYSTEM, &derror); | ||
| 761 | else | ||
| 762 | connection = dbus_bus_get (DBUS_BUS_SESSION, &derror); | ||
| 749 | 763 | ||
| 750 | if (dbus_error_is_set (&derror)) | 764 | if (dbus_error_is_set (&derror)) |
| 751 | if (raise_error) | 765 | { |
| 752 | XD_ERROR (derror); | 766 | if (raise_error) |
| 753 | else | 767 | XD_ERROR (derror); |
| 754 | connection = NULL; | 768 | else |
| 769 | connection = NULL; | ||
| 770 | } | ||
| 771 | |||
| 772 | /* If it is not the system or session bus, we must register | ||
| 773 | ourselves. Otherwise, we have called dbus_bus_get, which has | ||
| 774 | configured us to exit if the connection closes - we undo this | ||
| 775 | setting. */ | ||
| 776 | if (connection != NULL) | ||
| 777 | { | ||
| 778 | if (STRINGP (bus)) | ||
| 779 | dbus_bus_register (connection, &derror); | ||
| 780 | else | ||
| 781 | dbus_connection_set_exit_on_disconnect (connection, FALSE); | ||
| 782 | } | ||
| 783 | |||
| 784 | if (dbus_error_is_set (&derror)) | ||
| 785 | { | ||
| 786 | if (raise_error) | ||
| 787 | XD_ERROR (derror); | ||
| 788 | else | ||
| 789 | connection = NULL; | ||
| 790 | } | ||
| 755 | 791 | ||
| 756 | if (connection == NULL && raise_error) | 792 | if (connection == NULL && raise_error) |
| 757 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); | 793 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); |
| @@ -794,7 +830,8 @@ xd_add_watch (DBusWatch *watch, void *data) | |||
| 794 | } | 830 | } |
| 795 | 831 | ||
| 796 | /* Remove connection file descriptor from input_wait_mask. DATA is | 832 | /* Remove connection file descriptor from input_wait_mask. DATA is |
| 797 | the used bus, either QCdbus_system_bus or QCdbus_session_bus. */ | 833 | the used bus, either a string or QCdbus_system_bus or |
| 834 | QCdbus_session_bus. */ | ||
| 798 | void | 835 | void |
| 799 | xd_remove_watch (DBusWatch *watch, void *data) | 836 | xd_remove_watch (DBusWatch *watch, void *data) |
| 800 | { | 837 | { |
| @@ -830,15 +867,11 @@ xd_remove_watch (DBusWatch *watch, void *data) | |||
| 830 | } | 867 | } |
| 831 | 868 | ||
| 832 | DEFUN ("dbus-init-bus", Fdbus_init_bus, Sdbus_init_bus, 1, 1, 0, | 869 | DEFUN ("dbus-init-bus", Fdbus_init_bus, Sdbus_init_bus, 1, 1, 0, |
| 833 | doc: /* Initialize connection to D-Bus BUS. | 870 | doc: /* Initialize connection to D-Bus BUS. */) |
| 834 | This is an internal function, it shall not be used outside dbus.el. */) | ||
| 835 | (Lisp_Object bus) | 871 | (Lisp_Object bus) |
| 836 | { | 872 | { |
| 837 | DBusConnection *connection; | 873 | DBusConnection *connection; |
| 838 | 874 | ||
| 839 | /* Check parameters. */ | ||
| 840 | CHECK_SYMBOL (bus); | ||
| 841 | |||
| 842 | /* Open a connection to the bus. */ | 875 | /* Open a connection to the bus. */ |
| 843 | connection = xd_initialize (bus, TRUE); | 876 | connection = xd_initialize (bus, TRUE); |
| 844 | 877 | ||
| @@ -850,6 +883,28 @@ This is an internal function, it shall not be used outside dbus.el. */) | |||
| 850 | NULL, (void*) XHASH (bus), NULL)) | 883 | NULL, (void*) XHASH (bus), NULL)) |
| 851 | XD_SIGNAL1 (build_string ("Cannot add watch functions")); | 884 | XD_SIGNAL1 (build_string ("Cannot add watch functions")); |
| 852 | 885 | ||
| 886 | /* Add bus to list of registered buses. */ | ||
| 887 | Vdbus_registered_buses = Fcons (bus, Vdbus_registered_buses); | ||
| 888 | |||
| 889 | /* Return. */ | ||
| 890 | return Qnil; | ||
| 891 | } | ||
| 892 | |||
| 893 | DEFUN ("dbus-close-bus", Fdbus_close_bus, Sdbus_close_bus, 1, 1, 0, | ||
| 894 | doc: /* Close connection to D-Bus BUS. */) | ||
| 895 | (Lisp_Object bus) | ||
| 896 | { | ||
| 897 | DBusConnection *connection; | ||
| 898 | |||
| 899 | /* Open a connection to the bus. */ | ||
| 900 | connection = xd_initialize (bus, TRUE); | ||
| 901 | |||
| 902 | /* Decrement reference count to the bus. */ | ||
| 903 | dbus_connection_unref (connection); | ||
| 904 | |||
| 905 | /* Remove bus from list of registered buses. */ | ||
| 906 | Vdbus_registered_buses = Fdelete (bus, Vdbus_registered_buses); | ||
| 907 | |||
| 853 | /* Return. */ | 908 | /* Return. */ |
| 854 | return Qnil; | 909 | return Qnil; |
| 855 | } | 910 | } |
| @@ -862,9 +917,6 @@ DEFUN ("dbus-get-unique-name", Fdbus_get_unique_name, Sdbus_get_unique_name, | |||
| 862 | DBusConnection *connection; | 917 | DBusConnection *connection; |
| 863 | const char *name; | 918 | const char *name; |
| 864 | 919 | ||
| 865 | /* Check parameters. */ | ||
| 866 | CHECK_SYMBOL (bus); | ||
| 867 | |||
| 868 | /* Open a connection to the bus. */ | 920 | /* Open a connection to the bus. */ |
| 869 | connection = xd_initialize (bus, TRUE); | 921 | connection = xd_initialize (bus, TRUE); |
| 870 | 922 | ||
| @@ -880,7 +932,8 @@ DEFUN ("dbus-get-unique-name", Fdbus_get_unique_name, Sdbus_get_unique_name, | |||
| 880 | DEFUN ("dbus-call-method", Fdbus_call_method, Sdbus_call_method, 5, MANY, 0, | 932 | DEFUN ("dbus-call-method", Fdbus_call_method, Sdbus_call_method, 5, MANY, 0, |
| 881 | doc: /* Call METHOD on the D-Bus BUS. | 933 | doc: /* Call METHOD on the D-Bus BUS. |
| 882 | 934 | ||
| 883 | BUS is either the symbol `:system' or the symbol `:session'. | 935 | BUS is either a Lisp symbol, `:system' or `:session', or a string |
| 936 | denoting the bus address. | ||
| 884 | 937 | ||
| 885 | SERVICE is the D-Bus service name to be used. PATH is the D-Bus | 938 | SERVICE is the D-Bus service name to be used. PATH is the D-Bus |
| 886 | object path SERVICE is registered at. INTERFACE is an interface | 939 | object path SERVICE is registered at. INTERFACE is an interface |
| @@ -967,7 +1020,6 @@ usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TI | |||
| 967 | interface = args[3]; | 1020 | interface = args[3]; |
| 968 | method = args[4]; | 1021 | method = args[4]; |
| 969 | 1022 | ||
| 970 | CHECK_SYMBOL (bus); | ||
| 971 | CHECK_STRING (service); | 1023 | CHECK_STRING (service); |
| 972 | CHECK_STRING (path); | 1024 | CHECK_STRING (path); |
| 973 | CHECK_STRING (interface); | 1025 | CHECK_STRING (interface); |
| @@ -1082,7 +1134,8 @@ DEFUN ("dbus-call-method-asynchronously", Fdbus_call_method_asynchronously, | |||
| 1082 | Sdbus_call_method_asynchronously, 6, MANY, 0, | 1134 | Sdbus_call_method_asynchronously, 6, MANY, 0, |
| 1083 | doc: /* Call METHOD on the D-Bus BUS asynchronously. | 1135 | doc: /* Call METHOD on the D-Bus BUS asynchronously. |
| 1084 | 1136 | ||
| 1085 | BUS is either the symbol `:system' or the symbol `:session'. | 1137 | BUS is either a Lisp symbol, `:system' or `:session', or a string |
| 1138 | denoting the bus address. | ||
| 1086 | 1139 | ||
| 1087 | SERVICE is the D-Bus service name to be used. PATH is the D-Bus | 1140 | SERVICE is the D-Bus service name to be used. PATH is the D-Bus |
| 1088 | object path SERVICE is registered at. INTERFACE is an interface | 1141 | object path SERVICE is registered at. INTERFACE is an interface |
| @@ -1148,7 +1201,6 @@ usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLE | |||
| 1148 | method = args[4]; | 1201 | method = args[4]; |
| 1149 | handler = args[5]; | 1202 | handler = args[5]; |
| 1150 | 1203 | ||
| 1151 | CHECK_SYMBOL (bus); | ||
| 1152 | CHECK_STRING (service); | 1204 | CHECK_STRING (service); |
| 1153 | CHECK_STRING (path); | 1205 | CHECK_STRING (path); |
| 1154 | CHECK_STRING (interface); | 1206 | CHECK_STRING (interface); |
| @@ -1271,7 +1323,6 @@ usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */) | |||
| 1271 | serial = args[1]; | 1323 | serial = args[1]; |
| 1272 | service = args[2]; | 1324 | service = args[2]; |
| 1273 | 1325 | ||
| 1274 | CHECK_SYMBOL (bus); | ||
| 1275 | CHECK_NUMBER (serial); | 1326 | CHECK_NUMBER (serial); |
| 1276 | CHECK_STRING (service); | 1327 | CHECK_STRING (service); |
| 1277 | GCPRO3 (bus, serial, service); | 1328 | GCPRO3 (bus, serial, service); |
| @@ -1363,7 +1414,6 @@ usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */) | |||
| 1363 | serial = args[1]; | 1414 | serial = args[1]; |
| 1364 | service = args[2]; | 1415 | service = args[2]; |
| 1365 | 1416 | ||
| 1366 | CHECK_SYMBOL (bus); | ||
| 1367 | CHECK_NUMBER (serial); | 1417 | CHECK_NUMBER (serial); |
| 1368 | CHECK_STRING (service); | 1418 | CHECK_STRING (service); |
| 1369 | GCPRO3 (bus, serial, service); | 1419 | GCPRO3 (bus, serial, service); |
| @@ -1436,7 +1486,8 @@ usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */) | |||
| 1436 | DEFUN ("dbus-send-signal", Fdbus_send_signal, Sdbus_send_signal, 5, MANY, 0, | 1486 | DEFUN ("dbus-send-signal", Fdbus_send_signal, Sdbus_send_signal, 5, MANY, 0, |
| 1437 | doc: /* Send signal SIGNAL on the D-Bus BUS. | 1487 | doc: /* Send signal SIGNAL on the D-Bus BUS. |
| 1438 | 1488 | ||
| 1439 | BUS is either the symbol `:system' or the symbol `:session'. | 1489 | BUS is either a Lisp symbol, `:system' or `:session', or a string |
| 1490 | denoting the bus address. | ||
| 1440 | 1491 | ||
| 1441 | SERVICE is the D-Bus service name SIGNAL is sent from. PATH is the | 1492 | SERVICE is the D-Bus service name SIGNAL is sent from. PATH is the |
| 1442 | D-Bus object path SERVICE is registered at. INTERFACE is an interface | 1493 | D-Bus object path SERVICE is registered at. INTERFACE is an interface |
| @@ -1480,7 +1531,6 @@ usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */) | |||
| 1480 | interface = args[3]; | 1531 | interface = args[3]; |
| 1481 | signal = args[4]; | 1532 | signal = args[4]; |
| 1482 | 1533 | ||
| 1483 | CHECK_SYMBOL (bus); | ||
| 1484 | CHECK_STRING (service); | 1534 | CHECK_STRING (service); |
| 1485 | CHECK_STRING (path); | 1535 | CHECK_STRING (path); |
| 1486 | CHECK_STRING (interface); | 1536 | CHECK_STRING (interface); |
| @@ -1552,7 +1602,8 @@ usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */) | |||
| 1552 | } | 1602 | } |
| 1553 | 1603 | ||
| 1554 | /* Check, whether there is pending input in the message queue of the | 1604 | /* Check, whether there is pending input in the message queue of the |
| 1555 | D-Bus BUS. BUS is a Lisp symbol, either :system or :session. */ | 1605 | D-Bus BUS. BUS is either a Lisp symbol, :system or :session, or a |
| 1606 | string denoting the bus address. */ | ||
| 1556 | int | 1607 | int |
| 1557 | xd_get_dispatch_status (Lisp_Object bus) | 1608 | xd_get_dispatch_status (Lisp_Object bus) |
| 1558 | { | 1609 | { |
| @@ -1572,24 +1623,31 @@ xd_get_dispatch_status (Lisp_Object bus) | |||
| 1572 | ? TRUE : FALSE; | 1623 | ? TRUE : FALSE; |
| 1573 | } | 1624 | } |
| 1574 | 1625 | ||
| 1575 | /* Check for queued incoming messages from the system and session buses. */ | 1626 | /* Check for queued incoming messages from the buses. */ |
| 1576 | int | 1627 | int |
| 1577 | xd_pending_messages (void) | 1628 | xd_pending_messages (void) |
| 1578 | { | 1629 | { |
| 1630 | Lisp_Object busp = Vdbus_registered_buses; | ||
| 1631 | |||
| 1632 | while (!NILP (busp)) | ||
| 1633 | { | ||
| 1634 | /* We do not want to have an autolaunch for the session bus. */ | ||
| 1635 | if (EQ ((CAR_SAFE (busp)), QCdbus_session_bus) | ||
| 1636 | && getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL) | ||
| 1637 | continue; | ||
| 1579 | 1638 | ||
| 1580 | /* Vdbus_registered_objects_table will be initialized as hash table | 1639 | if (xd_get_dispatch_status (CAR_SAFE (busp))) |
| 1581 | in dbus.el. When this package isn't loaded yet, it doesn't make | 1640 | return TRUE; |
| 1582 | sense to handle D-Bus messages. */ | 1641 | |
| 1583 | return (HASH_TABLE_P (Vdbus_registered_objects_table) | 1642 | busp = CDR_SAFE (busp); |
| 1584 | ? (xd_get_dispatch_status (QCdbus_system_bus) | 1643 | } |
| 1585 | || ((getenv ("DBUS_SESSION_BUS_ADDRESS") != NULL) | 1644 | |
| 1586 | ? xd_get_dispatch_status (QCdbus_session_bus) | 1645 | return FALSE; |
| 1587 | : FALSE)) | ||
| 1588 | : FALSE); | ||
| 1589 | } | 1646 | } |
| 1590 | 1647 | ||
| 1591 | /* Read queued incoming message of the D-Bus BUS. BUS is a Lisp | 1648 | /* Read queued incoming message of the D-Bus BUS. BUS is either a |
| 1592 | symbol, either :system or :session. */ | 1649 | Lisp symbol, :system or :session, or a string denoting the bus |
| 1650 | address. */ | ||
| 1593 | static Lisp_Object | 1651 | static Lisp_Object |
| 1594 | xd_read_message (Lisp_Object bus) | 1652 | xd_read_message (Lisp_Object bus) |
| 1595 | { | 1653 | { |
| @@ -1746,29 +1804,28 @@ xd_read_message (Lisp_Object bus) | |||
| 1746 | RETURN_UNGCPRO (Qnil); | 1804 | RETURN_UNGCPRO (Qnil); |
| 1747 | } | 1805 | } |
| 1748 | 1806 | ||
| 1749 | /* Read queued incoming messages from the system and session buses. */ | 1807 | /* Read queued incoming messages from all buses. */ |
| 1750 | void | 1808 | void |
| 1751 | xd_read_queued_messages (void) | 1809 | xd_read_queued_messages (void) |
| 1752 | { | 1810 | { |
| 1811 | Lisp_Object busp = Vdbus_registered_buses; | ||
| 1753 | 1812 | ||
| 1754 | /* Vdbus_registered_objects_table will be initialized as hash table | 1813 | xd_in_read_queued_messages = 1; |
| 1755 | in dbus.el. When this package isn't loaded yet, it doesn't make | 1814 | while (!NILP (busp)) |
| 1756 | sense to handle D-Bus messages. Furthermore, we ignore all Lisp | ||
| 1757 | errors during the call. */ | ||
| 1758 | if (HASH_TABLE_P (Vdbus_registered_objects_table)) | ||
| 1759 | { | 1815 | { |
| 1760 | xd_in_read_queued_messages = 1; | 1816 | /* We ignore all Lisp errors during the call. */ |
| 1761 | internal_catch (Qdbus_error, xd_read_message, QCdbus_system_bus); | 1817 | internal_catch (Qdbus_error, xd_read_message, CAR_SAFE (busp)); |
| 1762 | internal_catch (Qdbus_error, xd_read_message, QCdbus_session_bus); | 1818 | busp = CDR_SAFE (busp); |
| 1763 | xd_in_read_queued_messages = 0; | ||
| 1764 | } | 1819 | } |
| 1820 | xd_in_read_queued_messages = 0; | ||
| 1765 | } | 1821 | } |
| 1766 | 1822 | ||
| 1767 | DEFUN ("dbus-register-signal", Fdbus_register_signal, Sdbus_register_signal, | 1823 | DEFUN ("dbus-register-signal", Fdbus_register_signal, Sdbus_register_signal, |
| 1768 | 6, MANY, 0, | 1824 | 6, MANY, 0, |
| 1769 | doc: /* Register for signal SIGNAL on the D-Bus BUS. | 1825 | doc: /* Register for signal SIGNAL on the D-Bus BUS. |
| 1770 | 1826 | ||
| 1771 | BUS is either the symbol `:system' or the symbol `:session'. | 1827 | BUS is either a Lisp symbol, `:system' or `:session', or a string |
| 1828 | denoting the bus address. | ||
| 1772 | 1829 | ||
| 1773 | SERVICE is the D-Bus service name used by the sending D-Bus object. | 1830 | SERVICE is the D-Bus service name used by the sending D-Bus object. |
| 1774 | It can be either a known name or the unique name of the D-Bus object | 1831 | It can be either a known name or the unique name of the D-Bus object |
| @@ -1822,7 +1879,6 @@ usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARG | |||
| 1822 | signal = args[4]; | 1879 | signal = args[4]; |
| 1823 | handler = args[5]; | 1880 | handler = args[5]; |
| 1824 | 1881 | ||
| 1825 | CHECK_SYMBOL (bus); | ||
| 1826 | if (!NILP (service)) CHECK_STRING (service); | 1882 | if (!NILP (service)) CHECK_STRING (service); |
| 1827 | if (!NILP (path)) CHECK_STRING (path); | 1883 | if (!NILP (path)) CHECK_STRING (path); |
| 1828 | CHECK_STRING (interface); | 1884 | CHECK_STRING (interface); |
| @@ -1915,7 +1971,8 @@ DEFUN ("dbus-register-method", Fdbus_register_method, Sdbus_register_method, | |||
| 1915 | 6, 6, 0, | 1971 | 6, 6, 0, |
| 1916 | doc: /* Register for method METHOD on the D-Bus BUS. | 1972 | doc: /* Register for method METHOD on the D-Bus BUS. |
| 1917 | 1973 | ||
| 1918 | BUS is either the symbol `:system' or the symbol `:session'. | 1974 | BUS is either a Lisp symbol, `:system' or `:session', or a string |
| 1975 | denoting the bus address. | ||
| 1919 | 1976 | ||
| 1920 | SERVICE is the D-Bus service name of the D-Bus object METHOD is | 1977 | SERVICE is the D-Bus service name of the D-Bus object METHOD is |
| 1921 | registered for. It must be a known name. | 1978 | registered for. It must be a known name. |
| @@ -1933,7 +1990,6 @@ used for composing the returning D-Bus message. */) | |||
| 1933 | DBusError derror; | 1990 | DBusError derror; |
| 1934 | 1991 | ||
| 1935 | /* Check parameters. */ | 1992 | /* Check parameters. */ |
| 1936 | CHECK_SYMBOL (bus); | ||
| 1937 | CHECK_STRING (service); | 1993 | CHECK_STRING (service); |
| 1938 | CHECK_STRING (path); | 1994 | CHECK_STRING (path); |
| 1939 | CHECK_STRING (interface); | 1995 | CHECK_STRING (interface); |
| @@ -1978,6 +2034,10 @@ syms_of_dbusbind (void) | |||
| 1978 | staticpro (&Qdbus_init_bus); | 2034 | staticpro (&Qdbus_init_bus); |
| 1979 | defsubr (&Sdbus_init_bus); | 2035 | defsubr (&Sdbus_init_bus); |
| 1980 | 2036 | ||
| 2037 | Qdbus_close_bus = intern_c_string ("dbus-close-bus"); | ||
| 2038 | staticpro (&Qdbus_close_bus); | ||
| 2039 | defsubr (&Sdbus_close_bus); | ||
| 2040 | |||
| 1981 | Qdbus_get_unique_name = intern_c_string ("dbus-get-unique-name"); | 2041 | Qdbus_get_unique_name = intern_c_string ("dbus-get-unique-name"); |
| 1982 | staticpro (&Qdbus_get_unique_name); | 2042 | staticpro (&Qdbus_get_unique_name); |
| 1983 | defsubr (&Sdbus_get_unique_name); | 2043 | defsubr (&Sdbus_get_unique_name); |
| @@ -2074,18 +2134,25 @@ syms_of_dbusbind (void) | |||
| 2074 | QCdbus_type_dict_entry = intern_c_string (":dict-entry"); | 2134 | QCdbus_type_dict_entry = intern_c_string (":dict-entry"); |
| 2075 | staticpro (&QCdbus_type_dict_entry); | 2135 | staticpro (&QCdbus_type_dict_entry); |
| 2076 | 2136 | ||
| 2137 | DEFVAR_LISP ("dbus-registered-buses", | ||
| 2138 | &Vdbus_registered_buses, | ||
| 2139 | doc: /* List of D-Bus buses we are polling for messages. */); | ||
| 2140 | Vdbus_registered_buses = Qnil; | ||
| 2141 | |||
| 2077 | DEFVAR_LISP ("dbus-registered-objects-table", | 2142 | DEFVAR_LISP ("dbus-registered-objects-table", |
| 2078 | &Vdbus_registered_objects_table, | 2143 | &Vdbus_registered_objects_table, |
| 2079 | doc: /* Hash table of registered functions for D-Bus. | 2144 | doc: /* Hash table of registered functions for D-Bus. |
| 2145 | |||
| 2080 | There are two different uses of the hash table: for accessing | 2146 | There are two different uses of the hash table: for accessing |
| 2081 | registered interfaces properties, targeted by signals or method calls, | 2147 | registered interfaces properties, targeted by signals or method calls, |
| 2082 | and for calling handlers in case of non-blocking method call returns. | 2148 | and for calling handlers in case of non-blocking method call returns. |
| 2083 | 2149 | ||
| 2084 | In the first case, the key in the hash table is the list (BUS | 2150 | In the first case, the key in the hash table is the list (BUS |
| 2085 | INTERFACE MEMBER). BUS is either the symbol `:system' or the symbol | 2151 | INTERFACE MEMBER). BUS is either a Lisp symbol, `:system' or |
| 2086 | `:session'. INTERFACE is a string which denotes a D-Bus interface, | 2152 | `:session', or a string denoting the bus address. INTERFACE is a |
| 2087 | and MEMBER, also a string, is either a method, a signal or a property | 2153 | string which denotes a D-Bus interface, and MEMBER, also a string, is |
| 2088 | INTERFACE is offering. All arguments but BUS must not be nil. | 2154 | either a method, a signal or a property INTERFACE is offering. All |
| 2155 | arguments but BUS must not be nil. | ||
| 2089 | 2156 | ||
| 2090 | The value in the hash table is a list of quadruple lists | 2157 | The value in the hash table is a list of quadruple lists |
| 2091 | \((UNAME SERVICE PATH OBJECT) (UNAME SERVICE PATH OBJECT) ...). | 2158 | \((UNAME SERVICE PATH OBJECT) (UNAME SERVICE PATH OBJECT) ...). |
| @@ -2097,15 +2164,18 @@ be called when a D-Bus message, which matches the key criteria, | |||
| 2097 | arrives (methods and signals), or a cons cell containing the value of | 2164 | arrives (methods and signals), or a cons cell containing the value of |
| 2098 | the property. | 2165 | the property. |
| 2099 | 2166 | ||
| 2100 | In the second case, the key in the hash table is the list (BUS SERIAL). | 2167 | In the second case, the key in the hash table is the list (BUS |
| 2101 | BUS is either the symbol `:system' or the symbol `:session'. SERIAL | 2168 | SERIAL). BUS is either a Lisp symbol, `:system' or `:session', or a |
| 2102 | is the serial number of the non-blocking method call, a reply is | 2169 | string denoting the bus address. SERIAL is the serial number of the |
| 2103 | expected. Both arguments must not be nil. The value in the hash | 2170 | non-blocking method call, a reply is expected. Both arguments must |
| 2104 | table is HANDLER, the function to be called when the D-Bus reply | 2171 | not be nil. The value in the hash table is HANDLER, the function to |
| 2105 | message arrives. */); | 2172 | be called when the D-Bus reply message arrives. */); |
| 2106 | /* We initialize Vdbus_registered_objects_table in dbus.el, because | 2173 | { |
| 2107 | we need to define a hash table function first. */ | 2174 | Lisp_Object args[2]; |
| 2108 | Vdbus_registered_objects_table = Qnil; | 2175 | args[0] = QCtest; |
| 2176 | args[1] = Qequal; | ||
| 2177 | Vdbus_registered_objects_table = Fmake_hash_table (2, args); | ||
| 2178 | } | ||
| 2109 | 2179 | ||
| 2110 | DEFVAR_LISP ("dbus-debug", &Vdbus_debug, | 2180 | DEFVAR_LISP ("dbus-debug", &Vdbus_debug, |
| 2111 | doc: /* If non-nil, debug messages of D-Bus bindings are raised. */); | 2181 | doc: /* If non-nil, debug messages of D-Bus bindings are raised. */); |