diff options
| author | Michael Albinus | 2012-04-22 16:11:43 +0200 |
|---|---|---|
| committer | Michael Albinus | 2012-04-22 16:11:43 +0200 |
| commit | dcbf5805ac7ade7fc83f3d209e2d56f029918402 (patch) | |
| tree | ca2d664f76032c4cd39d798ae659e23a30f0b4f8 /doc | |
| parent | cf20dee0248049a925275f54381cf63bb2017e35 (diff) | |
| download | emacs-dcbf5805ac7ade7fc83f3d209e2d56f029918402.tar.gz emacs-dcbf5805ac7ade7fc83f3d209e2d56f029918402.zip | |
Move functions from C to Lisp. Make non-blocking method calls
the default. Implement further D-Bus standard interfaces.
* configure.in (dbus_validate_bus_name, dbus_validate_path)
(dbus_validate_interface, dbus_validate_member): Check also for
these library functions
* dbusbind.c (DBUS_NUM_MESSAGE_TYPES): Declare.
(QCdbus_request_name_allow_replacement)
(QCdbus_request_name_replace_existing)
(QCdbus_request_name_do_not_queue)
(QCdbus_request_name_reply_primary_owner)
(QCdbus_request_name_reply_in_queue)
(QCdbus_request_name_reply_exists)
(QCdbus_request_name_reply_already_owner): Move to dbus.el.
(QCdbus_registered_serial, QCdbus_registered_method)
(QCdbus_registered_signal): New Lisp objects.
(XD_DEBUG_MESSAGE): Use sizeof.
(XD_MESSAGE_TYPE_TO_STRING, XD_OBJECT_TO_STRING)
(XD_DBUS_VALIDATE_BUS_ADDRESS, XD_DBUS_VALIDATE_OBJECT)
(XD_DBUS_VALIDATE_BUS_NAME, XD_DBUS_VALIDATE_PATH)
(XD_DBUS_VALIDATE_INTERFACE, XD_DBUS_VALIDATE_MEMBER): New macros.
(XD_CHECK_DBUS_SERIAL): Rename from CHECK_DBUS_SERIAL_GET_SERIAL.
(xd_signature, xd_append_arg): Allow float for integer types.
(xd_get_connection_references): New function.
(xd_get_connection_address): Rename from xd_initialize. Return
cached address.
(xd_remove_watch): Do not unset $DBUS_SESSION_BUS_ADDRESS.
(xd_close_bus): Rename from Fdbus_close_bus. Not needed on Lisp
level.
(Fdbus_init_bus): New optional arg PRIVATE. Cache address.
Return number of recounts.
(Fdbus_get_unique_name): Make stronger parameter check.
(Fdbus_message_internal): New defun.
(Fdbus_call_method, Fdbus_call_method_asynchronously)
(Fdbus_method_return_internal, Fdbus_method_error_internal)
(Fdbus_send_signal, Fdbus_register_service)
(Fdbus_register_signal, Fdbus_register_method): Move to dbus.el.
(xd_read_message_1): Obey new structure of Vdbus_registered_objects.
(xd_read_queued_messages): Obey new structure of Vdbus_registered_buses.
(Vdbus_compiled_version, Vdbus_runtime_version)
(Vdbus_message_type_invalid, Vdbus_message_type_method_call)
(Vdbus_message_type_method_return, Vdbus_message_type_error)
(Vdbus_message_type_signal): New defvars.
(Vdbus_registered_buses, Vdbus_registered_objects_table): Adapt
docstring.
* net/dbus.el (dbus-message-internal): Declare function. Remove
unneeded function declarations.
(defvar dbus-message-type-invalid, dbus-message-type-method-call)
(dbus-message-type-method-return, dbus-message-type-error)
(dbus-message-type-signal): Declare variables. Remove local
definitions.
(dbus-interface-dbus, dbus-interface-peer)
(dbus-interface-introspectable, dbus-interface-properties)
(dbus-path-emacs, dbus-interface-emacs, dbus-return-values-table):
Adapt docstring.
(dbus-interface-objectmanager): New defconst.
(dbus-call-method, dbus-call-method-asynchronously)
(dbus-send-signal, dbus-method-return-internal)
(dbus-method-error-internal, dbus-register-service)
(dbus-register-signal, dbus-register-method): New defuns, moved
from dbusbind.c
(dbus-call-method-handler, dbus-setenv)
(dbus-get-all-managed-objects, dbus-managed-objects-handler): New
defuns.
(dbus-call-method-non-blocking): Make it an obsolete function.
(dbus-unregister-object, dbus-unregister-service)
(dbus-handle-event, dbus-register-property)
(dbus-property-handler): Obey the new structure of
`bus-registered-objects'.
(dbus-introspect): Use `dbus-call-method'. Use a timeout.
(dbus-get-property, dbus-set-property, dbus-get-all-properties):
Use `dbus-call-method'.
* dbus.texi (Version): New node.
(Properties and Annotations): Mention the object manager
interface. Describe dbus-get-all-managed-objects.
(Type Conversion): Floating point numbers are allowed, if an
anteger does not fit Emacs's integer range.
(Synchronous Methods): Remove obsolete dbus-call-method-non-blocking.
(Asynchronous Methods): Fix description of
dbus-call-method-asynchronously.
(Receiving Method Calls): Fix some minor errors. Add
dbus-interface-emacs.
(Signals): Describe unicast signals and the new match rules.
(Alternative Buses): Add the PRIVATE optional argument to
dbus-init-bus. Describe its new return value. Add dbus-setenv.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/misc/ChangeLog | 16 | ||||
| -rw-r--r-- | doc/misc/dbus.texi | 313 |
2 files changed, 256 insertions, 73 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 14f389044bb..834a8f2c47f 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog | |||
| @@ -1,3 +1,19 @@ | |||
| 1 | 2012-04-22 Michael Albinus <michael.albinus@gmx.de> | ||
| 2 | |||
| 3 | * dbus.texi (Version): New node. | ||
| 4 | (Properties and Annotations): Mention the object manager | ||
| 5 | interface. Describe dbus-get-all-managed-objects. | ||
| 6 | (Type Conversion): Floating point numbers are allowed, if an | ||
| 7 | anteger does not fit Emacs's integer range. | ||
| 8 | (Synchronous Methods): Remove obsolete dbus-call-method-non-blocking. | ||
| 9 | (Asynchronous Methods): Fix description of | ||
| 10 | dbus-call-method-asynchronously. | ||
| 11 | (Receiving Method Calls): Fix some minor errors. Add | ||
| 12 | dbus-interface-emacs. | ||
| 13 | (Signals): Describe unicast signals and the new match rules. | ||
| 14 | (Alternative Buses): Add the PRIVATE optional argument to | ||
| 15 | dbus-init-bus. Describe its new return value. Add dbus-setenv. | ||
| 16 | |||
| 1 | 2012-04-20 Glenn Morris <rgm@gnu.org> | 17 | 2012-04-20 Glenn Morris <rgm@gnu.org> |
| 2 | 18 | ||
| 3 | * faq.texi (New in Emacs 24): New section. | 19 | * faq.texi (New in Emacs 24): New section. |
diff --git a/doc/misc/dbus.texi b/doc/misc/dbus.texi index 204afe7056e..e99e20b9aa0 100644 --- a/doc/misc/dbus.texi +++ b/doc/misc/dbus.texi | |||
| @@ -53,7 +53,7 @@ another. An overview of D-Bus can be found at | |||
| 53 | * Asynchronous Methods:: Calling methods non-blocking. | 53 | * Asynchronous Methods:: Calling methods non-blocking. |
| 54 | * Receiving Method Calls:: Offering own methods. | 54 | * Receiving Method Calls:: Offering own methods. |
| 55 | * Signals:: Sending and receiving signals. | 55 | * Signals:: Sending and receiving signals. |
| 56 | * Alternative Buses:: Alternative buses. | 56 | * Alternative Buses:: Alternative buses and environments. |
| 57 | * Errors and Events:: Errors and events. | 57 | * Errors and Events:: Errors and events. |
| 58 | * Index:: Index including concepts, functions, variables. | 58 | * Index:: Index including concepts, functions, variables. |
| 59 | 59 | ||
| @@ -116,6 +116,7 @@ name could be @samp{org.gnu.Emacs.TextEditor} or | |||
| 116 | @cindex inspection | 116 | @cindex inspection |
| 117 | 117 | ||
| 118 | @menu | 118 | @menu |
| 119 | * Version:: Determining the D-Bus version. | ||
| 119 | * Bus names:: Discovering D-Bus names. | 120 | * Bus names:: Discovering D-Bus names. |
| 120 | * Introspection:: Knowing the details of D-Bus services. | 121 | * Introspection:: Knowing the details of D-Bus services. |
| 121 | * Nodes and Interfaces:: Detecting object paths and interfaces. | 122 | * Nodes and Interfaces:: Detecting object paths and interfaces. |
| @@ -125,6 +126,25 @@ name could be @samp{org.gnu.Emacs.TextEditor} or | |||
| 125 | @end menu | 126 | @end menu |
| 126 | 127 | ||
| 127 | 128 | ||
| 129 | @node Version | ||
| 130 | @section D-Bus version. | ||
| 131 | |||
| 132 | D-Bus has evolved over the years. New features have been added with | ||
| 133 | new D-Bus versions. There are two variables, which allow to determine | ||
| 134 | the used D-Bus version. | ||
| 135 | |||
| 136 | @defvar dbus-compiled-version | ||
| 137 | This variable, a string, determines the version of D-Bus Emacs is | ||
| 138 | compiled against. If it cannot be determined the value is @code{nil}. | ||
| 139 | @end defvar | ||
| 140 | |||
| 141 | @defvar dbus-runtime-version | ||
| 142 | The other D-Bus version to be checked is the version of D-Bus Emacs | ||
| 143 | runs with. This string can be different from @code{dbus-compiled-version}. | ||
| 144 | It is also @code{nil}, if it cannot be determined at runtime. | ||
| 145 | @end defvar | ||
| 146 | |||
| 147 | |||
| 128 | @node Bus names | 148 | @node Bus names |
| 129 | @section Bus names. | 149 | @section Bus names. |
| 130 | 150 | ||
| @@ -149,7 +169,6 @@ activatable service names at all. Example: | |||
| 149 | (member "org.gnome.evince.Daemon" | 169 | (member "org.gnome.evince.Daemon" |
| 150 | (dbus-list-activatable-names :session)) | 170 | (dbus-list-activatable-names :session)) |
| 151 | @end lisp | 171 | @end lisp |
| 152 | |||
| 153 | @end defun | 172 | @end defun |
| 154 | 173 | ||
| 155 | @defun dbus-list-names bus | 174 | @defun dbus-list-names bus |
| @@ -637,6 +656,12 @@ Interfaces can have properties. These can be exposed via the | |||
| 637 | That is, properties can be retrieved and changed during lifetime of an | 656 | That is, properties can be retrieved and changed during lifetime of an |
| 638 | element. | 657 | element. |
| 639 | 658 | ||
| 659 | A generalized interface is | ||
| 660 | @samp{org.freedesktop.DBus.Objectmanager}@footnote{See | ||
| 661 | @uref{http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager}}, | ||
| 662 | which returns objects, their interfaces and properties for a given | ||
| 663 | service in just one call. | ||
| 664 | |||
| 640 | Annotations, on the other hand, are static values for an element. | 665 | Annotations, on the other hand, are static values for an element. |
| 641 | Often, they are used to instruct generators, how to generate code from | 666 | Often, they are used to instruct generators, how to generate code from |
| 642 | the interface for a given language binding. | 667 | the interface for a given language binding. |
| @@ -732,6 +757,61 @@ If there are no properties, @code{nil} is returned. Example: | |||
| 732 | @end lisp | 757 | @end lisp |
| 733 | @end defun | 758 | @end defun |
| 734 | 759 | ||
| 760 | @defun dbus-get-all-managed-objects bus service path | ||
| 761 | This functions returns all objects at @var{bus}, @var{service}, | ||
| 762 | @var{path}, and the children of @var{path}. The result is a list of | ||
| 763 | objects. Every object is a cons of an existing path name, and the | ||
| 764 | list of available interface objects. An interface object is another | ||
| 765 | cons, which car is the interface name, and the cdr is the list of | ||
| 766 | properties as returned by @code{dbus-get-all-properties} for that path | ||
| 767 | and interface. Example: | ||
| 768 | |||
| 769 | @lisp | ||
| 770 | (dbus-get-all-managed-objects | ||
| 771 | :session "org.gnome.SettingsDaemon" "/") | ||
| 772 | |||
| 773 | @result{} (("/org/gnome/SettingsDaemon/MediaKeys" | ||
| 774 | ("org.gnome.SettingsDaemon.MediaKeys") | ||
| 775 | ("org.freedesktop.DBus.Peer") | ||
| 776 | ("org.freedesktop.DBus.Introspectable") | ||
| 777 | ("org.freedesktop.DBus.Properties") | ||
| 778 | ("org.freedesktop.DBus.ObjectManager")) | ||
| 779 | ("/org/gnome/SettingsDaemon/Power" | ||
| 780 | ("org.gnome.SettingsDaemon.Power.Keyboard") | ||
| 781 | ("org.gnome.SettingsDaemon.Power.Screen") | ||
| 782 | ("org.gnome.SettingsDaemon.Power" | ||
| 783 | ("Icon" . ". GThemedIcon battery-full-charged-symbolic ") | ||
| 784 | ("Tooltip" . "Laptop battery is charged")) | ||
| 785 | ("org.freedesktop.DBus.Peer") | ||
| 786 | ("org.freedesktop.DBus.Introspectable") | ||
| 787 | ("org.freedesktop.DBus.Properties") | ||
| 788 | ("org.freedesktop.DBus.ObjectManager")) | ||
| 789 | @dots{}) | ||
| 790 | @end lisp | ||
| 791 | |||
| 792 | If possible, @samp{org.freedesktop.DBus.ObjectManager.GetManagedObjects} | ||
| 793 | is used for retrieving the information. Otherwise, the information | ||
| 794 | is collected via @samp{org.freedesktop.DBus.Introspectable.Introspect} | ||
| 795 | and @samp{org.freedesktop.DBus.Properties.GetAll}, which is slow. | ||
| 796 | |||
| 797 | An overview of all existing object paths, their interfaces and | ||
| 798 | properties could be retrieved by the following code: | ||
| 799 | |||
| 800 | @lisp | ||
| 801 | (with-current-buffer (switch-to-buffer "*objectmanager*") | ||
| 802 | (erase-buffer) | ||
| 803 | (let (result) | ||
| 804 | (dolist (service (dbus-list-known-names :session) result) | ||
| 805 | (message "%s" service) | ||
| 806 | (add-to-list | ||
| 807 | 'result | ||
| 808 | (cons service | ||
| 809 | (dbus-get-all-managed-objects :session service "/")))) | ||
| 810 | (insert (message "%s" (pp result))) | ||
| 811 | (redisplay t))) | ||
| 812 | @end lisp | ||
| 813 | @end defun | ||
| 814 | |||
| 735 | @defun dbus-introspect-get-annotation-names bus service path interface &optional name | 815 | @defun dbus-introspect-get-annotation-names bus service path interface &optional name |
| 736 | Return a list of all annotation names as list of strings. If | 816 | Return a list of all annotation names as list of strings. If |
| 737 | @var{name} is @code{nil}, the annotations are children of | 817 | @var{name} is @code{nil}, the annotations are children of |
| @@ -928,6 +1008,10 @@ represented outside this range are stripped of. For example, | |||
| 928 | @code{:byte ?x} is equal to @code{:byte ?\M-x}, but it is not equal to | 1008 | @code{:byte ?x} is equal to @code{:byte ?\M-x}, but it is not equal to |
| 929 | @code{:byte ?\C-x} or @code{:byte ?\M-\C-x}. | 1009 | @code{:byte ?\C-x} or @code{:byte ?\M-\C-x}. |
| 930 | 1010 | ||
| 1011 | Signed and unsigned integer D-Bus types expect a corresponding integer | ||
| 1012 | value. If the value does not fit Emacs's integer range, it is also | ||
| 1013 | possible to use an equivalent floating point number. | ||
| 1014 | |||
| 931 | A D-Bus compound type is always represented as a list. The @sc{car} | 1015 | A D-Bus compound type is always represented as a list. The @sc{car} |
| 932 | of this list can be the type symbol @code{:array}, @code{:variant}, | 1016 | of this list can be the type symbol @code{:array}, @code{:variant}, |
| 933 | @code{:struct} or @code{:dict-entry}, which would result in a | 1017 | @code{:struct} or @code{:dict-entry}, which would result in a |
| @@ -1182,24 +1266,6 @@ emulate the @code{lshal} command on GNU/Linux systems: | |||
| 1182 | @end lisp | 1266 | @end lisp |
| 1183 | @end defun | 1267 | @end defun |
| 1184 | 1268 | ||
| 1185 | @defun dbus-call-method-non-blocking bus service path interface method &optional :timeout timeout &rest args | ||
| 1186 | Call @var{method} on the D-Bus @var{bus}, but don't block the event queue. | ||
| 1187 | This is necessary for communicating to registered D-Bus methods, | ||
| 1188 | which are running in the same Emacs process. | ||
| 1189 | |||
| 1190 | The arguments are the same as in @code{dbus-call-method}. Example: | ||
| 1191 | |||
| 1192 | @lisp | ||
| 1193 | (dbus-call-method-non-blocking | ||
| 1194 | :system "org.freedesktop.Hal" | ||
| 1195 | "/org/freedesktop/Hal/devices/computer" | ||
| 1196 | "org.freedesktop.Hal.Device" "GetPropertyString" | ||
| 1197 | "system.kernel.machine") | ||
| 1198 | |||
| 1199 | @result{} "i686" | ||
| 1200 | @end lisp | ||
| 1201 | @end defun | ||
| 1202 | |||
| 1203 | 1269 | ||
| 1204 | @node Asynchronous Methods | 1270 | @node Asynchronous Methods |
| 1205 | @chapter Calling methods non-blocking. | 1271 | @chapter Calling methods non-blocking. |
| @@ -1229,7 +1295,7 @@ All other arguments args are passed to @var{method} as arguments. | |||
| 1229 | They are converted into D-Bus types as described in @ref{Type | 1295 | They are converted into D-Bus types as described in @ref{Type |
| 1230 | Conversion}. | 1296 | Conversion}. |
| 1231 | 1297 | ||
| 1232 | Unless @var{handler} is @code{nil}, the function returns a key into | 1298 | If @var{handler} is a Lisp function, the function returns a key into |
| 1233 | the hash table @code{dbus-registered-objects-table}. The | 1299 | the hash table @code{dbus-registered-objects-table}. The |
| 1234 | corresponding entry in the hash table is removed, when the return | 1300 | corresponding entry in the hash table is removed, when the return |
| 1235 | message has been arrived, and @var{handler} is called. Example: | 1301 | message has been arrived, and @var{handler} is called. Example: |
| @@ -1241,7 +1307,7 @@ message has been arrived, and @var{handler} is called. Example: | |||
| 1241 | "org.freedesktop.Hal.Device" "GetPropertyString" 'message | 1307 | "org.freedesktop.Hal.Device" "GetPropertyString" 'message |
| 1242 | "system.kernel.machine") | 1308 | "system.kernel.machine") |
| 1243 | 1309 | ||
| 1244 | @result{} (:system 2) | 1310 | @result{} (:serial :system 2) |
| 1245 | 1311 | ||
| 1246 | @print{} i686 | 1312 | @print{} i686 |
| 1247 | @end lisp | 1313 | @end lisp |
| @@ -1323,19 +1389,21 @@ implementation of an interface of a well known service, like | |||
| 1323 | 1389 | ||
| 1324 | It could be also an implementation of an own interface. In this case, | 1390 | It could be also an implementation of an own interface. In this case, |
| 1325 | the service name must be @samp{org.gnu.Emacs}. The object path shall | 1391 | the service name must be @samp{org.gnu.Emacs}. The object path shall |
| 1326 | begin with @samp{/org/gnu/Emacs/@strong{Application}/}, and the | 1392 | begin with @samp{/org/gnu/Emacs/@strong{Application}}, and the |
| 1327 | interface name shall be @code{org.gnu.Emacs.@strong{Application}}. | 1393 | interface name shall be @code{org.gnu.Emacs.@strong{Application}}. |
| 1328 | @samp{@strong{Application}} is the name of the application which | 1394 | @samp{@strong{Application}} is the name of the application which |
| 1329 | provides the interface. | 1395 | provides the interface. |
| 1330 | 1396 | ||
| 1331 | @deffn Constant dbus-service-emacs | 1397 | @deffn Constant dbus-service-emacs |
| 1332 | The well known service name of Emacs. | 1398 | The well known service name @samp{org.gnu.Emacs} of Emacs. |
| 1333 | @end deffn | 1399 | @end deffn |
| 1334 | 1400 | ||
| 1335 | @deffn Constant dbus-path-emacs | 1401 | @deffn Constant dbus-path-emacs |
| 1336 | The object path head "/org/gnu/Emacs" used by Emacs. All object | 1402 | The object path namespace @samp{/org/gnu/Emacs} used by Emacs. |
| 1337 | paths, used by offered methods or signals, shall start with this | 1403 | @end deffn |
| 1338 | string. | 1404 | |
| 1405 | @deffn Constant dbus-interface-emacs | ||
| 1406 | The interface namespace @code{org.gnu.Emacs} used by Emacs. | ||
| 1339 | @end deffn | 1407 | @end deffn |
| 1340 | 1408 | ||
| 1341 | @defun dbus-register-method bus service path interface method handler dont-register-service | 1409 | @defun dbus-register-method bus service path interface method handler dont-register-service |
| @@ -1400,7 +1468,7 @@ registration for @var{method}. Example: | |||
| 1400 | "org.freedesktop.TextEditor" "OpenFile" | 1468 | "org.freedesktop.TextEditor" "OpenFile" |
| 1401 | 'my-dbus-method-handler) | 1469 | 'my-dbus-method-handler) |
| 1402 | 1470 | ||
| 1403 | @result{} ((:session "org.freedesktop.TextEditor" "OpenFile") | 1471 | @result{} ((:method :session "org.freedesktop.TextEditor" "OpenFile") |
| 1404 | ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor" | 1472 | ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor" |
| 1405 | my-dbus-method-handler)) | 1473 | my-dbus-method-handler)) |
| 1406 | @end lisp | 1474 | @end lisp |
| @@ -1497,14 +1565,14 @@ clients from discovering the still incomplete interface. | |||
| 1497 | :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor" | 1565 | :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor" |
| 1498 | "org.freedesktop.TextEditor" "name" :read "GNU Emacs") | 1566 | "org.freedesktop.TextEditor" "name" :read "GNU Emacs") |
| 1499 | 1567 | ||
| 1500 | @result{} ((:session "org.freedesktop.TextEditor" "name") | 1568 | @result{} ((:property :session "org.freedesktop.TextEditor" "name") |
| 1501 | ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor")) | 1569 | ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor")) |
| 1502 | 1570 | ||
| 1503 | (dbus-register-property | 1571 | (dbus-register-property |
| 1504 | :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor" | 1572 | :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor" |
| 1505 | "org.freedesktop.TextEditor" "version" :readwrite emacs-version t) | 1573 | "org.freedesktop.TextEditor" "version" :readwrite emacs-version t) |
| 1506 | 1574 | ||
| 1507 | @result{} ((:session "org.freedesktop.TextEditor" "version") | 1575 | @result{} ((:property :session "org.freedesktop.TextEditor" "version") |
| 1508 | ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor")) | 1576 | ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor")) |
| 1509 | @end lisp | 1577 | @end lisp |
| 1510 | 1578 | ||
| @@ -1569,8 +1637,8 @@ to the service from D-Bus. | |||
| 1569 | @chapter Sending and receiving signals. | 1637 | @chapter Sending and receiving signals. |
| 1570 | @cindex signals | 1638 | @cindex signals |
| 1571 | 1639 | ||
| 1572 | Signals are broadcast messages. They carry input parameters, which | 1640 | Signals are one way messages. They carry input parameters, which are |
| 1573 | are received by all objects which have registered for such a signal. | 1641 | received by all objects which have registered for such a signal. |
| 1574 | 1642 | ||
| 1575 | @defun dbus-send-signal bus service path interface signal &rest args | 1643 | @defun dbus-send-signal bus service path interface signal &rest args |
| 1576 | This function is similar to @code{dbus-call-method}. The difference | 1644 | This function is similar to @code{dbus-call-method}. The difference |
| @@ -1580,10 +1648,14 @@ The function emits @var{signal} on the D-Bus @var{bus}. @var{bus} is | |||
| 1580 | either the symbol @code{:system} or the symbol @code{:session}. It | 1648 | either the symbol @code{:system} or the symbol @code{:session}. It |
| 1581 | doesn't matter whether another object has registered for @var{signal}. | 1649 | doesn't matter whether another object has registered for @var{signal}. |
| 1582 | 1650 | ||
| 1583 | @var{service} is the D-Bus service name of the object the signal is | 1651 | Signals can be unicast or broadcast messages. For broadcast messages, |
| 1584 | emitted from. @var{path} is the corresponding D-Bus object path, | 1652 | @var{service} must be @code{nil}. Otherwise, @var{service} is the |
| 1585 | @var{service} is registered at. @var{interface} is an interface | 1653 | D-Bus service name the signal is sent to as unicast |
| 1586 | offered by @var{service}. It must provide @var{signal}. | 1654 | message.@footnote{For backward compatibility, a broadcast message is |
| 1655 | also emitted if @var{service} is the known or unique name Emacs is | ||
| 1656 | registered at D-Bus @var{bus}.} @var{path} is the D-Bus object path | ||
| 1657 | @var{signal} is sent from. @var{interface} is an interface available | ||
| 1658 | at @var{path}. It must provide @var{signal}. | ||
| 1587 | 1659 | ||
| 1588 | All other arguments args are passed to @var{signal} as arguments. | 1660 | All other arguments args are passed to @var{signal} as arguments. |
| 1589 | They are converted into D-Bus types as described in @ref{Type | 1661 | They are converted into D-Bus types as described in @ref{Type |
| @@ -1591,15 +1663,15 @@ Conversion}. Example: | |||
| 1591 | 1663 | ||
| 1592 | @lisp | 1664 | @lisp |
| 1593 | (dbus-send-signal | 1665 | (dbus-send-signal |
| 1594 | :session dbus-service-emacs dbus-path-emacs | 1666 | :session nil dbus-path-emacs |
| 1595 | (concat dbus-service-emacs ".FileManager") "FileModified" | 1667 | (concat dbus-interface-emacs ".FileManager") "FileModified" |
| 1596 | "/home/albinus/.emacs") | 1668 | "/home/albinus/.emacs") |
| 1597 | @end lisp | 1669 | @end lisp |
| 1598 | @end defun | 1670 | @end defun |
| 1599 | 1671 | ||
| 1600 | @defun dbus-register-signal bus service path interface signal handler &rest args | 1672 | @defun dbus-register-signal bus service path interface signal handler &rest args |
| 1601 | With this function, an application registers for @var{signal} on the | 1673 | With this function, an application registers for a signal on the D-Bus |
| 1602 | D-Bus @var{bus}. | 1674 | @var{bus}. |
| 1603 | 1675 | ||
| 1604 | @var{bus} is either the symbol @code{:system} or the symbol | 1676 | @var{bus} is either the symbol @code{:system} or the symbol |
| 1605 | @code{:session}. | 1677 | @code{:session}. |
| @@ -1611,24 +1683,46 @@ unique name of the object, owning @var{service} at registration time. | |||
| 1611 | When the corresponding D-Bus object disappears, signals won't be | 1683 | When the corresponding D-Bus object disappears, signals won't be |
| 1612 | received any longer. | 1684 | received any longer. |
| 1613 | 1685 | ||
| 1614 | When @var{service} is @code{nil}, related signals from all D-Bus | ||
| 1615 | objects shall be accepted. | ||
| 1616 | |||
| 1617 | @var{path} is the corresponding D-Bus object path, @var{service} is | 1686 | @var{path} is the corresponding D-Bus object path, @var{service} is |
| 1618 | registered at. It can also be @code{nil} if the path name of incoming | 1687 | registered at. @var{interface} is an interface offered by |
| 1619 | signals shall not be checked. | 1688 | @var{service}. It must provide @var{signal}. |
| 1620 | 1689 | ||
| 1621 | @var{interface} is an interface offered by @var{service}. It must | 1690 | @var{service}, @var{path}, @var{interface} and @var{signal} can be |
| 1622 | provide @var{signal}. | 1691 | @code{nil}. This is interpreted as a wildcard for the respective |
| 1692 | argument. | ||
| 1623 | 1693 | ||
| 1624 | @var{handler} is a Lisp function to be called when the @var{signal} is | 1694 | @var{handler} is a Lisp function to be called when the @var{signal} is |
| 1625 | received. It must accept as arguments the output parameters | 1695 | received. It must accept as arguments the output parameters |
| 1626 | @var{signal} is sending. | 1696 | @var{signal} is sending. |
| 1627 | 1697 | ||
| 1628 | All other arguments @var{args}, if specified, must be strings. They | 1698 | The remaining arguments @var{args} can be keywords or keyword string |
| 1629 | stand for the respective arguments of @var{signal} in their order, and | 1699 | pairs.@footnote{For backward compatibility, the arguments @var{args} |
| 1630 | are used for filtering as well. A @code{nil} argument might be used | 1700 | can also be just strings. They stand for the respective arguments of |
| 1631 | to preserve the order. | 1701 | @var{signal} in their order, and are used for filtering as well. A |
| 1702 | @code{nil} argument might be used to preserve the order.} The meaning | ||
| 1703 | is as follows: | ||
| 1704 | |||
| 1705 | @itemize | ||
| 1706 | @item @code{:argN} @var{string}:@* | ||
| 1707 | @code{:pathN} @var{string}:@* | ||
| 1708 | This stands for the Nth argument of the signal. @code{:pathN} | ||
| 1709 | arguments can be used for object path wildcard matches as specified by | ||
| 1710 | D-Bus, whilest an @code{:argN} argument requires an exact match. | ||
| 1711 | |||
| 1712 | @item @code{:arg-namespace} @var{string}:@* | ||
| 1713 | Register for the signals, which first argument defines the service or | ||
| 1714 | interface namespace @var{string}. | ||
| 1715 | |||
| 1716 | @item @code{:path-namespace} @var{string}:@* | ||
| 1717 | Register for the object path namespace @var{string}. All signals sent | ||
| 1718 | from an object path, which has @var{string} as the preceding string, | ||
| 1719 | are matched. This requires @var{path} to be @code{nil}. | ||
| 1720 | |||
| 1721 | @item @code{:eavesdrop}:@* | ||
| 1722 | Register for unicast signals which are not directed to the D-Bus | ||
| 1723 | object Emacs is registered at D-Bus BUS, if the security policy of BUS | ||
| 1724 | allows this. Otherwise, this argument is ignored. | ||
| 1725 | @end itemize | ||
| 1632 | 1726 | ||
| 1633 | @code{dbus-register-signal} returns a Lisp object, which can be used | 1727 | @code{dbus-register-signal} returns a Lisp object, which can be used |
| 1634 | as argument in @code{dbus-unregister-object} for removing the | 1728 | as argument in @code{dbus-unregister-object} for removing the |
| @@ -1645,7 +1739,7 @@ registration for @var{signal}. Example: | |||
| 1645 | "org.freedesktop.Hal.Manager" "DeviceAdded" | 1739 | "org.freedesktop.Hal.Manager" "DeviceAdded" |
| 1646 | 'my-dbus-signal-handler) | 1740 | 'my-dbus-signal-handler) |
| 1647 | 1741 | ||
| 1648 | @result{} ((:system "org.freedesktop.Hal.Manager" "DeviceAdded") | 1742 | @result{} ((:signal :system "org.freedesktop.Hal.Manager" "DeviceAdded") |
| 1649 | ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager" | 1743 | ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager" |
| 1650 | my-signal-handler)) | 1744 | my-signal-handler)) |
| 1651 | @end lisp | 1745 | @end lisp |
| @@ -1657,23 +1751,36 @@ The callback function @code{my-dbus-signal-handler} must define one | |||
| 1657 | single string argument therefore. Plugging an USB device to your | 1751 | single string argument therefore. Plugging an USB device to your |
| 1658 | machine, when registered for signal @samp{DeviceAdded}, will show you | 1752 | machine, when registered for signal @samp{DeviceAdded}, will show you |
| 1659 | which objects the GNU/Linux @code{hal} daemon adds. | 1753 | which objects the GNU/Linux @code{hal} daemon adds. |
| 1754 | |||
| 1755 | Some of the match rules have been added to a later version of D-Bus. | ||
| 1756 | In order to test the availability of such features, you could register | ||
| 1757 | for a dummy signal, and check the result: | ||
| 1758 | |||
| 1759 | @lisp | ||
| 1760 | (dbus-ignore-errors | ||
| 1761 | (dbus-register-signal | ||
| 1762 | :system nil nil nil nil 'ignore :path-namespace "/invalid/path")) | ||
| 1763 | |||
| 1764 | @result{} nil | ||
| 1765 | @end lisp | ||
| 1660 | @end defun | 1766 | @end defun |
| 1661 | 1767 | ||
| 1662 | 1768 | ||
| 1663 | @node Alternative Buses | 1769 | @node Alternative Buses |
| 1664 | @chapter Alternative buses. | 1770 | @chapter Alternative buses and environments. |
| 1665 | @cindex bus names | 1771 | @cindex bus names |
| 1666 | @cindex UNIX domain socket | 1772 | @cindex UNIX domain socket |
| 1773 | @cindex TCP/IP socket | ||
| 1667 | 1774 | ||
| 1668 | Until now, we have spoken about the system and the session buses, | 1775 | Until now, we have spoken about the system and the session buses, |
| 1669 | which are the default buses to be connected to. However, it is | 1776 | which are the default buses to be connected to. However, it is |
| 1670 | possible to connect to any bus, from which the address is known. This | 1777 | possible to connect to any bus, from which the address is known. This |
| 1671 | is a UNIX domain socket. Everywhere, where a @var{bus} is mentioned | 1778 | is a UNIX domain or TCP/IP socket. Everywhere, where a @var{bus} is |
| 1672 | as argument of a function (the symbol @code{:system} or the symbol | 1779 | mentioned as argument of a function (the symbol @code{:system} or the |
| 1673 | @code{:session}), this address can be used instead. The connection to | 1780 | symbol @code{:session}), this address can be used instead. The |
| 1674 | this bus must be initialized first. | 1781 | connection to this bus must be initialized first. |
| 1675 | 1782 | ||
| 1676 | @defun dbus-init-bus bus | 1783 | @defun dbus-init-bus bus &optional private |
| 1677 | Establish the connection to D-Bus @var{bus}. | 1784 | Establish the connection to D-Bus @var{bus}. |
| 1678 | 1785 | ||
| 1679 | @var{bus} can be either the symbol @code{:system} or the symbol | 1786 | @var{bus} can be either the symbol @code{:system} or the symbol |
| @@ -1682,30 +1789,90 @@ corresponding bus. For the system and session buses, this function | |||
| 1682 | is called when loading @file{dbus.el}, there is no need to call it | 1789 | is called when loading @file{dbus.el}, there is no need to call it |
| 1683 | again. | 1790 | again. |
| 1684 | 1791 | ||
| 1685 | Example: You open another session bus in a terminal window on your host: | 1792 | The function returns a number, which counts the connections this Emacs |
| 1793 | session has established to the @var{bus} under the same unique name | ||
| 1794 | (see @code{dbus-get-unique-name}). It depends on the libraries Emacs | ||
| 1795 | is linked with, and on the environment Emacs is running. For example, | ||
| 1796 | if Emacs is linked with the gtk toolkit, and it runs in a GTK-aware | ||
| 1797 | environment like Gnome, another connection might already be | ||
| 1798 | established. | ||
| 1686 | 1799 | ||
| 1687 | @example | 1800 | When @var{private} is non-@code{nil}, a new connection is established |
| 1688 | # eval `dbus-launch --auto-syntax` | 1801 | instead of reusing an existing one. It results in a new unique name |
| 1689 | # echo $DBUS_SESSION_BUS_ADDRESS | 1802 | at the bus. This can be used, if it is necessary to distinguish from |
| 1803 | another connection used in the same Emacs process, like the one | ||
| 1804 | established by GTK+. It should be used with care for at least the | ||
| 1805 | @code{:system} and @code{:session} buses, because other Emacs Lisp | ||
| 1806 | packages might already use this connection to those buses. | ||
| 1690 | 1807 | ||
| 1691 | @print{} unix:abstract=/tmp/dbus-JoFtAVG92w,guid=2f320a1ebe50b7ef58e | 1808 | Example: You initialize a connection to the AT-SPI bus on your host: |
| 1692 | @end example | ||
| 1693 | |||
| 1694 | In Emacs, you can access to this bus via its address: | ||
| 1695 | 1809 | ||
| 1696 | @lisp | 1810 | @lisp |
| 1697 | (setq my-bus | 1811 | (setq my-bus |
| 1698 | "unix:abstract=/tmp/dbus-JoFtAVG92w,guid=2f320a1ebe50b7ef58e") | 1812 | (dbus-call-method |
| 1813 | :session "org.a11y.Bus" "/org/a11y/bus" | ||
| 1814 | "org.a11y.Bus" "GetAddress")) | ||
| 1699 | 1815 | ||
| 1700 | @result{} "unix:abstract=/tmp/dbus-JoFtAVG92w,guid=2f320a1ebe50b7ef58e" | 1816 | @result{} "unix:abstract=/tmp/dbus-2yzWHOCdSD,guid=a490dd26625870ca1298b6e10000fd7f" |
| 1701 | 1817 | ||
| 1818 | ;; If Emacs is built with gtk support, and you run in a GTK enabled | ||
| 1819 | ;; environment (like a GNOME session), the initialization reuses the | ||
| 1820 | ;; connection established by GTK's atk bindings. | ||
| 1702 | (dbus-init-bus my-bus) | 1821 | (dbus-init-bus my-bus) |
| 1703 | 1822 | ||
| 1704 | @result{} nil | 1823 | @result{} 2 |
| 1705 | 1824 | ||
| 1706 | (dbus-get-unique-name my-bus) | 1825 | (dbus-get-unique-name my-bus) |
| 1707 | 1826 | ||
| 1708 | @result{} ":1.0" | 1827 | @result{} ":1.19" |
| 1828 | |||
| 1829 | ;; Open a new connection to the same bus. This obsoletes the | ||
| 1830 | ;; previous one. | ||
| 1831 | (dbus-init-bus my-bus 'private) | ||
| 1832 | |||
| 1833 | @result{} 1 | ||
| 1834 | |||
| 1835 | (dbus-get-unique-name my-bus) | ||
| 1836 | |||
| 1837 | @result{} ":1.20" | ||
| 1838 | @end lisp | ||
| 1839 | |||
| 1840 | D-Bus addresses can specify different transport. A possible address | ||
| 1841 | could be based on TCP/IP sockets, see next example. However, it | ||
| 1842 | depends on the bus daemon configuration, which transport is supported. | ||
| 1843 | @end defun | ||
| 1844 | |||
| 1845 | @defun dbus-setenv bus variable value | ||
| 1846 | Set the value of the @var{bus} environment variable @var{variable} to | ||
| 1847 | @var{value}. | ||
| 1848 | |||
| 1849 | @var{bus} is either a Lisp symbol, @code{:system} or @code{:session}, | ||
| 1850 | or a string denoting the bus address. Both @var{variable} and | ||
| 1851 | @var{value} should be strings. | ||
| 1852 | |||
| 1853 | Normally, services inherit the environment of the bus daemon. This | ||
| 1854 | function adds to or modifies that environment when activating services. | ||
| 1855 | |||
| 1856 | Some bus instances, such as @code{:system}, may disable setting the | ||
| 1857 | environment. In such cases, or if this feature is not available in | ||
| 1858 | older D-Bus versions, a @code{dbus-error} error is raised. | ||
| 1859 | |||
| 1860 | As an example, it might be desirable to start X11 enabled services on | ||
| 1861 | a remote host's bus on the same X11 server the local Emacs is | ||
| 1862 | running. This could be achieved by | ||
| 1863 | |||
| 1864 | @lisp | ||
| 1865 | (setq my-bus "unix:host=example.gnu.org,port=4711") | ||
| 1866 | |||
| 1867 | @result{} "unix:host=example.gnu.org,port=4711" | ||
| 1868 | |||
| 1869 | (dbus-init-bus my-bus) | ||
| 1870 | |||
| 1871 | @result{} 1 | ||
| 1872 | |||
| 1873 | (dbus-setenv my-bus "DISPLAY" (getenv "DISPLAY")) | ||
| 1874 | |||
| 1875 | @result{} nil | ||
| 1709 | @end lisp | 1876 | @end lisp |
| 1710 | @end defun | 1877 | @end defun |
| 1711 | 1878 | ||
| @@ -1723,8 +1890,8 @@ If this variable is non-@code{nil}, D-Bus specific debug messages are raised. | |||
| 1723 | @end defvar | 1890 | @end defvar |
| 1724 | 1891 | ||
| 1725 | Input parameters of @code{dbus-call-method}, | 1892 | Input parameters of @code{dbus-call-method}, |
| 1726 | @code{dbus-call-method-non-blocking}, | 1893 | @code{dbus-call-method-asynchronously}, @code{dbus-send-signal}, |
| 1727 | @code{dbus-call-method-asynchronously}, and | 1894 | @code{dbus-register-method}, @code{dbus-register-property} and |
| 1728 | @code{dbus-register-signal} are checked for correct D-Bus types. If | 1895 | @code{dbus-register-signal} are checked for correct D-Bus types. If |
| 1729 | there is a type mismatch, the Lisp error @code{wrong-type-argument} | 1896 | there is a type mismatch, the Lisp error @code{wrong-type-argument} |
| 1730 | @code{D-Bus ARG} is raised. | 1897 | @code{D-Bus ARG} is raised. |
| @@ -1825,7 +1992,7 @@ Example: | |||
| 1825 | 1992 | ||
| 1826 | @lisp | 1993 | @lisp |
| 1827 | (defun my-dbus-event-error-handler (event error) | 1994 | (defun my-dbus-event-error-handler (event error) |
| 1828 | (when (string-equal (concat dbus-service-emacs ".FileManager") | 1995 | (when (string-equal (concat dbus-interface-emacs ".FileManager") |
| 1829 | (dbus-event-interface-name event)) | 1996 | (dbus-event-interface-name event)) |
| 1830 | (message "my-dbus-event-error-handler: %S %S" event error) | 1997 | (message "my-dbus-event-error-handler: %S %S" event error) |
| 1831 | (signal 'file-error (cdr error)))) | 1998 | (signal 'file-error (cdr error)))) |