diff options
| author | Michael Albinus | 2020-09-27 18:59:04 +0200 |
|---|---|---|
| committer | Michael Albinus | 2020-09-27 18:59:04 +0200 |
| commit | 4155ca273ade47bc7e19fe4af1f41c4e764a59ba (patch) | |
| tree | 27cb915a5768177b297966f083718d2c76b1a58d | |
| parent | f2a6bbefa919c0fcde66c0a8fb54aa5fb499de65 (diff) | |
| download | emacs-4155ca273ade47bc7e19fe4af1f41c4e764a59ba.tar.gz emacs-4155ca273ade47bc7e19fe4af1f41c4e764a59ba.zip | |
Document D-Bus monitoring
* doc/misc/dbus.texi: Replace "symbol" by "keyword" where appropriate.
(Alternative Buses): Adapt dbus-init-bus description.
(Errors and Events): Adapt dbus-event structure. New defuns
dbus-event-destination-name, dbus-event-handler and dbus-event-arguments.
(Monitoring Events): New node.
* lisp/net/dbus.el: Replace "symbol" by "keyword" where appropriate.
(cl-lib): Require.
(dbus-register-monitor): Adapt the argument list.
(dbus-monitor-handler): Extend.
(dbus-init-bus): Adapt docstring.
* test/lisp/net/dbus-tests.el (dbus-test01-compound-types):
Skip if needed. Extend test.
| -rw-r--r-- | doc/misc/dbus.texi | 165 | ||||
| -rw-r--r-- | lisp/net/dbus.el | 224 | ||||
| -rw-r--r-- | test/lisp/net/dbus-tests.el | 9 |
3 files changed, 250 insertions, 148 deletions
diff --git a/doc/misc/dbus.texi b/doc/misc/dbus.texi index 95d6523d36d..4b2eab4eb76 100644 --- a/doc/misc/dbus.texi +++ b/doc/misc/dbus.texi | |||
| @@ -63,6 +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 | * Index:: Index including concepts, functions, variables. | 67 | * Index:: Index including concepts, functions, variables. |
| 67 | 68 | ||
| 68 | * GNU Free Documentation License:: The license for this documentation. | 69 | * GNU Free Documentation License:: The license for this documentation. |
| @@ -162,12 +163,13 @@ registered names. Internally they use the basic interface | |||
| 162 | 163 | ||
| 163 | @defun dbus-list-activatable-names &optional bus | 164 | @defun dbus-list-activatable-names &optional bus |
| 164 | This function returns the D-Bus service names, which can be activated | 165 | This function returns the D-Bus service names, which can be activated |
| 165 | for @var{bus}. It must be either the symbol @code{:system} (the | 166 | for @var{bus}. It must be either the keyword @code{:system} (the |
| 166 | default) or the symbol @code{:session}. An activatable service is | 167 | default) or the keyword @code{:session}. An activatable service is |
| 167 | described in a service registration file. Under GNU/Linux, such files | 168 | described in a service registration file. Under GNU/Linux, such files |
| 168 | are located at @file{/usr/share/dbus-1/system-services/} (for the | 169 | are located at @file{/usr/share/dbus-1/system-services/} (for the |
| 169 | @code{:system} bus) or @file{/usr/share/dbus-1/services/}. An | 170 | @code{:system} bus) or @file{/usr/share/dbus-1/services/}. An |
| 170 | activatable service is not necessarily registered at @var{bus} already. | 171 | activatable service is not necessarily registered at @var{bus} |
| 172 | already. | ||
| 171 | 173 | ||
| 172 | The result is a list of strings, which is @code{nil} when there are no | 174 | The result is a list of strings, which is @code{nil} when there are no |
| 173 | activatable service names at all. Example: | 175 | activatable service names at all. Example: |
| @@ -186,7 +188,7 @@ there are no registered service names at all. Well known names are | |||
| 186 | strings like @samp{org.freedesktop.DBus}. Names starting with | 188 | strings like @samp{org.freedesktop.DBus}. Names starting with |
| 187 | @samp{:} are unique names for services. | 189 | @samp{:} are unique names for services. |
| 188 | 190 | ||
| 189 | @var{bus} must be either the symbol @code{:system} or the symbol | 191 | @var{bus} must be either the keyword @code{:system} or the keyword |
| 190 | @code{:session}. | 192 | @code{:session}. |
| 191 | @end defun | 193 | @end defun |
| 192 | 194 | ||
| @@ -196,7 +198,7 @@ known name in @var{bus}. A service has a known name if it doesn't | |||
| 196 | start with @samp{:}. The result is a list of strings, which is | 198 | start with @samp{:}. The result is a list of strings, which is |
| 197 | @code{nil} when there are no known names at all. | 199 | @code{nil} when there are no known names at all. |
| 198 | 200 | ||
| 199 | @var{bus} must be either the symbol @code{:system} or the symbol | 201 | @var{bus} must be either the keyword @code{:system} or the keyword |
| 200 | @code{:session}. | 202 | @code{:session}. |
| 201 | @end defun | 203 | @end defun |
| 202 | 204 | ||
| @@ -206,7 +208,7 @@ For a given service, registered at D-Bus @var{bus} under the name | |||
| 206 | result is a list of strings, or @code{nil} when there are no queued | 208 | result is a list of strings, or @code{nil} when there are no queued |
| 207 | names for @var{service} at all. | 209 | names for @var{service} at all. |
| 208 | 210 | ||
| 209 | @var{bus} must be either the symbol @code{:system} or the symbol | 211 | @var{bus} must be either the keyword @code{:system} or the keyword |
| 210 | @code{:session}. @var{service} must be a known service name as | 212 | @code{:session}. @var{service} must be a known service name as |
| 211 | string. | 213 | string. |
| 212 | @end defun | 214 | @end defun |
| @@ -217,7 +219,7 @@ For a given service, registered at D-Bus @var{bus} under the name | |||
| 217 | owner. The result is a string, or @code{nil} when there is no name | 219 | owner. The result is a string, or @code{nil} when there is no name |
| 218 | owner of @var{service}. | 220 | owner of @var{service}. |
| 219 | 221 | ||
| 220 | @var{bus} must be either the symbol @code{:system} or the symbol | 222 | @var{bus} must be either the keyword @code{:system} or the keyword |
| 221 | @code{:session}. @var{service} must be a known service name as | 223 | @code{:session}. @var{service} must be a known service name as |
| 222 | string. | 224 | string. |
| 223 | @end defun | 225 | @end defun |
| @@ -228,7 +230,7 @@ registered at D-Bus @var{bus}. If @var{service} has not yet started, | |||
| 228 | it is autostarted if possible. The result is either @code{t} or | 230 | it is autostarted if possible. The result is either @code{t} or |
| 229 | @code{nil}. | 231 | @code{nil}. |
| 230 | 232 | ||
| 231 | @var{bus} must be either the symbol @code{:system} or the symbol | 233 | @var{bus} must be either the keyword @code{:system} or the keyword |
| 232 | @code{:session}. @var{service} must be a string. @var{timeout}, a | 234 | @code{:session}. @var{service} must be a string. @var{timeout}, a |
| 233 | nonnegative integer, specifies the maximum number of milliseconds | 235 | nonnegative integer, specifies the maximum number of milliseconds |
| 234 | before @code{dbus-ping} must return. The default value is 25,000. | 236 | before @code{dbus-ping} must return. The default value is 25,000. |
| @@ -256,7 +258,7 @@ it, you can instead write: | |||
| 256 | This function returns the unique name, under which Emacs is registered | 258 | This function returns the unique name, under which Emacs is registered |
| 257 | at D-Bus @var{bus}, as a string. | 259 | at D-Bus @var{bus}, as a string. |
| 258 | 260 | ||
| 259 | @var{bus} must be either the symbol @code{:system} or the symbol | 261 | @var{bus} must be either the keyword @code{:system} or the keyword |
| 260 | @code{:session}. | 262 | @code{:session}. |
| 261 | @end defun | 263 | @end defun |
| 262 | 264 | ||
| @@ -375,7 +377,7 @@ must be strings. | |||
| 375 | This function returns all interfaces and sub-nodes of @var{service}, | 377 | This function returns all interfaces and sub-nodes of @var{service}, |
| 376 | registered at object path @var{path} at bus @var{bus}. | 378 | registered at object path @var{path} at bus @var{bus}. |
| 377 | 379 | ||
| 378 | @var{bus} must be either the symbol @code{:system} or the symbol | 380 | @var{bus} must be either the keyword @code{:system} or the keyword |
| 379 | @code{:session}. @var{service} must be a known service name, and | 381 | @code{:session}. @var{service} must be a known service name, and |
| 380 | @var{path} must be a valid object path. The last two parameters are | 382 | @var{path} must be a valid object path. The last two parameters are |
| 381 | strings. The result, the introspection data, is a string in XML | 383 | strings. The result, the introspection data, is a string in XML |
| @@ -747,8 +749,8 @@ or @var{property} cannot be read, an error is raised. Example: | |||
| 747 | @defun dbus-set-property bus service path interface property [type] value | 749 | @defun dbus-set-property bus service path interface property [type] value |
| 748 | This function sets the value of @var{property} of @var{interface} to | 750 | This function sets the value of @var{property} of @var{interface} to |
| 749 | @var{value}. It will be checked at @var{bus}, @var{service}, | 751 | @var{value}. It will be checked at @var{bus}, @var{service}, |
| 750 | @var{path}. @var{value} can be preceded by a @var{type} symbol. When | 752 | @var{path}. @var{value} can be preceded by a @var{type} keyword. |
| 751 | the value is successfully set, this function returns @var{value}. | 753 | When the value is successfully set, this function returns @var{value}. |
| 752 | Example: | 754 | Example: |
| 753 | 755 | ||
| 754 | @lisp | 756 | @lisp |
| @@ -999,8 +1001,8 @@ Other Lisp objects, like symbols or hash tables, are not accepted as | |||
| 999 | input parameters. | 1001 | input parameters. |
| 1000 | 1002 | ||
| 1001 | If it is necessary to use another D-Bus type, a corresponding type | 1003 | If it is necessary to use another D-Bus type, a corresponding type |
| 1002 | symbol can be prepended to the corresponding Lisp object. Basic D-Bus | 1004 | keyword can be prepended to the corresponding Lisp object. Basic |
| 1003 | types are represented by the type symbols @code{:byte}, | 1005 | D-Bus types are represented by the type keywords @code{:byte}, |
| 1004 | @code{:boolean}, @code{:int16}, @code{:uint16}, @code{:int32}, | 1006 | @code{:boolean}, @code{:int16}, @code{:uint16}, @code{:int32}, |
| 1005 | @code{:uint32}, @code{:int64}, @code{:uint64}, @code{:double}, | 1007 | @code{:uint32}, @code{:int64}, @code{:uint64}, @code{:double}, |
| 1006 | @code{:string}, @code{:object-path}, @code{:signature} and | 1008 | @code{:string}, @code{:object-path}, @code{:signature} and |
| @@ -1040,7 +1042,7 @@ If typed explicitly, a non-@code{nil} boolean value like | |||
| 1040 | @code{:boolean 'symbol} is handled like @code{t} or @code{:boolean t}. | 1042 | @code{:boolean 'symbol} is handled like @code{t} or @code{:boolean t}. |
| 1041 | 1043 | ||
| 1042 | A D-Bus compound type is always represented as a list. The @sc{car} | 1044 | A D-Bus compound type is always represented as a list. The @sc{car} |
| 1043 | of this list can be the type symbol @code{:array}, @code{:variant}, | 1045 | of this list can be the type keyword @code{:array}, @code{:variant}, |
| 1044 | @code{:struct} or @code{:dict-entry}, which would result in a | 1046 | @code{:struct} or @code{:dict-entry}, which would result in a |
| 1045 | corresponding D-Bus container. @code{:array} is optional, because | 1047 | corresponding D-Bus container. @code{:array} is optional, because |
| 1046 | this is the default compound D-Bus type for a list. | 1048 | this is the default compound D-Bus type for a list. |
| @@ -1215,7 +1217,7 @@ parameters from the object. | |||
| 1215 | @defun dbus-call-method bus service path interface method &optional :timeout timeout &rest args | 1217 | @defun dbus-call-method bus service path interface method &optional :timeout timeout &rest args |
| 1216 | @anchor{dbus-call-method} | 1218 | @anchor{dbus-call-method} |
| 1217 | This function calls @var{method} on the D-Bus @var{bus}. @var{bus} is | 1219 | This function calls @var{method} on the D-Bus @var{bus}. @var{bus} is |
| 1218 | either the symbol @code{:system} or the symbol @code{:session}. | 1220 | either the keyword @code{:system} or the keyword @code{:session}. |
| 1219 | 1221 | ||
| 1220 | @var{service} is the D-Bus service name to be used. @var{path} is the | 1222 | @var{service} is the D-Bus service name to be used. @var{path} is the |
| 1221 | D-Bus object path, @var{service} is registered at. @var{interface} is | 1223 | D-Bus object path, @var{service} is registered at. @var{interface} is |
| @@ -1308,8 +1310,8 @@ emulate the @code{lshal} command on GNU/Linux systems: | |||
| 1308 | 1310 | ||
| 1309 | @defun dbus-call-method-asynchronously bus service path interface method handler &optional :timeout timeout &rest args | 1311 | @defun dbus-call-method-asynchronously bus service path interface method handler &optional :timeout timeout &rest args |
| 1310 | This function calls @var{method} on the D-Bus @var{bus} | 1312 | This function calls @var{method} on the D-Bus @var{bus} |
| 1311 | asynchronously. @var{bus} is either the symbol @code{:system} or the | 1313 | asynchronously. @var{bus} is either the keyword @code{:system} or the |
| 1312 | symbol @code{:session}. | 1314 | keyword @code{:session}. |
| 1313 | 1315 | ||
| 1314 | @var{service} is the D-Bus service name to be used. @var{path} is the | 1316 | @var{service} is the D-Bus service name to be used. @var{path} is the |
| 1315 | D-Bus object path, @var{service} is registered at. @var{interface} is | 1317 | D-Bus object path, @var{service} is registered at. @var{interface} is |
| @@ -1369,7 +1371,7 @@ the following functions: | |||
| 1369 | This function registers the known name @var{service} on D-Bus | 1371 | This function registers the known name @var{service} on D-Bus |
| 1370 | @var{bus}. | 1372 | @var{bus}. |
| 1371 | 1373 | ||
| 1372 | @var{bus} is either the symbol @code{:system} or the symbol | 1374 | @var{bus} is either the keyword @code{:system} or the keyword |
| 1373 | @code{:session}. | 1375 | @code{:session}. |
| 1374 | 1376 | ||
| 1375 | @var{service} is the service name to be registered on the D-Bus. It | 1377 | @var{service} is the service name to be registered on the D-Bus. It |
| @@ -1405,7 +1407,7 @@ We already are the primary owner. | |||
| 1405 | This function unregisters all objects from D-Bus @var{bus}, that were | 1407 | This function unregisters all objects from D-Bus @var{bus}, that were |
| 1406 | registered by Emacs for @var{service}. | 1408 | registered by Emacs for @var{service}. |
| 1407 | 1409 | ||
| 1408 | @var{bus} is either the symbol @code{:system} or the symbol | 1410 | @var{bus} is either the keyword @code{:system} or the keyword |
| 1409 | @code{:session}. | 1411 | @code{:session}. |
| 1410 | 1412 | ||
| 1411 | @var{service} is the D-Bus service name of the D-Bus. It must be a | 1413 | @var{service} is the D-Bus service name of the D-Bus. It must be a |
| @@ -1452,7 +1454,7 @@ The interface namespace @code{org.gnu.Emacs} used by Emacs. | |||
| 1452 | With this function, an application registers @var{method} on the D-Bus | 1454 | With this function, an application registers @var{method} on the D-Bus |
| 1453 | @var{bus}. | 1455 | @var{bus}. |
| 1454 | 1456 | ||
| 1455 | @var{bus} is either the symbol @code{:system} or the symbol | 1457 | @var{bus} is either the keyword @code{:system} or the keyword |
| 1456 | @code{:session}. | 1458 | @code{:session}. |
| 1457 | 1459 | ||
| 1458 | @var{service} is the D-Bus service name of the D-Bus object | 1460 | @var{service} is the D-Bus service name of the D-Bus object |
| @@ -1477,8 +1479,8 @@ cons cell, @var{handler} can return this object directly, instead of | |||
| 1477 | returning a list containing the object. | 1479 | returning a list containing the object. |
| 1478 | 1480 | ||
| 1479 | If @var{handler} returns a reply message with an empty argument list, | 1481 | If @var{handler} returns a reply message with an empty argument list, |
| 1480 | @var{handler} must return the symbol @code{:ignore} in order | 1482 | @var{handler} must return the keyword @code{:ignore} in order to |
| 1481 | to distinguish it from @code{nil} (the boolean false). | 1483 | distinguish it from @code{nil} (the boolean false). |
| 1482 | 1484 | ||
| 1483 | If @var{handler} detects an error, it shall return the list | 1485 | If @var{handler} detects an error, it shall return the list |
| 1484 | @code{(:error @var{error-name} @var{error-message})}. | 1486 | @code{(:error @var{error-name} @var{error-message})}. |
| @@ -1580,7 +1582,7 @@ The test then runs | |||
| 1580 | With this function, an application declares a @var{property} on the D-Bus | 1582 | With this function, an application declares a @var{property} on the D-Bus |
| 1581 | @var{bus}. | 1583 | @var{bus}. |
| 1582 | 1584 | ||
| 1583 | @var{bus} is either the symbol @code{:system} or the symbol | 1585 | @var{bus} is either the keyword @code{:system} or the keyword |
| 1584 | @code{:session}. | 1586 | @code{:session}. |
| 1585 | 1587 | ||
| 1586 | @var{service} is the D-Bus service name of the D-Bus. It must be a | 1588 | @var{service} is the D-Bus service name of the D-Bus. It must be a |
| @@ -1593,12 +1595,12 @@ discussion of @var{dont-register-service} below). | |||
| 1593 | @var{property} is the name of the property of @var{interface}. | 1595 | @var{property} is the name of the property of @var{interface}. |
| 1594 | 1596 | ||
| 1595 | @var{access} indicates, whether the property can be changed by other | 1597 | @var{access} indicates, whether the property can be changed by other |
| 1596 | services via D-Bus. It must be either the symbol @code{:read}, | 1598 | services via D-Bus. It must be either the keyword @code{:read}, |
| 1597 | @code{:write} or @code{:readwrite}. | 1599 | @code{:write} or @code{:readwrite}. |
| 1598 | 1600 | ||
| 1599 | @var{value} is the initial value of the property, it can be of any | 1601 | @var{value} is the initial value of the property, it can be of any |
| 1600 | valid type (@xref{dbus-call-method}, for details). @var{value} can be | 1602 | valid type (@xref{dbus-call-method}, for details). @var{value} can be |
| 1601 | preceded by a @var{type} symbol. | 1603 | preceded by a @var{type} keyword. |
| 1602 | 1604 | ||
| 1603 | If @var{property} already exists on @var{path}, it will be | 1605 | If @var{property} already exists on @var{path}, it will be |
| 1604 | overwritten. For properties with access type @code{:read} this is the | 1606 | overwritten. For properties with access type @code{:read} this is the |
| @@ -1707,7 +1709,7 @@ This function is similar to @code{dbus-call-method}. The difference | |||
| 1707 | is, that there are no returning output parameters. | 1709 | is, that there are no returning output parameters. |
| 1708 | 1710 | ||
| 1709 | The function emits @var{signal} on the D-Bus @var{bus}. @var{bus} is | 1711 | The function emits @var{signal} on the D-Bus @var{bus}. @var{bus} is |
| 1710 | either the symbol @code{:system} or the symbol @code{:session}. It | 1712 | either the keyword @code{:system} or the keyword @code{:session}. It |
| 1711 | doesn't matter whether another object has registered for @var{signal}. | 1713 | doesn't matter whether another object has registered for @var{signal}. |
| 1712 | 1714 | ||
| 1713 | Signals can be unicast or broadcast messages. For broadcast messages, | 1715 | Signals can be unicast or broadcast messages. For broadcast messages, |
| @@ -1735,7 +1737,7 @@ arguments. They are converted into D-Bus types as described in | |||
| 1735 | With this function, an application registers for a signal on the D-Bus | 1737 | With this function, an application registers for a signal on the D-Bus |
| 1736 | @var{bus}. | 1738 | @var{bus}. |
| 1737 | 1739 | ||
| 1738 | @var{bus} is either the symbol @code{:system} or the symbol | 1740 | @var{bus} is either the keyword @code{:system} or the keyword |
| 1739 | @code{:session}. | 1741 | @code{:session}. |
| 1740 | 1742 | ||
| 1741 | @var{service} is the D-Bus service name used by the sending D-Bus | 1743 | @var{service} is the D-Bus service name used by the sending D-Bus |
| @@ -1837,18 +1839,17 @@ Until now, we have spoken about the system and the session buses, | |||
| 1837 | which are the default buses to be connected to. However, it is | 1839 | which are the default buses to be connected to. However, it is |
| 1838 | possible to connect to any bus with a known address. This is a UNIX | 1840 | possible to connect to any bus with a known address. This is a UNIX |
| 1839 | domain or TCP/IP socket. Everywhere, where a @var{bus} is mentioned | 1841 | domain or TCP/IP socket. Everywhere, where a @var{bus} is mentioned |
| 1840 | as argument of a function (the symbol @code{:system} or the symbol | 1842 | as argument of a function (the keyword @code{:system} or the keyword |
| 1841 | @code{:session}), this address can be used instead. The connection to | 1843 | @code{:session}), this address can be used instead. The connection to |
| 1842 | this bus must be initialized first. | 1844 | this bus must be initialized first. |
| 1843 | 1845 | ||
| 1844 | @defun dbus-init-bus bus &optional private | 1846 | @defun dbus-init-bus bus &optional private |
| 1845 | This function establishes the connection to D-Bus @var{bus}. | 1847 | This function establishes the connection to D-Bus @var{bus}. |
| 1846 | 1848 | ||
| 1847 | @var{bus} can be either the symbol @code{:system} or the symbol | 1849 | @var{bus} can be either the keyword @code{:system} or the keyword |
| 1848 | @code{:session}, or it can be a string denoting the address of the | 1850 | @code{:session}, or it can be a string denoting the address of the |
| 1849 | corresponding bus. For the system and session buses, this function | 1851 | corresponding bus. For the system and session buses, this function is |
| 1850 | is called when loading @file{dbus.el}, there is no need to call it | 1852 | called when loading @file{dbus.el}, there is no need to call it again. |
| 1851 | again. | ||
| 1852 | 1853 | ||
| 1853 | The function returns the number of connections this Emacs session has | 1854 | The function returns the number of connections this Emacs session has |
| 1854 | established to the @var{bus} under the same unique name | 1855 | established to the @var{bus} under the same unique name |
| @@ -1860,11 +1861,12 @@ established. | |||
| 1860 | 1861 | ||
| 1861 | When @var{private} is non-@code{nil}, a new connection is established | 1862 | When @var{private} is non-@code{nil}, a new connection is established |
| 1862 | instead of reusing an existing one. It results in a new unique name | 1863 | instead of reusing an existing one. It results in a new unique name |
| 1863 | at the bus. This can be used, if it is necessary to distinguish from | 1864 | at the @var{bus}. This can be used, if it is necessary to distinguish |
| 1864 | another connection used in the same Emacs process, like the one | 1865 | from another connection used in the same Emacs process, like the one |
| 1865 | established by GTK+. It should be used with care for at least the | 1866 | established by GTK+. If @var{bus} is the keyword @code{:system} or |
| 1866 | @code{:system} and @code{:session} buses, because other Emacs Lisp | 1867 | the keyword @code{:session}, the new private connection is identified |
| 1867 | packages might already use this connection to those buses. | 1868 | by the keywords @code{:system-private} or @code{:session-private}, |
| 1869 | respectively. | ||
| 1868 | 1870 | ||
| 1869 | Example: You initialize a connection to the AT-SPI bus on your host: | 1871 | Example: You initialize a connection to the AT-SPI bus on your host: |
| 1870 | 1872 | ||
| @@ -1907,7 +1909,7 @@ is supported depends on the bus daemon configuration, however. | |||
| 1907 | This function sets the value of the @var{bus} environment | 1909 | This function sets the value of the @var{bus} environment |
| 1908 | @var{variable} to @var{value}. | 1910 | @var{variable} to @var{value}. |
| 1909 | 1911 | ||
| 1910 | @var{bus} is either a Lisp symbol, @code{:system} or @code{:session}, | 1912 | @var{bus} is either a Lisp keyword, @code{:system} or @code{:session}, |
| 1911 | or a string denoting the bus address. Both @var{variable} and | 1913 | or a string denoting the bus address. Both @var{variable} and |
| 1912 | @var{value} should be strings. | 1914 | @var{value} should be strings. |
| 1913 | 1915 | ||
| @@ -1973,23 +1975,31 @@ Events, , , elisp}. They are retrieved only, when Emacs runs in | |||
| 1973 | interactive mode. The generated event has this form: | 1975 | interactive mode. The generated event has this form: |
| 1974 | 1976 | ||
| 1975 | @lisp | 1977 | @lisp |
| 1976 | (dbus-event @var{bus} @var{type} @var{serial} @var{service} @var{path} @var{interface} @var{member} @var{handler} | 1978 | (dbus-event @var{bus} @var{type} @var{serial} @var{service} @var{destination} @var{path} @var{interface} @var{member} |
| 1977 | &rest @var{args}) | 1979 | @var{handler} &rest @var{args}) |
| 1978 | @end lisp | 1980 | @end lisp |
| 1979 | 1981 | ||
| 1980 | @var{bus} identifies the D-Bus the message is coming from. It is | 1982 | @var{bus} identifies the D-Bus the message is coming from. It is |
| 1981 | either the symbol @code{:system} or the symbol @code{:session}. | 1983 | either a Lisp keyword, @code{:system}, @code{:session}, |
| 1984 | @code{:system-private} or @code{:session-private}, or a string | ||
| 1985 | denoting the bus address. | ||
| 1982 | 1986 | ||
| 1983 | @var{type} is the D-Bus message type which has caused the event. It | 1987 | @var{type} is the D-Bus message type which has caused the event. It |
| 1984 | can be @code{dbus-message-type-invalid}, | 1988 | can be @code{dbus-message-type-invalid}, |
| 1985 | @code{dbus-message-type-method-call}, | 1989 | @code{dbus-message-type-method-call}, |
| 1986 | @code{dbus-message-type-method-return}, | 1990 | @code{dbus-message-type-method-return}, |
| 1987 | @code{dbus-message-type-error}, or @code{dbus-message-type-signal}. | 1991 | @code{dbus-message-type-error}, or @code{dbus-message-type-signal}. |
| 1988 | @var{serial} is the serial number of the received D-Bus message. | 1992 | @var{serial} is the serial number of the received D-Bus message, |
| 1993 | unless @var{type} is equal @code{dbus-message-type-error}. | ||
| 1989 | 1994 | ||
| 1990 | @var{service} and @var{path} are the unique name and the object path | 1995 | @var{service} and @var{path} are the unique name and the object path |
| 1991 | of the D-Bus object emitting the message. @var{interface} and | 1996 | of the D-Bus object emitting the message. @var{destination} is the |
| 1992 | @var{member} denote the message which has been sent. | 1997 | D-Bus name the message is dedicated to, or @code{nil} in case the |
| 1998 | message is a broadcast signal. | ||
| 1999 | |||
| 2000 | @var{interface} and @var{member} denote the message which has been | ||
| 2001 | sent. When @var{type} is @code{dbus-message-type-error}, @var{member} | ||
| 2002 | is the error name. | ||
| 1993 | 2003 | ||
| 1994 | @var{handler} is the callback function which has been registered for | 2004 | @var{handler} is the callback function which has been registered for |
| 1995 | this message (@pxref{Signals}). @var{args} are the typed arguments as | 2005 | this message (@pxref{Signals}). @var{args} are the typed arguments as |
| @@ -2010,7 +2020,7 @@ callback function in order to retrieve the information from the event. | |||
| 2010 | 2020 | ||
| 2011 | @defun dbus-event-bus-name event | 2021 | @defun dbus-event-bus-name event |
| 2012 | This function returns the bus name @var{event} is coming from. The | 2022 | This function returns the bus name @var{event} is coming from. The |
| 2013 | result is either the symbol @code{:system} or the symbol | 2023 | result is either the keyword @code{:system} or the keyword |
| 2014 | @code{:session}. | 2024 | @code{:session}. |
| 2015 | @end defun | 2025 | @end defun |
| 2016 | 2026 | ||
| @@ -2029,6 +2039,11 @@ This function returns the unique name of the D-Bus object @var{event} | |||
| 2029 | is coming from. | 2039 | is coming from. |
| 2030 | @end defun | 2040 | @end defun |
| 2031 | 2041 | ||
| 2042 | @defun dbus-event-destination-name event | ||
| 2043 | This function returns the unique name of the D-Bus object @var{event} | ||
| 2044 | is dedicated to. | ||
| 2045 | @end defun | ||
| 2046 | |||
| 2032 | @defun dbus-event-path-name event | 2047 | @defun dbus-event-path-name event |
| 2033 | This function returns the object path of the D-Bus object @var{event} | 2048 | This function returns the object path of the D-Bus object @var{event} |
| 2034 | is coming from. | 2049 | is coming from. |
| @@ -2044,6 +2059,16 @@ This function returns the member name of the D-Bus object @var{event} | |||
| 2044 | is coming from. It is either a signal name or a method name. | 2059 | is coming from. It is either a signal name or a method name. |
| 2045 | @end defun | 2060 | @end defun |
| 2046 | 2061 | ||
| 2062 | @defun dbus-event-handler event | ||
| 2063 | This function returns the handler the D-Bus object @var{event} is | ||
| 2064 | applied with. | ||
| 2065 | @end defun | ||
| 2066 | |||
| 2067 | @defun dbus-event-arguments event | ||
| 2068 | This function returns the arguments the D-Bus object @var{event} is | ||
| 2069 | carrying on. | ||
| 2070 | @end defun | ||
| 2071 | |||
| 2047 | D-Bus errors are not propagated during event handling, because it is | 2072 | D-Bus errors are not propagated during event handling, because it is |
| 2048 | usually not desired. D-Bus errors in events can be made visible by | 2073 | usually not desired. D-Bus errors in events can be made visible by |
| 2049 | setting the variable @code{dbus-debug} to non-@code{nil}. They can | 2074 | setting the variable @code{dbus-debug} to non-@code{nil}. They can |
| @@ -2074,6 +2099,54 @@ D-Bus applications running. They should therefore check carefully, | |||
| 2074 | whether a given D-Bus error is related to them. | 2099 | whether a given D-Bus error is related to them. |
| 2075 | 2100 | ||
| 2076 | 2101 | ||
| 2102 | @node Monitoring Events | ||
| 2103 | @chapter Monitoring events. | ||
| 2104 | @cindex monitoring | ||
| 2105 | |||
| 2106 | @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 | ||
| 2108 | @var{bus}. | ||
| 2109 | |||
| 2110 | @var{bus} is either a Lisp keyword, @code{:system} or @code{:session}, | ||
| 2111 | or a string denoting the bus address. | ||
| 2112 | |||
| 2113 | @findex dbus-monitor-handler | ||
| 2114 | @var{handler} is the function to be called when a monitor event | ||
| 2115 | arrives. It is called with the `args' slot of the monitor event, | ||
| 2116 | which are stripped off the type keywords. If @var{handler} is | ||
| 2117 | @code{nil}, the default handler @code{dbus-monitor-handler} is | ||
| 2118 | applied. This default handler behaves similar to the | ||
| 2119 | @command{dbus-monitor} program. | ||
| 2120 | |||
| 2121 | 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 | ||
| 2123 | one of the strings @samp{method_call}, @samp{method_return}, | ||
| 2124 | @samp{error} or @samp{signal}. | ||
| 2125 | |||
| 2126 | @code{:sender @var{sender}} and @code{:destination @var{destination}} | ||
| 2127 | are D-Bus names. They can be unique names, or well-known service | ||
| 2128 | names. | ||
| 2129 | |||
| 2130 | @code{:path @var{path}} is the D-Bus object to be monitored. | ||
| 2131 | @code{:interface @var{interface}} is the name of an interface, and | ||
| 2132 | @code{:member @var{member}} is either a method name, a signal name, or | ||
| 2133 | an error name. | ||
| 2134 | |||
| 2135 | The following form shows all D-Bus events on the session bus in buffer | ||
| 2136 | @samp{*D-Bus Monitor*}: | ||
| 2137 | |||
| 2138 | @lisp | ||
| 2139 | (dbus-register-monitor :session) | ||
| 2140 | @end lisp | ||
| 2141 | |||
| 2142 | And this form restricts the monitoring on D-Bus errors: | ||
| 2143 | |||
| 2144 | @lisp | ||
| 2145 | (dbus-register-monitor :session nil :type "error") | ||
| 2146 | @end lisp | ||
| 2147 | @end defun | ||
| 2148 | |||
| 2149 | |||
| 2077 | @node Index | 2150 | @node Index |
| 2078 | @unnumbered Index | 2151 | @unnumbered Index |
| 2079 | 2152 | ||
diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el index da47e5bc7f2..b1bea55d982 100644 --- a/lisp/net/dbus.el +++ b/lisp/net/dbus.el | |||
| @@ -51,6 +51,7 @@ | |||
| 51 | (unless (boundp 'dbus-debug) | 51 | (unless (boundp 'dbus-debug) |
| 52 | (defvar dbus-debug nil)) | 52 | (defvar dbus-debug nil)) |
| 53 | 53 | ||
| 54 | (require 'cl-lib) | ||
| 54 | (require 'seq) | 55 | (require 'seq) |
| 55 | (require 'subr-x) | 56 | (require 'subr-x) |
| 56 | (require 'xml) | 57 | (require 'xml) |
| @@ -245,7 +246,7 @@ caught in `condition-case' by `dbus-error'.") | |||
| 245 | (defvar dbus-return-values-table (make-hash-table :test #'equal) | 246 | (defvar dbus-return-values-table (make-hash-table :test #'equal) |
| 246 | "Hash table for temporarily storing arguments of reply messages. | 247 | "Hash table for temporarily storing arguments of reply messages. |
| 247 | A key in this hash table is a list (:serial BUS SERIAL), like in | 248 | A key in this hash table is a list (:serial BUS SERIAL), like in |
| 248 | `dbus-registered-objects-table'. BUS is either a Lisp symbol, | 249 | `dbus-registered-objects-table'. BUS is either a Lisp keyword, |
| 249 | `:system' or `:session', or a string denoting the bus address. | 250 | `:system' or `:session', or a string denoting the bus address. |
| 250 | SERIAL is the serial number of the reply message. | 251 | SERIAL is the serial number of the reply message. |
| 251 | 252 | ||
| @@ -279,8 +280,8 @@ The result will be made available in `dbus-return-values-table'." | |||
| 279 | (defun dbus-call-method (bus service path interface method &rest args) | 280 | (defun dbus-call-method (bus service path interface method &rest args) |
| 280 | "Call METHOD on the D-Bus BUS. | 281 | "Call METHOD on the D-Bus BUS. |
| 281 | 282 | ||
| 282 | BUS is either a Lisp symbol, `:system' or `:session', or a string | 283 | BUS is either a Lisp keyword, `:system' or `:session', or a |
| 283 | denoting the bus address. | 284 | string denoting the bus address. |
| 284 | 285 | ||
| 285 | SERVICE is the D-Bus service name to be used. PATH is the D-Bus | 286 | SERVICE is the D-Bus service name to be used. PATH is the D-Bus |
| 286 | object path SERVICE is registered at. INTERFACE is an interface | 287 | object path SERVICE is registered at. INTERFACE is an interface |
| @@ -301,8 +302,8 @@ converted into D-Bus types via the following rules: | |||
| 301 | string => DBUS_TYPE_STRING | 302 | string => DBUS_TYPE_STRING |
| 302 | list => DBUS_TYPE_ARRAY | 303 | list => DBUS_TYPE_ARRAY |
| 303 | 304 | ||
| 304 | All arguments can be preceded by a type symbol. For details about | 305 | All arguments can be preceded by a type keyword. For details |
| 305 | type symbols, see Info node `(dbus)Type Conversion'. | 306 | about type keywords, see Info node `(dbus)Type Conversion'. |
| 306 | 307 | ||
| 307 | `dbus-call-method' returns the resulting values of METHOD as a list of | 308 | `dbus-call-method' returns the resulting values of METHOD as a list of |
| 308 | Lisp objects. The type conversion happens the other direction as for | 309 | Lisp objects. The type conversion happens the other direction as for |
| @@ -405,8 +406,8 @@ object is returned instead of a list containing this single Lisp object. | |||
| 405 | (bus service path interface method handler &rest args) | 406 | (bus service path interface method handler &rest args) |
| 406 | "Call METHOD on the D-Bus BUS asynchronously. | 407 | "Call METHOD on the D-Bus BUS asynchronously. |
| 407 | 408 | ||
| 408 | BUS is either a Lisp symbol, `:system' or `:session', or a string | 409 | BUS is either a Lisp keyword, `:system' or `:session', or a |
| 409 | denoting the bus address. | 410 | string denoting the bus address. |
| 410 | 411 | ||
| 411 | SERVICE is the D-Bus service name to be used. PATH is the D-Bus | 412 | SERVICE is the D-Bus service name to be used. PATH is the D-Bus |
| 412 | object path SERVICE is registered at. INTERFACE is an interface | 413 | object path SERVICE is registered at. INTERFACE is an interface |
| @@ -431,8 +432,8 @@ converted into D-Bus types via the following rules: | |||
| 431 | string => DBUS_TYPE_STRING | 432 | string => DBUS_TYPE_STRING |
| 432 | list => DBUS_TYPE_ARRAY | 433 | list => DBUS_TYPE_ARRAY |
| 433 | 434 | ||
| 434 | All arguments can be preceded by a type symbol. For details about | 435 | All arguments can be preceded by a type keyword. For details |
| 435 | type symbols, see Info node `(dbus)Type Conversion'. | 436 | about type keywords, see Info node `(dbus)Type Conversion'. |
| 436 | 437 | ||
| 437 | If HANDLER is a Lisp function, the function returns a key into the | 438 | If HANDLER is a Lisp function, the function returns a key into the |
| 438 | hash table `dbus-registered-objects-table'. The corresponding entry | 439 | hash table `dbus-registered-objects-table'. The corresponding entry |
| @@ -472,9 +473,9 @@ Example: | |||
| 472 | (defun dbus-send-signal (bus service path interface signal &rest args) | 473 | (defun dbus-send-signal (bus service path interface signal &rest args) |
| 473 | "Send signal SIGNAL on the D-Bus BUS. | 474 | "Send signal SIGNAL on the D-Bus BUS. |
| 474 | 475 | ||
| 475 | BUS is either a Lisp symbol, `:system' or `:session', or a string | 476 | BUS is either a Lisp keyword, `:system' or `:session', or a |
| 476 | denoting the bus address. The signal is sent from the D-Bus object | 477 | string denoting the bus address. The signal is sent from the |
| 477 | Emacs is registered at BUS. | 478 | D-Bus object Emacs is registered at BUS. |
| 478 | 479 | ||
| 479 | SERVICE is the D-Bus name SIGNAL is sent to. It can be either a known | 480 | SERVICE is the D-Bus name SIGNAL is sent to. It can be either a known |
| 480 | name or a unique name. If SERVICE is nil, the signal is sent as | 481 | name or a unique name. If SERVICE is nil, the signal is sent as |
| @@ -492,8 +493,8 @@ converted into D-Bus types via the following rules: | |||
| 492 | string => DBUS_TYPE_STRING | 493 | string => DBUS_TYPE_STRING |
| 493 | list => DBUS_TYPE_ARRAY | 494 | list => DBUS_TYPE_ARRAY |
| 494 | 495 | ||
| 495 | All arguments can be preceded by a type symbol. For details about | 496 | All arguments can be preceded by a type keyword. For details |
| 496 | type symbols, see Info node `(dbus)Type Conversion'. | 497 | about type keywords, see Info node `(dbus)Type Conversion'. |
| 497 | 498 | ||
| 498 | Example: | 499 | Example: |
| 499 | 500 | ||
| @@ -586,8 +587,9 @@ hash table." | |||
| 586 | (defun dbus-setenv (bus variable value) | 587 | (defun dbus-setenv (bus variable value) |
| 587 | "Set the value of the BUS environment variable named VARIABLE to VALUE. | 588 | "Set the value of the BUS environment variable named VARIABLE to VALUE. |
| 588 | 589 | ||
| 589 | BUS is either a Lisp symbol, `:system' or `:session', or a string | 590 | BUS is either a Lisp keyword, `:system' or `:session', or a |
| 590 | denoting the bus address. Both VARIABLE and VALUE should be strings. | 591 | string denoting the bus address. Both VARIABLE and VALUE should |
| 592 | be strings. | ||
| 591 | 593 | ||
| 592 | Normally, services inherit the environment of the BUS daemon. This | 594 | Normally, services inherit the environment of the BUS daemon. This |
| 593 | function adds to or modifies that environment when activating services. | 595 | function adds to or modifies that environment when activating services. |
| @@ -601,8 +603,8 @@ Some bus instances, such as `:system', may disable setting the environment." | |||
| 601 | (defun dbus-register-service (bus service &rest flags) | 603 | (defun dbus-register-service (bus service &rest flags) |
| 602 | "Register known name SERVICE on the D-Bus BUS. | 604 | "Register known name SERVICE on the D-Bus BUS. |
| 603 | 605 | ||
| 604 | BUS is either a Lisp symbol, `:system' or `:session', or a string | 606 | BUS is either a Lisp keyword, `:system' or `:session', or a |
| 605 | denoting the bus address. | 607 | string denoting the bus address. |
| 606 | 608 | ||
| 607 | SERVICE is the D-Bus service name that should be registered. It must | 609 | SERVICE is the D-Bus service name that should be registered. It must |
| 608 | be a known name. | 610 | be a known name. |
| @@ -663,8 +665,9 @@ placed in the queue. | |||
| 663 | 665 | ||
| 664 | (defun dbus-unregister-service (bus service) | 666 | (defun dbus-unregister-service (bus service) |
| 665 | "Unregister all objects related to SERVICE from D-Bus BUS. | 667 | "Unregister all objects related to SERVICE from D-Bus BUS. |
| 666 | BUS is either a Lisp symbol, `:system' or `:session', or a string | 668 | BUS is either a Lisp keyword, `:system' or `:session', or a |
| 667 | denoting the bus address. SERVICE must be a known service name. | 669 | string denoting the bus address. SERVICE must be a known service |
| 670 | name. | ||
| 668 | 671 | ||
| 669 | The function returns a keyword, indicating the result of the | 672 | The function returns a keyword, indicating the result of the |
| 670 | operation. One of the following keywords is returned: | 673 | operation. One of the following keywords is returned: |
| @@ -699,8 +702,8 @@ queue of this service." | |||
| 699 | (bus service path interface signal handler &rest args) | 702 | (bus service path interface signal handler &rest args) |
| 700 | "Register for a signal on the D-Bus BUS. | 703 | "Register for a signal on the D-Bus BUS. |
| 701 | 704 | ||
| 702 | BUS is either a Lisp symbol, `:system' or `:session', or a string | 705 | BUS is either a Lisp keyword, `:system' or `:session', or a |
| 703 | denoting the bus address. | 706 | string denoting the bus address. |
| 704 | 707 | ||
| 705 | SERVICE is the D-Bus service name used by the sending D-Bus object. | 708 | SERVICE is the D-Bus service name used by the sending D-Bus object. |
| 706 | It can be either a known name or the unique name of the D-Bus object | 709 | It can be either a known name or the unique name of the D-Bus object |
| @@ -854,8 +857,8 @@ Example: | |||
| 854 | (bus service path interface method handler &optional dont-register-service) | 857 | (bus service path interface method handler &optional dont-register-service) |
| 855 | "Register METHOD on the D-Bus BUS. | 858 | "Register METHOD on the D-Bus BUS. |
| 856 | 859 | ||
| 857 | BUS is either a Lisp symbol, `:system' or `:session', or a string | 860 | BUS is either a Lisp keyword, `:system' or `:session', or a |
| 858 | denoting the bus address. | 861 | string denoting the bus address. |
| 859 | 862 | ||
| 860 | SERVICE is the D-Bus service name of the D-Bus object METHOD is | 863 | SERVICE is the D-Bus service name of the D-Bus object METHOD is |
| 861 | registered for. It must be a known name (see discussion of | 864 | registered for. It must be a known name (see discussion of |
| @@ -869,7 +872,7 @@ HANDLER is a Lisp function to be called when a method call is | |||
| 869 | received. It must accept the input arguments of METHOD. The | 872 | received. It must accept the input arguments of METHOD. The |
| 870 | return value of HANDLER is used for composing the returning D-Bus | 873 | return value of HANDLER is used for composing the returning D-Bus |
| 871 | message. If HANDLER returns a reply message with an empty | 874 | message. If HANDLER returns a reply message with an empty |
| 872 | argument list, HANDLER must return the symbol `:ignore' in order | 875 | argument list, HANDLER must return the keyword `:ignore' in order |
| 873 | to distinguish it from nil (the boolean false). | 876 | to distinguish it from nil (the boolean false). |
| 874 | 877 | ||
| 875 | If HANDLER detects an error, it shall return the list `(:error | 878 | If HANDLER detects an error, it shall return the list `(:error |
| @@ -1039,7 +1042,7 @@ EVENT is a list which starts with symbol `dbus-event': | |||
| 1039 | INTERFACE MEMBER HANDLER &rest ARGS) | 1042 | INTERFACE MEMBER HANDLER &rest ARGS) |
| 1040 | 1043 | ||
| 1041 | BUS identifies the D-Bus the message is coming from. It is | 1044 | BUS identifies the D-Bus the message is coming from. It is |
| 1042 | either a Lisp symbol, `:system', `:session', `:systemp-private' | 1045 | either a Lisp keyword, `:system', `:session', `:systemp-private' |
| 1043 | or `:session-private', or a string denoting the bus address. | 1046 | or `:session-private', or a string denoting the bus address. |
| 1044 | 1047 | ||
| 1045 | TYPE is the D-Bus message type which has caused the event, SERIAL | 1048 | TYPE is the D-Bus message type which has caused the event, SERIAL |
| @@ -1048,7 +1051,7 @@ equal `dbus-message-type-method-return' or `dbus-message-type-error'. | |||
| 1048 | 1051 | ||
| 1049 | SERVICE and PATH are the unique name and the object path of the | 1052 | SERVICE and PATH are the unique name and the object path of the |
| 1050 | D-Bus object emitting the message. DESTINATION is the D-Bus name | 1053 | D-Bus object emitting the message. DESTINATION is the D-Bus name |
| 1051 | the message is dedicated to, or nil in case thje message is a | 1054 | the message is dedicated to, or nil in case the message is a |
| 1052 | broadcast signal. | 1055 | broadcast signal. |
| 1053 | 1056 | ||
| 1054 | INTERFACE and MEMBER denote the message which has been sent. | 1057 | INTERFACE and MEMBER denote the message which has been sent. |
| @@ -1064,7 +1067,7 @@ formed." | |||
| 1064 | (when dbus-debug (message "DBus-Event %s" event)) | 1067 | (when dbus-debug (message "DBus-Event %s" event)) |
| 1065 | (unless (and (listp event) | 1068 | (unless (and (listp event) |
| 1066 | (eq (car event) 'dbus-event) | 1069 | (eq (car event) 'dbus-event) |
| 1067 | ;; Bus symbol. | 1070 | ;; Bus keyword. |
| 1068 | (or (keywordp (nth 1 event)) | 1071 | (or (keywordp (nth 1 event)) |
| 1069 | (stringp (nth 1 event))) | 1072 | (stringp (nth 1 event))) |
| 1070 | ;; Type. | 1073 | ;; Type. |
| @@ -1181,8 +1184,8 @@ If the HANDLER returns a `dbus-error', it is propagated as return message." | |||
| 1181 | 1184 | ||
| 1182 | (defun dbus-event-bus-name (event) | 1185 | (defun dbus-event-bus-name (event) |
| 1183 | "Return the bus name the event is coming from. | 1186 | "Return the bus name the event is coming from. |
| 1184 | The result is either a Lisp symbol, `:system' or `:session', or a | 1187 | The result is either a Lisp keyword, `:system' or `:session', or |
| 1185 | string denoting the bus address. EVENT is a D-Bus event, see | 1188 | a string denoting the bus address. EVENT is a D-Bus event, see |
| 1186 | `dbus-check-event'. This function signals a `dbus-error' if the | 1189 | `dbus-check-event'. This function signals a `dbus-error' if the |
| 1187 | event is not well formed." | 1190 | event is not well formed." |
| 1188 | (dbus-check-event event) | 1191 | (dbus-check-event event) |
| @@ -1375,11 +1378,11 @@ It will be registered for all objects created by `dbus-register-service'." | |||
| 1375 | "Return all interfaces and sub-nodes of SERVICE, | 1378 | "Return all interfaces and sub-nodes of SERVICE, |
| 1376 | registered at object path PATH at bus BUS. | 1379 | registered at object path PATH at bus BUS. |
| 1377 | 1380 | ||
| 1378 | BUS is either a Lisp symbol, `:system' or `:session', or a string | 1381 | BUS is either a Lisp keyword, `:system' or `:session', or a |
| 1379 | denoting the bus address. SERVICE must be a known service name, | 1382 | string denoting the bus address. SERVICE must be a known service |
| 1380 | and PATH must be a valid object path. The last two parameters | 1383 | name, and PATH must be a valid object path. The last two |
| 1381 | are strings. The result, the introspection data, is a string in | 1384 | parameters are strings. The result, the introspection data, is a |
| 1382 | XML format." | 1385 | string in XML format." |
| 1383 | ;; We don't want to raise errors. | 1386 | ;; We don't want to raise errors. |
| 1384 | (let (dbus-debug) | 1387 | (let (dbus-debug) |
| 1385 | (dbus-ignore-errors | 1388 | (dbus-ignore-errors |
| @@ -1596,7 +1599,7 @@ valid D-Bus value, or nil if there is no PROPERTY, or PROPERTY cannot be read." | |||
| 1596 | (defun dbus-set-property (bus service path interface property &rest args) | 1599 | (defun dbus-set-property (bus service path interface property &rest args) |
| 1597 | "Set value of PROPERTY of INTERFACE to VALUE. | 1600 | "Set value of PROPERTY of INTERFACE to VALUE. |
| 1598 | It will be checked at BUS, SERVICE, PATH. VALUE can be preceded | 1601 | It will be checked at BUS, SERVICE, PATH. VALUE can be preceded |
| 1599 | by a TYPE symbol. When the value is successfully set, and the | 1602 | by a TYPE keyword. When the value is successfully set, and the |
| 1600 | property's access type is not `:write', return VALUE. Otherwise, | 1603 | property's access type is not `:write', return VALUE. Otherwise, |
| 1601 | return nil. | 1604 | return nil. |
| 1602 | 1605 | ||
| @@ -1651,8 +1654,8 @@ Filter out matching PATH." | |||
| 1651 | (bus service path interface property access &rest args) | 1654 | (bus service path interface property access &rest args) |
| 1652 | "Register PROPERTY on the D-Bus BUS. | 1655 | "Register PROPERTY on the D-Bus BUS. |
| 1653 | 1656 | ||
| 1654 | BUS is either a Lisp symbol, `:system' or `:session', or a string | 1657 | BUS is either a Lisp keyword, `:system' or `:session', or a |
| 1655 | denoting the bus address. | 1658 | string denoting the bus address. |
| 1656 | 1659 | ||
| 1657 | SERVICE is the D-Bus service name of the D-Bus. It must be a | 1660 | SERVICE is the D-Bus service name of the D-Bus. It must be a |
| 1658 | known name (see discussion of DONT-REGISTER-SERVICE below). | 1661 | known name (see discussion of DONT-REGISTER-SERVICE below). |
| @@ -1662,11 +1665,11 @@ discussion of DONT-REGISTER-SERVICE below). INTERFACE is the | |||
| 1662 | name of the interface used at PATH, PROPERTY is the name of the | 1665 | name of the interface used at PATH, PROPERTY is the name of the |
| 1663 | property of INTERFACE. ACCESS indicates, whether the property | 1666 | property of INTERFACE. ACCESS indicates, whether the property |
| 1664 | can be changed by other services via D-Bus. It must be either | 1667 | can be changed by other services via D-Bus. It must be either |
| 1665 | the symbol `:read', `:write' or `:readwrite'. | 1668 | the keyword `:read', `:write' or `:readwrite'. |
| 1666 | 1669 | ||
| 1667 | VALUE is the initial value of the property, it can be of any | 1670 | VALUE is the initial value of the property, it can be of any |
| 1668 | valid type (see `dbus-call-method' for details). VALUE can be | 1671 | valid type (see `dbus-call-method' for details). VALUE can be |
| 1669 | preceded by a TYPE symbol. | 1672 | preceded by a TYPE keyword. |
| 1670 | 1673 | ||
| 1671 | If PROPERTY already exists on PATH, it will be overwritten. For | 1674 | If PROPERTY already exists on PATH, it will be overwritten. For |
| 1672 | properties with access type `:read' this is the only way to | 1675 | properties with access type `:read' this is the only way to |
| @@ -1688,7 +1691,7 @@ clients from discovering the still incomplete interface. | |||
| 1688 | 1691 | ||
| 1689 | \(dbus-register-property BUS SERVICE PATH INTERFACE PROPERTY ACCESS \ | 1692 | \(dbus-register-property BUS SERVICE PATH INTERFACE PROPERTY ACCESS \ |
| 1690 | [TYPE] VALUE &optional EMITS-SIGNAL DONT-REGISTER-SERVICE)" | 1693 | [TYPE] VALUE &optional EMITS-SIGNAL DONT-REGISTER-SERVICE)" |
| 1691 | (let (;; Read basic type symbol. | 1694 | (let (;; Read basic type keyword. |
| 1692 | (type (when (keywordp (car args)) (pop args))) | 1695 | (type (when (keywordp (car args)) (pop args))) |
| 1693 | (value (pop args)) | 1696 | (value (pop args)) |
| 1694 | (emits-signal (pop args)) | 1697 | (emits-signal (pop args)) |
| @@ -1973,68 +1976,53 @@ It will be registered for all objects created by `dbus-register-service'." | |||
| 1973 | result) | 1976 | result) |
| 1974 | '(:signature "{oa{sa{sv}}}")))))) | 1977 | '(:signature "{oa{sa{sv}}}")))))) |
| 1975 | 1978 | ||
| 1976 | (defun dbus-register-monitor | 1979 | (cl-defun dbus-register-monitor |
| 1977 | (bus &optional service path interface member handler &rest args) | 1980 | (bus &optional handler &key type sender destination path interface member) |
| 1978 | "Register HANDLER for monitor events on the D-Bus BUS. | 1981 | "Register HANDLER for monitor events on the D-Bus BUS. |
| 1979 | 1982 | ||
| 1980 | BUS is either a Lisp symbol, `:system' or `:session', or a string | 1983 | BUS is either a Lisp keyword, `:system' or `:session', or a |
| 1981 | denoting the bus address. | 1984 | string denoting the bus address. |
| 1982 | 1985 | ||
| 1983 | SERVICE is the D-Bus service name of the D-Bus. It must be a | 1986 | HANDLER is the function to be called when a monitor event |
| 1984 | known name (see discussion of DONT-REGISTER-SERVICE below). | 1987 | arrives. It is called with the `args' slot of the monitor event, |
| 1988 | which are stripped off the type keywords. If HANDLER is nil, the | ||
| 1989 | default handler `dbus-monitor-handler' is applied. | ||
| 1985 | 1990 | ||
| 1986 | PATH is the D-Bus object path SERVICE is registered at (see | 1991 | The other arguments are keyword-value pairs. `:type TYPE' |
| 1987 | discussion of DONT-REGISTER-SERVICE below). INTERFACE is the | 1992 | defines the message type to be monitored. If given, it must be |
| 1988 | name of the interface used at PATH. MEMBER is either a method | 1993 | equal one of the strings \"method_call\", \"method_return\", |
| 1989 | name, a signal name, or an error name. | 1994 | \"error\" or \"signal\". |
| 1990 | 1995 | ||
| 1991 | HANDLER is the function to be called when a monitor event | 1996 | `:sender SENDER' and `:destination DESTINATION' are D-Bus names. |
| 1992 | arrives. If nil, the default handler `dbus-monitor-handler' is | 1997 | They can be unique names, or well-known service names. |
| 1993 | applied. It is called with ARGS as arguments." | ||
| 1994 | 1998 | ||
| 1999 | `:path PATH' is the D-Bus object to be monitored. `:interface | ||
| 2000 | INTERFACE' is the name of an interface, and `:member MEMBER' is | ||
| 2001 | either a method name, a signal name, or an error name." | ||
| 1995 | (let ((bus-private (if (eq bus :system) :system-private | 2002 | (let ((bus-private (if (eq bus :system) :system-private |
| 1996 | (if (eq bus :session) :session-private bus))) | 2003 | (if (eq bus :session) :session-private bus))) |
| 1997 | keyword type rule1 rule2 key key1 value) | 2004 | rule key key1 value) |
| 1998 | (unless handler (setq handler #'dbus-monitor-handler)) | 2005 | (unless handler (setq handler #'dbus-monitor-handler)) |
| 1999 | ;; Read arguments. | 2006 | ;; Compose rule. |
| 2000 | (while args | 2007 | (setq rule |
| 2001 | (when (keywordp (setq keyword (pop args))) | 2008 | (string-join |
| 2002 | (cond | 2009 | (delq nil (mapcar |
| 2003 | ((eq :type keyword) | 2010 | (lambda (item) |
| 2004 | ;; Must be "signal", "method_call", "method_return", or "error". | 2011 | (when (cdr item) |
| 2005 | (setq type (pop args)))))) | 2012 | (format "%s='%s'" (car item) (cdr item)))) |
| 2006 | ;; Compose rules. | 2013 | `(("type" . ,type) ("sender" . ,sender) |
| 2007 | (setq rule1 | 2014 | ("destination" . ,destination) ("path" . ,path) |
| 2008 | (or | 2015 | ("interface" . ,interface) ("member" . ,member)))) |
| 2009 | (string-join | 2016 | ",") |
| 2010 | (delq nil | 2017 | rule (or rule "")) |
| 2011 | (list (when service (format "sender='%s'" service)) | ||
| 2012 | (when path (format "path='%s'" path)) | ||
| 2013 | (when interface (format "interface='%s'" interface)) | ||
| 2014 | (when member (format "member='%s'" member)) | ||
| 2015 | (when type (format "type='%s'" type)))) | ||
| 2016 | ",") | ||
| 2017 | "") | ||
| 2018 | rule2 | ||
| 2019 | (when service | ||
| 2020 | (string-join | ||
| 2021 | (delq nil | ||
| 2022 | (list (format "destination='%s'" service) | ||
| 2023 | (when path (format "path='%s'" path)) | ||
| 2024 | (when interface (format "interface='%s'" interface)) | ||
| 2025 | (when member (format "member='%s'" member)) | ||
| 2026 | (when type (format "type='%s'" type)))) | ||
| 2027 | ","))) | ||
| 2028 | 2018 | ||
| 2029 | (unless (ignore-errors (dbus-get-unique-name bus-private)) | 2019 | (unless (ignore-errors (dbus-get-unique-name bus-private)) |
| 2030 | (dbus-init-bus bus 'private)) | 2020 | (dbus-init-bus bus 'private)) |
| 2031 | (dbus-call-method | 2021 | (dbus-call-method |
| 2032 | bus-private dbus-service-dbus dbus-path-dbus dbus-interface-monitoring | 2022 | bus-private dbus-service-dbus dbus-path-dbus dbus-interface-monitoring |
| 2033 | "BecomeMonitor" | 2023 | "BecomeMonitor" `(:array :string ,rule) :uint32 0) |
| 2034 | (append `(:array :string ,rule1) (when rule2 `(:string ,rule2))) | ||
| 2035 | :uint32 0) | ||
| 2036 | 2024 | ||
| 2037 | (when dbus-debug (message "Matching rule \"%s\" created" rule1)) | 2025 | (when dbus-debug (message "Matching rule \"%s\" created" rule)) |
| 2038 | 2026 | ||
| 2039 | ;; Create a hash table entry. | 2027 | ;; Create a hash table entry. |
| 2040 | (setq key (list :monitor bus-private) | 2028 | (setq key (list :monitor bus-private) |
| @@ -2046,14 +2034,19 @@ applied. It is called with ARGS as arguments." | |||
| 2046 | (when dbus-debug (message "%s" dbus-registered-objects-table)) | 2034 | (when dbus-debug (message "%s" dbus-registered-objects-table)) |
| 2047 | 2035 | ||
| 2048 | ;; Return the object. | 2036 | ;; Return the object. |
| 2049 | (list key (list service path handler)))) | 2037 | (list key key1))) |
| 2050 | 2038 | ||
| 2051 | (defun dbus-monitor-handler (&rest _args) | 2039 | (defun dbus-monitor-handler (&rest _args) |
| 2052 | "Default handler for the \"org.freedesktop.DBus.Monitoring.BecomeMonitor\" interface. | 2040 | "Default handler for the \"org.freedesktop.DBus.Monitoring.BecomeMonitor\" interface. |
| 2053 | It will be applied all objects created by `dbus-register-monitor'." | 2041 | It will be applied for all objects created by |
| 2042 | `dbus-register-monitor' which don't declare an own handler.." | ||
| 2054 | (with-current-buffer (get-buffer-create "*D-Bus Monitor*") | 2043 | (with-current-buffer (get-buffer-create "*D-Bus Monitor*") |
| 2055 | (special-mode) | 2044 | (special-mode) |
| 2045 | ;; Move forward and backward between messages. | ||
| 2046 | (local-set-key [?n] #'forward-paragraph) | ||
| 2047 | (local-set-key [?p] #'backward-paragraph) | ||
| 2056 | (let* ((inhibit-read-only t) | 2048 | (let* ((inhibit-read-only t) |
| 2049 | (point (point)) | ||
| 2057 | (eobp (eobp)) | 2050 | (eobp (eobp)) |
| 2058 | (event last-input-event) | 2051 | (event last-input-event) |
| 2059 | (type (dbus-event-message-type event)) | 2052 | (type (dbus-event-message-type event)) |
| @@ -2079,7 +2072,33 @@ It will be applied all objects created by `dbus-register-monitor'." | |||
| 2079 | sender destination serial path interface member)) | 2072 | sender destination serial path interface member)) |
| 2080 | (dolist (arg arguments) | 2073 | (dolist (arg arguments) |
| 2081 | (pp (dbus-flatten-types arg) (current-buffer))) | 2074 | (pp (dbus-flatten-types arg) (current-buffer))) |
| 2082 | (insert "\n")) | 2075 | (insert "\n") |
| 2076 | ;; Show byte arrays as string. | ||
| 2077 | (goto-char point) | ||
| 2078 | (while (re-search-forward | ||
| 2079 | "(:array\\( :byte [[:digit:]]+\\)+)" nil 'noerror) | ||
| 2080 | (put-text-property | ||
| 2081 | (match-beginning 0) (match-end 0) | ||
| 2082 | 'help-echo (dbus-byte-array-to-string (read (match-string 0))))) | ||
| 2083 | ;; Show fixed numbers. | ||
| 2084 | (goto-char point) | ||
| 2085 | (while (re-search-forward | ||
| 2086 | (concat | ||
| 2087 | (regexp-opt | ||
| 2088 | '(":int16" ":uint16" ":int32" ":uint32" ":int64" ":uint64")) | ||
| 2089 | " \\([-+[:digit:]]+\\)") | ||
| 2090 | nil 'noerror) | ||
| 2091 | (put-text-property | ||
| 2092 | (match-beginning 1) (match-end 1) | ||
| 2093 | 'help-echo | ||
| 2094 | (format | ||
| 2095 | "#o%o, #x%X" (read (match-string 1)) (read (match-string 1))))) | ||
| 2096 | ;; Show floating numbers. | ||
| 2097 | (goto-char point) | ||
| 2098 | (while (re-search-forward ":double \\([-+.[:digit:]]+\\)" nil 'noerror) | ||
| 2099 | (put-text-property | ||
| 2100 | (match-beginning 1) (match-end 1) | ||
| 2101 | 'help-echo (format "%e" (read (match-string 1)))))) | ||
| 2083 | (when eobp | 2102 | (when eobp |
| 2084 | (goto-char (point-max)))))) | 2103 | (goto-char (point-max)))))) |
| 2085 | 2104 | ||
| @@ -2115,10 +2134,11 @@ pending at the time of disconnect to fail." | |||
| 2115 | (defun dbus-init-bus (bus &optional private) | 2134 | (defun dbus-init-bus (bus &optional private) |
| 2116 | "Establish the connection to D-Bus BUS. | 2135 | "Establish the connection to D-Bus BUS. |
| 2117 | 2136 | ||
| 2118 | BUS can be either the symbol `:system' or the symbol `:session', or it | 2137 | BUS can be either the keyword `:system' or the keyword |
| 2119 | can be a string denoting the address of the corresponding bus. For | 2138 | `:session', or it can be a string denoting the address of the |
| 2120 | the system and session buses, this function is called when loading | 2139 | corresponding bus. For the system and session buses, this |
| 2121 | `dbus.el', there is no need to call it again. | 2140 | function is called when loading `dbus.el', there is no need to |
| 2141 | call it again. | ||
| 2122 | 2142 | ||
| 2123 | The function returns the number of connections this Emacs session | 2143 | The function returns the number of connections this Emacs session |
| 2124 | has established to the BUS under the same unique name (see | 2144 | has established to the BUS under the same unique name (see |
| @@ -2128,13 +2148,13 @@ example, if Emacs is linked with the GTK+ toolkit, and it runs in | |||
| 2128 | a GTK+-aware environment like GNOME, another connection might | 2148 | a GTK+-aware environment like GNOME, another connection might |
| 2129 | already be established. | 2149 | already be established. |
| 2130 | 2150 | ||
| 2131 | When PRIVATE is non-nil, a new connection is established instead of | 2151 | When PRIVATE is non-nil, a new connection is established instead |
| 2132 | reusing an existing one. It results in a new unique name at the bus. | 2152 | of reusing an existing one. It results in a new unique name at |
| 2133 | This can be used, if it is necessary to distinguish from another | 2153 | the bus. This can be used, if it is necessary to distinguish |
| 2134 | connection used in the same Emacs process, like the one established by | 2154 | from another connection used in the same Emacs process, like the |
| 2135 | GTK+. It should be used with care for at least the `:system' and | 2155 | one established by GTK+. If BUS is the keyword `:system' or the |
| 2136 | `:session' buses, because other Emacs Lisp packages might already use | 2156 | keyword `:session', the new connection is identified by the |
| 2137 | this connection to those buses." | 2157 | keywords `:system-private' or `:session-private', respectively." |
| 2138 | (or (featurep 'dbusbind) | 2158 | (or (featurep 'dbusbind) |
| 2139 | (signal 'dbus-error (list "Emacs not compiled with dbus support"))) | 2159 | (signal 'dbus-error (list "Emacs not compiled with dbus support"))) |
| 2140 | (prog1 | 2160 | (prog1 |
diff --git a/test/lisp/net/dbus-tests.el b/test/lisp/net/dbus-tests.el index 0f5582bfc9d..b853542a1f0 100644 --- a/test/lisp/net/dbus-tests.el +++ b/test/lisp/net/dbus-tests.el | |||
| @@ -66,6 +66,7 @@ | |||
| 66 | (ert-deftest dbus-test01-type-conversion () | 66 | (ert-deftest dbus-test01-type-conversion () |
| 67 | "Check type conversion functions." | 67 | "Check type conversion functions." |
| 68 | (skip-unless dbus--test-enabled-session-bus) | 68 | (skip-unless dbus--test-enabled-session-bus) |
| 69 | |||
| 69 | (let ((ustr "0123abc_xyz\x01\xff") | 70 | (let ((ustr "0123abc_xyz\x01\xff") |
| 70 | (mstr "Grüß Göttin")) | 71 | (mstr "Grüß Göttin")) |
| 71 | (should | 72 | (should |
| @@ -97,6 +98,7 @@ | |||
| 97 | (ert-deftest dbus-test01-basic-types () | 98 | (ert-deftest dbus-test01-basic-types () |
| 98 | "Check basic D-Bus type arguments." | 99 | "Check basic D-Bus type arguments." |
| 99 | (skip-unless dbus--test-enabled-session-bus) | 100 | (skip-unless dbus--test-enabled-session-bus) |
| 101 | |||
| 100 | ;; Unknown keyword. | 102 | ;; Unknown keyword. |
| 101 | (should-error | 103 | (should-error |
| 102 | (dbus-check-arguments :session dbus--test-service :keyword) | 104 | (dbus-check-arguments :session dbus--test-service :keyword) |
| @@ -288,6 +290,8 @@ | |||
| 288 | 290 | ||
| 289 | (ert-deftest dbus-test01-compound-types () | 291 | (ert-deftest dbus-test01-compound-types () |
| 290 | "Check basic D-Bus type arguments." | 292 | "Check basic D-Bus type arguments." |
| 293 | (skip-unless dbus--test-enabled-session-bus) | ||
| 294 | |||
| 291 | ;; `:array'. It contains several elements of the same type. | 295 | ;; `:array'. It contains several elements of the same type. |
| 292 | (should (dbus-check-arguments :session dbus--test-service '("string"))) | 296 | (should (dbus-check-arguments :session dbus--test-service '("string"))) |
| 293 | (should (dbus-check-arguments :session dbus--test-service '(:array "string"))) | 297 | (should (dbus-check-arguments :session dbus--test-service '(:array "string"))) |
| @@ -327,6 +331,11 @@ | |||
| 327 | (dbus-check-arguments | 331 | (dbus-check-arguments |
| 328 | :session dbus--test-service | 332 | :session dbus--test-service |
| 329 | '(:array (:dict-entry :string "string" :boolean t)))) | 333 | '(:array (:dict-entry :string "string" :boolean t)))) |
| 334 | ;; This is an alternative syntax. FIXME: Shall this be supported? | ||
| 335 | (should | ||
| 336 | (dbus-check-arguments | ||
| 337 | :session dbus--test-service | ||
| 338 | '(:array :dict-entry (:string "string" :boolean t)))) | ||
| 330 | ;; The second element is `nil' (implicitly). FIXME: Is this right? | 339 | ;; The second element is `nil' (implicitly). FIXME: Is this right? |
| 331 | (should | 340 | (should |
| 332 | (dbus-check-arguments | 341 | (dbus-check-arguments |