aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/misc/dbus.texi165
-rw-r--r--lisp/net/dbus.el224
-rw-r--r--test/lisp/net/dbus-tests.el9
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
164This function returns the D-Bus service names, which can be activated 165This function returns the D-Bus service names, which can be activated
165for @var{bus}. It must be either the symbol @code{:system} (the 166for @var{bus}. It must be either the keyword @code{:system} (the
166default) or the symbol @code{:session}. An activatable service is 167default) or the keyword @code{:session}. An activatable service is
167described in a service registration file. Under GNU/Linux, such files 168described in a service registration file. Under GNU/Linux, such files
168are located at @file{/usr/share/dbus-1/system-services/} (for the 169are 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
170activatable service is not necessarily registered at @var{bus} already. 171activatable service is not necessarily registered at @var{bus}
172already.
171 173
172The result is a list of strings, which is @code{nil} when there are no 174The result is a list of strings, which is @code{nil} when there are no
173activatable service names at all. Example: 175activatable service names at all. Example:
@@ -186,7 +188,7 @@ there are no registered service names at all. Well known names are
186strings like @samp{org.freedesktop.DBus}. Names starting with 188strings 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
196start with @samp{:}. The result is a list of strings, which is 198start 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
206result is a list of strings, or @code{nil} when there are no queued 208result is a list of strings, or @code{nil} when there are no queued
207names for @var{service} at all. 209names 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
211string. 213string.
212@end defun 214@end defun
@@ -217,7 +219,7 @@ For a given service, registered at D-Bus @var{bus} under the name
217owner. The result is a string, or @code{nil} when there is no name 219owner. The result is a string, or @code{nil} when there is no name
218owner of @var{service}. 220owner 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
222string. 224string.
223@end defun 225@end defun
@@ -228,7 +230,7 @@ registered at D-Bus @var{bus}. If @var{service} has not yet started,
228it is autostarted if possible. The result is either @code{t} or 230it 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
233nonnegative integer, specifies the maximum number of milliseconds 235nonnegative integer, specifies the maximum number of milliseconds
234before @code{dbus-ping} must return. The default value is 25,000. 236before @code{dbus-ping} must return. The default value is 25,000.
@@ -256,7 +258,7 @@ it, you can instead write:
256This function returns the unique name, under which Emacs is registered 258This function returns the unique name, under which Emacs is registered
257at D-Bus @var{bus}, as a string. 259at 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.
375This function returns all interfaces and sub-nodes of @var{service}, 377This function returns all interfaces and sub-nodes of @var{service},
376registered at object path @var{path} at bus @var{bus}. 378registered 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
381strings. The result, the introspection data, is a string in XML 383strings. 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
748This function sets the value of @var{property} of @var{interface} to 750This 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.
751the value is successfully set, this function returns @var{value}. 753When the value is successfully set, this function returns @var{value}.
752Example: 754Example:
753 755
754@lisp 756@lisp
@@ -999,8 +1001,8 @@ Other Lisp objects, like symbols or hash tables, are not accepted as
999input parameters. 1001input parameters.
1000 1002
1001If it is necessary to use another D-Bus type, a corresponding type 1003If it is necessary to use another D-Bus type, a corresponding type
1002symbol can be prepended to the corresponding Lisp object. Basic D-Bus 1004keyword can be prepended to the corresponding Lisp object. Basic
1003types are represented by the type symbols @code{:byte}, 1005D-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
1042A D-Bus compound type is always represented as a list. The @sc{car} 1044A D-Bus compound type is always represented as a list. The @sc{car}
1043of this list can be the type symbol @code{:array}, @code{:variant}, 1045of 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
1045corresponding D-Bus container. @code{:array} is optional, because 1047corresponding D-Bus container. @code{:array} is optional, because
1046this is the default compound D-Bus type for a list. 1048this 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}
1217This function calls @var{method} on the D-Bus @var{bus}. @var{bus} is 1219This function calls @var{method} on the D-Bus @var{bus}. @var{bus} is
1218either the symbol @code{:system} or the symbol @code{:session}. 1220either 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
1221D-Bus object path, @var{service} is registered at. @var{interface} is 1223D-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
1310This function calls @var{method} on the D-Bus @var{bus} 1312This function calls @var{method} on the D-Bus @var{bus}
1311asynchronously. @var{bus} is either the symbol @code{:system} or the 1313asynchronously. @var{bus} is either the keyword @code{:system} or the
1312symbol @code{:session}. 1314keyword @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
1315D-Bus object path, @var{service} is registered at. @var{interface} is 1317D-Bus object path, @var{service} is registered at. @var{interface} is
@@ -1369,7 +1371,7 @@ the following functions:
1369This function registers the known name @var{service} on D-Bus 1371This 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.
1405This function unregisters all objects from D-Bus @var{bus}, that were 1407This function unregisters all objects from D-Bus @var{bus}, that were
1406registered by Emacs for @var{service}. 1408registered 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.
1452With this function, an application registers @var{method} on the D-Bus 1454With 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
1477returning a list containing the object. 1479returning a list containing the object.
1478 1480
1479If @var{handler} returns a reply message with an empty argument list, 1481If @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
1481to distinguish it from @code{nil} (the boolean false). 1483distinguish it from @code{nil} (the boolean false).
1482 1484
1483If @var{handler} detects an error, it shall return the list 1485If @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
1580With this function, an application declares a @var{property} on the D-Bus 1582With 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
1596services via D-Bus. It must be either the symbol @code{:read}, 1598services 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
1600valid type (@xref{dbus-call-method}, for details). @var{value} can be 1602valid type (@xref{dbus-call-method}, for details). @var{value} can be
1601preceded by a @var{type} symbol. 1603preceded by a @var{type} keyword.
1602 1604
1603If @var{property} already exists on @var{path}, it will be 1605If @var{property} already exists on @var{path}, it will be
1604overwritten. For properties with access type @code{:read} this is the 1606overwritten. 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
1707is, that there are no returning output parameters. 1709is, that there are no returning output parameters.
1708 1710
1709The function emits @var{signal} on the D-Bus @var{bus}. @var{bus} is 1711The function emits @var{signal} on the D-Bus @var{bus}. @var{bus} is
1710either the symbol @code{:system} or the symbol @code{:session}. It 1712either the keyword @code{:system} or the keyword @code{:session}. It
1711doesn't matter whether another object has registered for @var{signal}. 1713doesn't matter whether another object has registered for @var{signal}.
1712 1714
1713Signals can be unicast or broadcast messages. For broadcast messages, 1715Signals can be unicast or broadcast messages. For broadcast messages,
@@ -1735,7 +1737,7 @@ arguments. They are converted into D-Bus types as described in
1735With this function, an application registers for a signal on the D-Bus 1737With 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,
1837which are the default buses to be connected to. However, it is 1839which are the default buses to be connected to. However, it is
1838possible to connect to any bus with a known address. This is a UNIX 1840possible to connect to any bus with a known address. This is a UNIX
1839domain or TCP/IP socket. Everywhere, where a @var{bus} is mentioned 1841domain or TCP/IP socket. Everywhere, where a @var{bus} is mentioned
1840as argument of a function (the symbol @code{:system} or the symbol 1842as 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
1842this bus must be initialized first. 1844this bus must be initialized first.
1843 1845
1844@defun dbus-init-bus bus &optional private 1846@defun dbus-init-bus bus &optional private
1845This function establishes the connection to D-Bus @var{bus}. 1847This 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
1849corresponding bus. For the system and session buses, this function 1851corresponding bus. For the system and session buses, this function is
1850is called when loading @file{dbus.el}, there is no need to call it 1852called when loading @file{dbus.el}, there is no need to call it again.
1851again.
1852 1853
1853The function returns the number of connections this Emacs session has 1854The function returns the number of connections this Emacs session has
1854established to the @var{bus} under the same unique name 1855established to the @var{bus} under the same unique name
@@ -1860,11 +1861,12 @@ established.
1860 1861
1861When @var{private} is non-@code{nil}, a new connection is established 1862When @var{private} is non-@code{nil}, a new connection is established
1862instead of reusing an existing one. It results in a new unique name 1863instead of reusing an existing one. It results in a new unique name
1863at the bus. This can be used, if it is necessary to distinguish from 1864at the @var{bus}. This can be used, if it is necessary to distinguish
1864another connection used in the same Emacs process, like the one 1865from another connection used in the same Emacs process, like the one
1865established by GTK+. It should be used with care for at least the 1866established by GTK+. If @var{bus} is the keyword @code{:system} or
1866@code{:system} and @code{:session} buses, because other Emacs Lisp 1867the keyword @code{:session}, the new private connection is identified
1867packages might already use this connection to those buses. 1868by the keywords @code{:system-private} or @code{:session-private},
1869respectively.
1868 1870
1869Example: You initialize a connection to the AT-SPI bus on your host: 1871Example: 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.
1907This function sets the value of the @var{bus} environment 1909This 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},
1911or a string denoting the bus address. Both @var{variable} and 1913or 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
1973interactive mode. The generated event has this form: 1975interactive 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
1981either the symbol @code{:system} or the symbol @code{:session}. 1983either a Lisp keyword, @code{:system}, @code{:session},
1984@code{:system-private} or @code{:session-private}, or a string
1985denoting 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
1984can be @code{dbus-message-type-invalid}, 1988can 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,
1993unless @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
1991of the D-Bus object emitting the message. @var{interface} and 1996of the D-Bus object emitting the message. @var{destination} is the
1992@var{member} denote the message which has been sent. 1997D-Bus name the message is dedicated to, or @code{nil} in case the
1998message is a broadcast signal.
1999
2000@var{interface} and @var{member} denote the message which has been
2001sent. When @var{type} is @code{dbus-message-type-error}, @var{member}
2002is 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
1995this message (@pxref{Signals}). @var{args} are the typed arguments as 2005this 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
2012This function returns the bus name @var{event} is coming from. The 2022This function returns the bus name @var{event} is coming from. The
2013result is either the symbol @code{:system} or the symbol 2023result 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}
2029is coming from. 2039is coming from.
2030@end defun 2040@end defun
2031 2041
2042@defun dbus-event-destination-name event
2043This function returns the unique name of the D-Bus object @var{event}
2044is dedicated to.
2045@end defun
2046
2032@defun dbus-event-path-name event 2047@defun dbus-event-path-name event
2033This function returns the object path of the D-Bus object @var{event} 2048This function returns the object path of the D-Bus object @var{event}
2034is coming from. 2049is coming from.
@@ -2044,6 +2059,16 @@ This function returns the member name of the D-Bus object @var{event}
2044is coming from. It is either a signal name or a method name. 2059is 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
2063This function returns the handler the D-Bus object @var{event} is
2064applied with.
2065@end defun
2066
2067@defun dbus-event-arguments event
2068This function returns the arguments the D-Bus object @var{event} is
2069carrying on.
2070@end defun
2071
2047D-Bus errors are not propagated during event handling, because it is 2072D-Bus errors are not propagated during event handling, because it is
2048usually not desired. D-Bus errors in events can be made visible by 2073usually not desired. D-Bus errors in events can be made visible by
2049setting the variable @code{dbus-debug} to non-@code{nil}. They can 2074setting the variable @code{dbus-debug} to non-@code{nil}. They can
@@ -2074,6 +2099,54 @@ D-Bus applications running. They should therefore check carefully,
2074whether a given D-Bus error is related to them. 2099whether 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
2107This 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},
2111or 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
2115arrives. It is called with the `args' slot of the monitor event,
2116which are stripped off the type keywords. If @var{handler} is
2117@code{nil}, the default handler @code{dbus-monitor-handler} is
2118applied. This default handler behaves similar to the
2119@command{dbus-monitor} program.
2120
2121The other arguments are keyword-value pairs. @code{:type @var{type}}
2122defines the message type to be monitored. If given, it must be equal
2123one 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}}
2127are D-Bus names. They can be unique names, or well-known service
2128names.
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
2133an error name.
2134
2135The 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
2142And 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.
247A key in this hash table is a list (:serial BUS SERIAL), like in 248A 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.
250SERIAL is the serial number of the reply message. 251SERIAL 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
282BUS is either a Lisp symbol, `:system' or `:session', or a string 283BUS is either a Lisp keyword, `:system' or `:session', or a
283denoting the bus address. 284string denoting the bus address.
284 285
285SERVICE is the D-Bus service name to be used. PATH is the D-Bus 286SERVICE is the D-Bus service name to be used. PATH is the D-Bus
286object path SERVICE is registered at. INTERFACE is an interface 287object 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
304All arguments can be preceded by a type symbol. For details about 305All arguments can be preceded by a type keyword. For details
305type symbols, see Info node `(dbus)Type Conversion'. 306about 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
308Lisp objects. The type conversion happens the other direction as for 309Lisp 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
408BUS is either a Lisp symbol, `:system' or `:session', or a string 409BUS is either a Lisp keyword, `:system' or `:session', or a
409denoting the bus address. 410string denoting the bus address.
410 411
411SERVICE is the D-Bus service name to be used. PATH is the D-Bus 412SERVICE is the D-Bus service name to be used. PATH is the D-Bus
412object path SERVICE is registered at. INTERFACE is an interface 413object 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
434All arguments can be preceded by a type symbol. For details about 435All arguments can be preceded by a type keyword. For details
435type symbols, see Info node `(dbus)Type Conversion'. 436about type keywords, see Info node `(dbus)Type Conversion'.
436 437
437If HANDLER is a Lisp function, the function returns a key into the 438If HANDLER is a Lisp function, the function returns a key into the
438hash table `dbus-registered-objects-table'. The corresponding entry 439hash 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
475BUS is either a Lisp symbol, `:system' or `:session', or a string 476BUS is either a Lisp keyword, `:system' or `:session', or a
476denoting the bus address. The signal is sent from the D-Bus object 477string denoting the bus address. The signal is sent from the
477Emacs is registered at BUS. 478D-Bus object Emacs is registered at BUS.
478 479
479SERVICE is the D-Bus name SIGNAL is sent to. It can be either a known 480SERVICE is the D-Bus name SIGNAL is sent to. It can be either a known
480name or a unique name. If SERVICE is nil, the signal is sent as 481name 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
495All arguments can be preceded by a type symbol. For details about 496All arguments can be preceded by a type keyword. For details
496type symbols, see Info node `(dbus)Type Conversion'. 497about type keywords, see Info node `(dbus)Type Conversion'.
497 498
498Example: 499Example:
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
589BUS is either a Lisp symbol, `:system' or `:session', or a string 590BUS is either a Lisp keyword, `:system' or `:session', or a
590denoting the bus address. Both VARIABLE and VALUE should be strings. 591string denoting the bus address. Both VARIABLE and VALUE should
592be strings.
591 593
592Normally, services inherit the environment of the BUS daemon. This 594Normally, services inherit the environment of the BUS daemon. This
593function adds to or modifies that environment when activating services. 595function 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
604BUS is either a Lisp symbol, `:system' or `:session', or a string 606BUS is either a Lisp keyword, `:system' or `:session', or a
605denoting the bus address. 607string denoting the bus address.
606 608
607SERVICE is the D-Bus service name that should be registered. It must 609SERVICE is the D-Bus service name that should be registered. It must
608be a known name. 610be 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.
666BUS is either a Lisp symbol, `:system' or `:session', or a string 668BUS is either a Lisp keyword, `:system' or `:session', or a
667denoting the bus address. SERVICE must be a known service name. 669string denoting the bus address. SERVICE must be a known service
670name.
668 671
669The function returns a keyword, indicating the result of the 672The function returns a keyword, indicating the result of the
670operation. One of the following keywords is returned: 673operation. 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
702BUS is either a Lisp symbol, `:system' or `:session', or a string 705BUS is either a Lisp keyword, `:system' or `:session', or a
703denoting the bus address. 706string denoting the bus address.
704 707
705SERVICE is the D-Bus service name used by the sending D-Bus object. 708SERVICE is the D-Bus service name used by the sending D-Bus object.
706It can be either a known name or the unique name of the D-Bus object 709It 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
857BUS is either a Lisp symbol, `:system' or `:session', or a string 860BUS is either a Lisp keyword, `:system' or `:session', or a
858denoting the bus address. 861string denoting the bus address.
859 862
860SERVICE is the D-Bus service name of the D-Bus object METHOD is 863SERVICE is the D-Bus service name of the D-Bus object METHOD is
861registered for. It must be a known name (see discussion of 864registered 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
869received. It must accept the input arguments of METHOD. The 872received. It must accept the input arguments of METHOD. The
870return value of HANDLER is used for composing the returning D-Bus 873return value of HANDLER is used for composing the returning D-Bus
871message. If HANDLER returns a reply message with an empty 874message. If HANDLER returns a reply message with an empty
872argument list, HANDLER must return the symbol `:ignore' in order 875argument list, HANDLER must return the keyword `:ignore' in order
873to distinguish it from nil (the boolean false). 876to distinguish it from nil (the boolean false).
874 877
875If HANDLER detects an error, it shall return the list `(:error 878If 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
1041BUS identifies the D-Bus the message is coming from. It is 1044BUS identifies the D-Bus the message is coming from. It is
1042either a Lisp symbol, `:system', `:session', `:systemp-private' 1045either a Lisp keyword, `:system', `:session', `:systemp-private'
1043or `:session-private', or a string denoting the bus address. 1046or `:session-private', or a string denoting the bus address.
1044 1047
1045TYPE is the D-Bus message type which has caused the event, SERIAL 1048TYPE 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
1049SERVICE and PATH are the unique name and the object path of the 1052SERVICE and PATH are the unique name and the object path of the
1050D-Bus object emitting the message. DESTINATION is the D-Bus name 1053D-Bus object emitting the message. DESTINATION is the D-Bus name
1051the message is dedicated to, or nil in case thje message is a 1054the message is dedicated to, or nil in case the message is a
1052broadcast signal. 1055broadcast signal.
1053 1056
1054INTERFACE and MEMBER denote the message which has been sent. 1057INTERFACE 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.
1184The result is either a Lisp symbol, `:system' or `:session', or a 1187The result is either a Lisp keyword, `:system' or `:session', or
1185string denoting the bus address. EVENT is a D-Bus event, see 1188a 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
1187event is not well formed." 1190event 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,
1376registered at object path PATH at bus BUS. 1379registered at object path PATH at bus BUS.
1377 1380
1378BUS is either a Lisp symbol, `:system' or `:session', or a string 1381BUS is either a Lisp keyword, `:system' or `:session', or a
1379denoting the bus address. SERVICE must be a known service name, 1382string denoting the bus address. SERVICE must be a known service
1380and PATH must be a valid object path. The last two parameters 1383name, and PATH must be a valid object path. The last two
1381are strings. The result, the introspection data, is a string in 1384parameters are strings. The result, the introspection data, is a
1382XML format." 1385string 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.
1598It will be checked at BUS, SERVICE, PATH. VALUE can be preceded 1601It will be checked at BUS, SERVICE, PATH. VALUE can be preceded
1599by a TYPE symbol. When the value is successfully set, and the 1602by a TYPE keyword. When the value is successfully set, and the
1600property's access type is not `:write', return VALUE. Otherwise, 1603property's access type is not `:write', return VALUE. Otherwise,
1601return nil. 1604return 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
1654BUS is either a Lisp symbol, `:system' or `:session', or a string 1657BUS is either a Lisp keyword, `:system' or `:session', or a
1655denoting the bus address. 1658string denoting the bus address.
1656 1659
1657SERVICE is the D-Bus service name of the D-Bus. It must be a 1660SERVICE is the D-Bus service name of the D-Bus. It must be a
1658known name (see discussion of DONT-REGISTER-SERVICE below). 1661known name (see discussion of DONT-REGISTER-SERVICE below).
@@ -1662,11 +1665,11 @@ discussion of DONT-REGISTER-SERVICE below). INTERFACE is the
1662name of the interface used at PATH, PROPERTY is the name of the 1665name of the interface used at PATH, PROPERTY is the name of the
1663property of INTERFACE. ACCESS indicates, whether the property 1666property of INTERFACE. ACCESS indicates, whether the property
1664can be changed by other services via D-Bus. It must be either 1667can be changed by other services via D-Bus. It must be either
1665the symbol `:read', `:write' or `:readwrite'. 1668the keyword `:read', `:write' or `:readwrite'.
1666 1669
1667VALUE is the initial value of the property, it can be of any 1670VALUE is the initial value of the property, it can be of any
1668valid type (see `dbus-call-method' for details). VALUE can be 1671valid type (see `dbus-call-method' for details). VALUE can be
1669preceded by a TYPE symbol. 1672preceded by a TYPE keyword.
1670 1673
1671If PROPERTY already exists on PATH, it will be overwritten. For 1674If PROPERTY already exists on PATH, it will be overwritten. For
1672properties with access type `:read' this is the only way to 1675properties 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
1980BUS is either a Lisp symbol, `:system' or `:session', or a string 1983BUS is either a Lisp keyword, `:system' or `:session', or a
1981denoting the bus address. 1984string denoting the bus address.
1982 1985
1983SERVICE is the D-Bus service name of the D-Bus. It must be a 1986HANDLER is the function to be called when a monitor event
1984known name (see discussion of DONT-REGISTER-SERVICE below). 1987arrives. It is called with the `args' slot of the monitor event,
1988which are stripped off the type keywords. If HANDLER is nil, the
1989default handler `dbus-monitor-handler' is applied.
1985 1990
1986PATH is the D-Bus object path SERVICE is registered at (see 1991The other arguments are keyword-value pairs. `:type TYPE'
1987discussion of DONT-REGISTER-SERVICE below). INTERFACE is the 1992defines the message type to be monitored. If given, it must be
1988name of the interface used at PATH. MEMBER is either a method 1993equal one of the strings \"method_call\", \"method_return\",
1989name, a signal name, or an error name. 1994\"error\" or \"signal\".
1990 1995
1991HANDLER is the function to be called when a monitor event 1996`:sender SENDER' and `:destination DESTINATION' are D-Bus names.
1992arrives. If nil, the default handler `dbus-monitor-handler' is 1997They can be unique names, or well-known service names.
1993applied. It is called with ARGS as arguments."
1994 1998
1999`:path PATH' is the D-Bus object to be monitored. `:interface
2000INTERFACE' is the name of an interface, and `:member MEMBER' is
2001either 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.
2053It will be applied all objects created by `dbus-register-monitor'." 2041It 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
2118BUS can be either the symbol `:system' or the symbol `:session', or it 2137BUS can be either the keyword `:system' or the keyword
2119can be a string denoting the address of the corresponding bus. For 2138`:session', or it can be a string denoting the address of the
2120the system and session buses, this function is called when loading 2139corresponding bus. For the system and session buses, this
2121`dbus.el', there is no need to call it again. 2140function is called when loading `dbus.el', there is no need to
2141call it again.
2122 2142
2123The function returns the number of connections this Emacs session 2143The function returns the number of connections this Emacs session
2124has established to the BUS under the same unique name (see 2144has 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
2128a GTK+-aware environment like GNOME, another connection might 2148a GTK+-aware environment like GNOME, another connection might
2129already be established. 2149already be established.
2130 2150
2131When PRIVATE is non-nil, a new connection is established instead of 2151When PRIVATE is non-nil, a new connection is established instead
2132reusing an existing one. It results in a new unique name at the bus. 2152of reusing an existing one. It results in a new unique name at
2133This can be used, if it is necessary to distinguish from another 2153the bus. This can be used, if it is necessary to distinguish
2134connection used in the same Emacs process, like the one established by 2154from another connection used in the same Emacs process, like the
2135GTK+. It should be used with care for at least the `:system' and 2155one established by GTK+. If BUS is the keyword `:system' or the
2136`:session' buses, because other Emacs Lisp packages might already use 2156keyword `:session', the new connection is identified by the
2137this connection to those buses." 2157keywords `: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