diff options
| author | Michael Albinus | 2020-10-04 18:56:45 +0200 |
|---|---|---|
| committer | Michael Albinus | 2020-10-04 18:56:45 +0200 |
| commit | 96a8e846061f255b1a394a5854197aa742dfff84 (patch) | |
| tree | d61810b678df0c95bd4cfb28ea97c889ac02f1b9 | |
| parent | d8665e6d3473403c90a0831e83439a013d0012d3 (diff) | |
| download | emacs-96a8e846061f255b1a394a5854197aa742dfff84.tar.gz emacs-96a8e846061f255b1a394a5854197aa742dfff84.zip | |
Make dbus-unregister-object work for monitors
* doc/misc/dbus.texi (Monitoring Messages): Rename from
"Monitoring Events".
(Register Objects, Monitoring Messages):
Mention returned object.
* lisp/net/dbus.el (dbus-unregister-object): Adapt docstring.
(dbus-unregister-object): Delete monitor if needed.
(dbus-register-monitor): Return proper object.
* src/dbusbind.c (dbus-registered-objects-table): Adapt docstring.
* test/lisp/net/dbus-tests.el (dbus--test-signal-handler):
Adapt docstring.
(dbus-test08-register-monitor): New test.
| -rw-r--r-- | doc/misc/dbus.texi | 35 | ||||
| -rw-r--r-- | lisp/net/dbus.el | 12 | ||||
| -rw-r--r-- | src/dbusbind.c | 18 | ||||
| -rw-r--r-- | test/lisp/net/dbus-tests.el | 42 |
4 files changed, 79 insertions, 28 deletions
diff --git a/doc/misc/dbus.texi b/doc/misc/dbus.texi index 4b2eab4eb76..5a1dd55248d 100644 --- a/doc/misc/dbus.texi +++ b/doc/misc/dbus.texi | |||
| @@ -63,7 +63,7 @@ another. An overview of D-Bus can be found at | |||
| 63 | * Signals:: Sending and receiving signals. | 63 | * Signals:: Sending and receiving signals. |
| 64 | * Alternative Buses:: Alternative buses and environments. | 64 | * Alternative Buses:: Alternative buses and environments. |
| 65 | * Errors and Events:: Errors and events. | 65 | * Errors and Events:: Errors and events. |
| 66 | * Monitoring Events:: Monitoring events. | 66 | * Monitoring Messages:: Monitoring messages. |
| 67 | * Index:: Index including concepts, functions, variables. | 67 | * Index:: Index including concepts, functions, variables. |
| 68 | 68 | ||
| 69 | * GNU Free Documentation License:: The license for this documentation. | 69 | * GNU Free Documentation License:: The license for this documentation. |
| @@ -1622,7 +1622,9 @@ are constructed incrementally by adding single methods or properties | |||
| 1622 | at a time, @var{dont-register-service} can be used to prevent other | 1622 | at a time, @var{dont-register-service} can be used to prevent other |
| 1623 | clients from discovering the still incomplete interface. | 1623 | clients from discovering the still incomplete interface. |
| 1624 | 1624 | ||
| 1625 | @noindent Example: | 1625 | @code{dbus-register-property} returns a Lisp object, which can be used |
| 1626 | as argument in @code{dbus-unregister-object} for removing the | ||
| 1627 | registration for @var{property}. Example: | ||
| 1626 | 1628 | ||
| 1627 | @lisp | 1629 | @lisp |
| 1628 | (dbus-register-property | 1630 | (dbus-register-property |
| @@ -1687,9 +1689,9 @@ It is also possible to apply the @code{dbus-get-property}, | |||
| 1687 | @defun dbus-unregister-object object | 1689 | @defun dbus-unregister-object object |
| 1688 | This function unregisters @var{object} from the D-Bus. @var{object} | 1690 | This function unregisters @var{object} from the D-Bus. @var{object} |
| 1689 | must be the result of a preceding @code{dbus-register-method}, | 1691 | must be the result of a preceding @code{dbus-register-method}, |
| 1690 | @code{dbus-register-property} or @code{dbus-register-signal} call | 1692 | @code{dbus-register-property}, @code{dbus-register-signal} |
| 1691 | (@pxref{Signals}). It returns @code{t} if @var{object} has been | 1693 | (@pxref{Signals}) or @code{dbus-register-monitor} call. It returns |
| 1692 | unregistered, @code{nil} otherwise. | 1694 | @code{t} if @var{object} has been unregistered, @code{nil} otherwise. |
| 1693 | 1695 | ||
| 1694 | When @var{object} identifies the last method or property, which is | 1696 | When @var{object} identifies the last method or property, which is |
| 1695 | registered for the respective service, Emacs releases its association | 1697 | registered for the respective service, Emacs releases its association |
| @@ -2099,24 +2101,24 @@ D-Bus applications running. They should therefore check carefully, | |||
| 2099 | whether a given D-Bus error is related to them. | 2101 | whether a given D-Bus error is related to them. |
| 2100 | 2102 | ||
| 2101 | 2103 | ||
| 2102 | @node Monitoring Events | 2104 | @node Monitoring Messages |
| 2103 | @chapter Monitoring events. | 2105 | @chapter Monitoring messages. |
| 2104 | @cindex monitoring | 2106 | @cindex monitoring |
| 2105 | 2107 | ||
| 2106 | @defun dbus-register-monitor bus &optional handler &key type sender destination path interface member | 2108 | @defun dbus-register-monitor bus &optional handler &key type sender destination path interface member |
| 2107 | This function registers @var{handler} for monitor events on the D-Bus | 2109 | This function registers @var{handler} for monitoring messages on the |
| 2108 | @var{bus}. | 2110 | D-Bus @var{bus}. |
| 2109 | 2111 | ||
| 2110 | @var{bus} is either a Lisp keyword, @code{:system} or @code{:session}, | 2112 | @var{bus} is either a Lisp keyword, @code{:system} or @code{:session}, |
| 2111 | or a string denoting the bus address. | 2113 | or a string denoting the bus address. |
| 2112 | 2114 | ||
| 2113 | @findex dbus-monitor-handler | 2115 | @findex dbus-monitor-handler |
| 2114 | @var{handler} is the function to be called when a monitor event | 2116 | @var{handler} is the function to be called when a D-Bus event to be |
| 2115 | arrives. It is called with the `args' slot of the monitor event, | 2117 | monitored arrives. It is called with the @var{args} slot of the D-Bus |
| 2116 | which are stripped off the type keywords. If @var{handler} is | 2118 | event (@pxref{Errors and Events}), which are stripped off the type |
| 2117 | @code{nil}, the default handler @code{dbus-monitor-handler} is | 2119 | keywords. If @var{handler} is @code{nil}, the default handler |
| 2118 | applied. This default handler behaves similar to the | 2120 | @code{dbus-monitor-handler} is applied. This default handler behaves |
| 2119 | @command{dbus-monitor} program. | 2121 | similar to the @command{dbus-monitor} program. |
| 2120 | 2122 | ||
| 2121 | The other arguments are keyword-value pairs. @code{:type @var{type}} | 2123 | The other arguments are keyword-value pairs. @code{:type @var{type}} |
| 2122 | defines the message type to be monitored. If given, it must be equal | 2124 | defines the message type to be monitored. If given, it must be equal |
| @@ -2132,6 +2134,9 @@ names. | |||
| 2132 | @code{:member @var{member}} is either a method name, a signal name, or | 2134 | @code{:member @var{member}} is either a method name, a signal name, or |
| 2133 | an error name. | 2135 | an error name. |
| 2134 | 2136 | ||
| 2137 | @code{dbus-register-monitor} returns a Lisp object, which can be used | ||
| 2138 | as argument in @code{dbus-unregister-object} for removing the monitor. | ||
| 2139 | |||
| 2135 | The following form shows all D-Bus events on the session bus in buffer | 2140 | The following form shows all D-Bus events on the session bus in buffer |
| 2136 | @samp{*D-Bus Monitor*}: | 2141 | @samp{*D-Bus Monitor*}: |
| 2137 | 2142 | ||
diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el index 48712a9c3d8..77ba5266dcb 100644 --- a/lisp/net/dbus.el +++ b/lisp/net/dbus.el | |||
| @@ -912,8 +912,9 @@ discovering the still incomplete interface." | |||
| 912 | (defun dbus-unregister-object (object) | 912 | (defun dbus-unregister-object (object) |
| 913 | "Unregister OBJECT from D-Bus. | 913 | "Unregister OBJECT from D-Bus. |
| 914 | OBJECT must be the result of a preceding `dbus-register-method', | 914 | OBJECT must be the result of a preceding `dbus-register-method', |
| 915 | `dbus-register-property' or `dbus-register-signal' call. It | 915 | `dbus-register-signal', `dbus-register-property' or |
| 916 | returns t if OBJECT has been unregistered, nil otherwise. | 916 | `dbus-register-monitor' call. The function returns t if OBJECT |
| 917 | has been unregistered, nil otherwise. | ||
| 917 | 918 | ||
| 918 | When OBJECT identifies the last method or property, which is | 919 | When OBJECT identifies the last method or property, which is |
| 919 | registered for the respective service, Emacs releases its | 920 | registered for the respective service, Emacs releases its |
| @@ -951,7 +952,10 @@ association to the service from D-Bus." | |||
| 951 | (when (eq type :signal) | 952 | (when (eq type :signal) |
| 952 | (dbus-call-method | 953 | (dbus-call-method |
| 953 | bus dbus-service-dbus dbus-path-dbus dbus-interface-dbus | 954 | bus dbus-service-dbus dbus-path-dbus dbus-interface-dbus |
| 954 | "RemoveMatch" (nth 4 elt))))) | 955 | "RemoveMatch" (nth 4 elt))) |
| 956 | ;; Delete monitor connection by reestablishing private bus. | ||
| 957 | (when (eq type :monitor) | ||
| 958 | (dbus-init-bus bus 'private)))) | ||
| 955 | 959 | ||
| 956 | ;; Check, whether there is still a registered function or property | 960 | ;; Check, whether there is still a registered function or property |
| 957 | ;; for the given service. If not, unregister the service from the | 961 | ;; for the given service. If not, unregister the service from the |
| @@ -2037,7 +2041,7 @@ either a method name, a signal name, or an error name." | |||
| 2037 | (when dbus-debug (message "%s" dbus-registered-objects-table)) | 2041 | (when dbus-debug (message "%s" dbus-registered-objects-table)) |
| 2038 | 2042 | ||
| 2039 | ;; Return the object. | 2043 | ;; Return the object. |
| 2040 | (list key key1))) | 2044 | (list key (list nil nil handler)))) |
| 2041 | 2045 | ||
| 2042 | (defconst dbus-monitor-method-call | 2046 | (defconst dbus-monitor-method-call |
| 2043 | (propertize "method-call" 'face 'font-lock-function-name-face) | 2047 | (propertize "method-call" 'face 'font-lock-function-name-face) |
diff --git a/src/dbusbind.c b/src/dbusbind.c index cca5f13907d..1ac77313a35 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -1937,11 +1937,12 @@ syms_of_dbusbind (void) | |||
| 1937 | doc: /* Hash table of registered functions for D-Bus. | 1937 | doc: /* Hash table of registered functions for D-Bus. |
| 1938 | 1938 | ||
| 1939 | There are two different uses of the hash table: for accessing | 1939 | There are two different uses of the hash table: for accessing |
| 1940 | registered interfaces properties, targeted by signals or method calls, | 1940 | registered interfaces properties, targeted by signals, method calls or |
| 1941 | and for calling handlers in case of non-blocking method call returns. | 1941 | monitors, and for calling handlers in case of non-blocking method call |
| 1942 | returns. | ||
| 1942 | 1943 | ||
| 1943 | In the first case, the key in the hash table is the list (TYPE BUS | 1944 | In the first case, the key in the hash table is the list (TYPE BUS |
| 1944 | INTERFACE MEMBER). TYPE is one of the Lisp symbols `:method', | 1945 | [INTERFACE MEMBER]). TYPE is one of the Lisp symbols `:method', |
| 1945 | `:signal', `:property' or `:monitor'. BUS is either a Lisp symbol, | 1946 | `:signal', `:property' or `:monitor'. BUS is either a Lisp symbol, |
| 1946 | `:system', `:session', `:system-private' or `:session-private', or a | 1947 | `:system', `:session', `:system-private' or `:session-private', or a |
| 1947 | string denoting the bus address. INTERFACE is a string which denotes | 1948 | string denoting the bus address. INTERFACE is a string which denotes |
| @@ -1951,17 +1952,18 @@ signal or a property INTERFACE is offering. All arguments can be nil. | |||
| 1951 | The value in the hash table is a list of quadruple lists ((UNAME | 1952 | The value in the hash table is a list of quadruple lists ((UNAME |
| 1952 | SERVICE PATH OBJECT [RULE]) ...). SERVICE is the service name as | 1953 | SERVICE PATH OBJECT [RULE]) ...). SERVICE is the service name as |
| 1953 | registered, UNAME is the corresponding unique name. In case of | 1954 | registered, UNAME is the corresponding unique name. In case of |
| 1954 | registered methods and properties, UNAME is nil. PATH is the object | 1955 | registered methods, properties and monitors, UNAME is nil. PATH is |
| 1955 | path of the sending object. All of them can be nil, which means a | 1956 | the object path of the sending object. All of them can be nil, which |
| 1956 | wildcard then. | 1957 | means a wildcard then. |
| 1957 | 1958 | ||
| 1958 | OBJECT is either the handler to be called when a D-Bus message, which | 1959 | OBJECT is either the handler to be called when a D-Bus message, which |
| 1959 | matches the key criteria, arrives (TYPE `:method', `:signal' and | 1960 | matches the key criteria, arrives (TYPE `:method', `:signal' and |
| 1960 | `:monitor'), or a list (ACCESS EMITS-SIGNAL VALUE) for TYPE | 1961 | `:monitor'), or a list (ACCESS EMITS-SIGNAL VALUE) for TYPE |
| 1961 | `:property'. | 1962 | `:property'. |
| 1962 | 1963 | ||
| 1963 | For entries of type `:signal', there is also a fifth element RULE, | 1964 | For entries of type `:signal' or `:monitor', there is also a fifth |
| 1964 | which keeps the match string the signal is registered with. | 1965 | element RULE, which keeps the match string the signal or monitor is |
| 1966 | registered with. | ||
| 1965 | 1967 | ||
| 1966 | In the second case, the key in the hash table is the list (:serial BUS | 1968 | In the second case, the key in the hash table is the list (:serial BUS |
| 1967 | SERIAL). BUS is either a Lisp symbol, `:system' or `:session', or a | 1969 | SERIAL). BUS is either a Lisp symbol, `:system' or `:session', or a |
diff --git a/test/lisp/net/dbus-tests.el b/test/lisp/net/dbus-tests.el index 7ebef5d2609..94816bb4929 100644 --- a/test/lisp/net/dbus-tests.el +++ b/test/lisp/net/dbus-tests.el | |||
| @@ -697,7 +697,7 @@ is in progress." | |||
| 697 | "Received signal value in `dbus--test-signal-handler'.") | 697 | "Received signal value in `dbus--test-signal-handler'.") |
| 698 | 698 | ||
| 699 | (defun dbus--test-signal-handler (&rest args) | 699 | (defun dbus--test-signal-handler (&rest args) |
| 700 | "Signal handler for `dbus-test*-signal'." | 700 | "Signal handler for `dbus-test*-signal' and `dbus-test08-register-monitor'." |
| 701 | (setq dbus--test-signal-received args)) | 701 | (setq dbus--test-signal-received args)) |
| 702 | 702 | ||
| 703 | (defun dbus--test-timeout-handler (&rest _ignore) | 703 | (defun dbus--test-timeout-handler (&rest _ignore) |
| @@ -1833,6 +1833,46 @@ The argument EXPECTED-ARGS is a list of expected arguments for the method." | |||
| 1833 | ;; Cleanup. | 1833 | ;; Cleanup. |
| 1834 | (dbus-unregister-service :session dbus--test-service))) | 1834 | (dbus-unregister-service :session dbus--test-service))) |
| 1835 | 1835 | ||
| 1836 | (ert-deftest dbus-test08-register-monitor () | ||
| 1837 | "Check monitor registration." | ||
| 1838 | :tags '(:expensive-test) | ||
| 1839 | (skip-unless dbus--test-enabled-session-bus) | ||
| 1840 | |||
| 1841 | (unwind-protect | ||
| 1842 | (let (registered) | ||
| 1843 | (should | ||
| 1844 | (equal | ||
| 1845 | (setq registered | ||
| 1846 | (dbus-register-monitor :session #'dbus--test-signal-handler)) | ||
| 1847 | '((:monitor :session-private) | ||
| 1848 | (nil nil dbus--test-signal-handler)))) | ||
| 1849 | |||
| 1850 | ;; Send a signal, shall be traced. | ||
| 1851 | (setq dbus--test-signal-received nil) | ||
| 1852 | (dbus-send-signal | ||
| 1853 | :session dbus--test-service dbus--test-path | ||
| 1854 | dbus--test-interface "Foo" "foo") | ||
| 1855 | (with-timeout (1 (dbus--test-timeout-handler)) | ||
| 1856 | (while (null dbus--test-signal-received) | ||
| 1857 | (read-event nil nil 0.1))) | ||
| 1858 | |||
| 1859 | ;; Unregister monitor. | ||
| 1860 | (should (dbus-unregister-object registered)) | ||
| 1861 | (should-not (dbus-unregister-object registered)) | ||
| 1862 | |||
| 1863 | ;; Send a signal, shall not be traced. | ||
| 1864 | (setq dbus--test-signal-received nil) | ||
| 1865 | (dbus-send-signal | ||
| 1866 | :session dbus--test-service dbus--test-path | ||
| 1867 | dbus--test-interface "Foo" "foo") | ||
| 1868 | (with-timeout (1 (ignore)) | ||
| 1869 | (while (null dbus--test-signal-received) | ||
| 1870 | (read-event nil nil 0.1))) | ||
| 1871 | (should-not dbus--test-signal-received)) | ||
| 1872 | |||
| 1873 | ;; Cleanup. | ||
| 1874 | (dbus-unregister-service :session dbus--test-service))) | ||
| 1875 | |||
| 1836 | (defun dbus-test-all (&optional interactive) | 1876 | (defun dbus-test-all (&optional interactive) |
| 1837 | "Run all tests for \\[dbus]." | 1877 | "Run all tests for \\[dbus]." |
| 1838 | (interactive "p") | 1878 | (interactive "p") |