~ubuntu-branches/ubuntu/karmic/emacs-snapshot/karmic

« back to all changes in this revision

Viewing changes to doc/misc/dbus.texi

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-04-05 09:14:30 UTC
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20090405091430-nw07lynn2arotjbe
Tags: upstream-20090320
Import upstream version 20090320

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
@c %**end of header
7
7
 
8
8
@copying
9
 
Copyright @copyright{} 2007, 2008 Free Software Foundation, Inc.
 
9
Copyright @copyright{} 2007, 2008, 2009 Free Software Foundation, Inc.
10
10
 
11
11
@quotation
12
12
Permission is granted to copy, distribute and/or modify this document
13
 
under the terms of the GNU Free Documentation License, Version 1.2 or
 
13
under the terms of the GNU Free Documentation License, Version 1.3 or
14
14
any later version published by the Free Software Foundation; with no
15
15
Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
16
16
and with the Back-Cover Texts as in (a) below.  A copy of the license
27
27
* D-Bus: (dbus).                Using D-Bus in Emacs.
28
28
@end direntry
29
29
 
 
30
@contents
30
31
 
31
32
@node Top, Overview, (dir), (dir)
32
33
@top D-Bus integration in Emacs
38
39
way for applications to talk to one another.  An overview of D-Bus can
39
40
be found at @uref{http://dbus.freedesktop.org/}.
40
41
 
 
42
@ifnottex
41
43
@insertcopying
 
44
@end ifnottex
42
45
 
43
46
@menu
44
47
* Overview::                    An overview of D-Bus.
945
948
@result{} 3
946
949
@end lisp
947
950
 
 
951
@defun dbus-string-to-byte-array string
 
952
Sometimes, D-Bus methods require as input parameter an array of bytes,
 
953
instead of a string.  If it is guaranteed, that @var{string} is an
 
954
UTF8 string, this function performs the conversion.  Example:
 
955
 
 
956
@lisp
 
957
(dbus-string-to-byte-array "/etc/hosts")
 
958
 
 
959
@result{} (:array :byte 47 :byte 101 :byte 116 :byte 99 :byte 47
 
960
           :byte 104 :byte 111 :byte 115 :byte 116 :byte 115)
 
961
@end lisp
 
962
@end defun
 
963
 
 
964
@defun dbus-escape-as-identifier string
 
965
Escape an arbitrary @var{string} so it follows the rules for a C
 
966
identifier.  The escaped string can be used as object path component,
 
967
interface element component, bus name component or member name in
 
968
D-Bus.
 
969
 
 
970
The escaping consists of replacing all non-alphanumerics, and the
 
971
first character if it's a digit, with an underscore and two
 
972
lower-case hex digits.  As a special case, "" is escaped to
 
973
"_".  Example:
 
974
 
 
975
@lisp
 
976
(dbus-escape-as-identifier "0123abc_xyz\x01\xff")
 
977
 
 
978
@result{} "_30123abc_5fxyz_01_ff"
 
979
@end lisp
 
980
@end defun
 
981
 
948
982
 
949
983
@section Output parameters.
950
984
 
991
1025
(@var{NUMBER} ((@var{STRING} @var{BOOL} @var{BOOL}) (@var{STRING} @var{BOOL} @var{BOOL}) @dots{}))
992
1026
@end lisp
993
1027
 
 
1028
@defun dbus-byte-array-to-string byte-array
 
1029
If a D-Bus method or signal returns an array of bytes, which are known
 
1030
to represent an UTF8 string, this function converts @var{byte-array}
 
1031
to the corresponding string.  Example:
 
1032
 
 
1033
@lisp
 
1034
(dbus-byte-array-to-string '(47 101 116 99 47 104 111 115 116 115))
 
1035
 
 
1036
@result{} "/etc/hosts"
 
1037
@end lisp
 
1038
@end defun
 
1039
 
 
1040
@defun dbus-unescape-from-identifier string
 
1041
Retrieve the original string from the encoded @var{string}.
 
1042
@var{string} must have been coded with
 
1043
@code{dbus-escape-as-identifier}.  Example:
 
1044
 
 
1045
@lisp
 
1046
(dbus-unescape-from-identifier "_30123abc_5fxyz_01_ff")
 
1047
 
 
1048
@result{} "0123abc_xyzÿ"
 
1049
@end lisp
 
1050
@end defun
 
1051
 
994
1052
 
995
1053
@node Synchronous Methods
996
1054
@chapter Calling methods in a blocking way.
1173
1231
@samp{@strong{Application}} is the name of the application which
1174
1232
provides the interface.
1175
1233
 
 
1234
@deffn Constant dbus-service-emacs
 
1235
The well known service name of Emacs.
 
1236
@end deffn
 
1237
 
 
1238
@deffn Constant dbus-path-emacs
 
1239
The object path head "/org/gnu/Emacs" used by Emacs.  All object
 
1240
paths, used by offered methods or signals, shall start with this
 
1241
string.
 
1242
@end deffn
 
1243
 
1176
1244
@defun dbus-register-method bus service path interface method handler
1177
1245
With this function, an application registers @var{method} on the D-Bus
1178
1246
@var{bus}.
1189
1257
@var{interface} is the interface offered by @var{service}.  It must
1190
1258
provide @var{method}.
1191
1259
 
1192
 
@var{handler} is a Lisp function to be called when when a @var{method}
1193
 
call is is received.  It must accept as arguments the input arguments
1194
 
of @var{method}.  @var{handler} must return a list, which elements are
1195
 
used as arguments for the reply message of @var{method}.  This list
1196
 
can be composed like the input parameters in @ref{Type Conversion}.
 
1260
@var{handler} is a Lisp function to be called when a @var{method} call
 
1261
is received.  It must accept as arguments the input arguments of
 
1262
@var{method}.  @var{handler} should return a list, whose elements are
 
1263
to be used as arguments for the reply message of @var{method}.  This
 
1264
list can be composed like the input parameters in @ref{Type
 
1265
Conversion}.
 
1266
 
 
1267
If @var{handler} wants to return just one Lisp object and it is not a
 
1268
cons cell, @var{handler} can return this object directly, instead of
 
1269
returning a list containing the object.
1197
1270
 
1198
1271
The default D-Bus timeout when waiting for a message reply is 25
1199
1272
seconds.  This value could be even smaller, depending on the calling
1296
1369
 
1297
1370
@lisp
1298
1371
(dbus-send-signal
1299
 
  :session "org.gnu.Emacs" "/org/gnu/Emacs"
1300
 
  "org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs")
 
1372
  :session dbus-service-emacs dbus-path-emacs
 
1373
  (concat dbus-service-emacs ".FileManager") "FileModified"
 
1374
  "/home/albinus/.emacs")
1301
1375
@end lisp
1302
1376
@end defun
1303
1377
 
1363
1437
@end defun
1364
1438
 
1365
1439
@defun dbus-unregister-object object
1366
 
Unregister @var{object} from the the D-Bus.  @var{object} must be the
 
1440
Unregister @var{object} from the D-Bus.  @var{object} must be the
1367
1441
result of a preceding @code{dbus-register-signal} or
1368
1442
@code{dbus-register-method} call.  It returns @code{t} if @var{object}
1369
1443
has been unregistered, @code{nil} otherwise.
1454
1528
@end defun
1455
1529
 
1456
1530
@defun dbus-event-interface-name event
1457
 
Returns the interface name of of the D-Bus object @var{event} is coming from.
 
1531
Returns the interface name of the D-Bus object @var{event} is coming from.
1458
1532
@end defun
1459
1533
 
1460
1534
@defun dbus-event-member-name event
1461
 
Returns the member name of of the D-Bus object @var{event} is coming
 
1535
Returns the member name of the D-Bus object @var{event} is coming
1462
1536
from.  It is either a signal name or a method name.
1463
1537
@end defun
1464
1538
 
1465
1539
D-Bus errors are not propagated during event handling, because it is
1466
1540
usually not desired.  D-Bus errors in events can be made visible by
1467
 
setting the variable @code{dbus-debug} to @code{t}.
 
1541
setting the variable @code{dbus-debug} to @code{t}.  They can also be
 
1542
handled by a hook function.
 
1543
 
 
1544
@defvar dbus-event-error-hooks
 
1545
This hook variable keeps a list of functions, which are called when a
 
1546
D-Bus error happens in the event handler.  Every function must accept
 
1547
two arguments, the event and the error variable catched in
 
1548
@code{condition-case} by @code{dbus-error}.
 
1549
 
 
1550
Such functions can be used the adapt the error signal to be raised.
 
1551
Example:
 
1552
 
 
1553
@lisp
 
1554
(defun my-dbus-event-error-handler (event error)
 
1555
  (when (string-equal (concat dbus-service-emacs ".FileManager")
 
1556
                      (dbus-event-interface-name event))
 
1557
    (message "my-dbus-event-error-handler: %S %S" event error)
 
1558
    (signal 'file-error (cdr error))))
 
1559
 
 
1560
(add-hook 'dbus-event-error-hooks 'my-dbus-event-error-handler)
 
1561
@end lisp
 
1562
@end defvar
 
1563
 
 
1564
Hook functions shall take into account, that there might be other
 
1565
D-Bus applications running.  Therefore, they shall check carefully,
 
1566
whether a given D-Bus error is related to them.
1468
1567
 
1469
1568
 
1470
1569
@node GNU Free Documentation License
1471
1570
@appendix GNU Free Documentation License
1472
1571
@include doclicense.texi
1473
1572
 
1474
 
@contents
1475
 
@c End of dbus.texi
1476
1573
@bye
1477
1574
 
1478
1575
@ignore