annotate lisp/net/dbus.el @ 112181:af71852e09a2

* net/dbus.el (dbus-unregister-service): Translate returned integer into a symbol. (dbus-register-property): Use `dbus-register-service' to do the name registration.
author Michael Albinus <michael.albinus@gmx.de>
date Mon, 10 Jan 2011 10:46:19 +0100
parents 318b7249ccd0
children adafd735e9aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
1 ;;; dbus.el --- Elisp bindings for D-Bus.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
2
112112
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
3 ;; Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
4
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
6 ;; Keywords: comm, hardware
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
7
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
9
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91728
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91728
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91728
diff changeset
13 ;; (at your option) any later version.
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
14
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
18 ;; GNU General Public License for more details.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
19
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91728
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
22
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
23 ;;; Commentary:
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
24
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
25 ;; This package provides language bindings for the D-Bus API. D-Bus
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
26 ;; is a message bus system, a simple way for applications to talk to
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
27 ;; one another. See <http://dbus.freedesktop.org/> for details.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
28
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
29 ;; Low-level language bindings are implemented in src/dbusbind.c.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
30
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
31 ;;; Code:
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
32
91484
7ddf7059d131 * dbus.el (top): Check (featurep 'dbusbind).
Michael Albinus <michael.albinus@gmx.de>
parents: 87885
diff changeset
33 ;; D-Bus support in the Emacs core can be disabled with configuration
91728
58bf306db72e * net/dbus.el: Remove `no-byte-compile' cookie.
Michael Albinus <michael.albinus@gmx.de>
parents: 91589
diff changeset
34 ;; option "--without-dbus". Declare used subroutines and variables.
58bf306db72e * net/dbus.el: Remove `no-byte-compile' cookie.
Michael Albinus <michael.albinus@gmx.de>
parents: 91589
diff changeset
35 (declare-function dbus-call-method "dbusbind.c")
97261
d5e87cca37af * net/dbus.el (dbus-call-method-asynchronously): Declare
Michael Albinus <michael.albinus@gmx.de>
parents: 97260
diff changeset
36 (declare-function dbus-call-method-asynchronously "dbusbind.c")
104337
709480950021 * net/dbus.el (dbus-init-bus): Declare. Apply it for the :system
Michael Albinus <michael.albinus@gmx.de>
parents: 104081
diff changeset
37 (declare-function dbus-init-bus "dbusbind.c")
97260
409001287195 * net/dbus.el (dbus-method-return-internal)
Michael Albinus <michael.albinus@gmx.de>
parents: 97213
diff changeset
38 (declare-function dbus-method-return-internal "dbusbind.c")
409001287195 * net/dbus.el (dbus-method-return-internal)
Michael Albinus <michael.albinus@gmx.de>
parents: 97213
diff changeset
39 (declare-function dbus-method-error-internal "dbusbind.c")
91728
58bf306db72e * net/dbus.el: Remove `no-byte-compile' cookie.
Michael Albinus <michael.albinus@gmx.de>
parents: 91589
diff changeset
40 (declare-function dbus-register-signal "dbusbind.c")
108938
319b48a599cf * net/dbus.el: Fix typos and declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 107255
diff changeset
41 (declare-function dbus-register-method "dbusbind.c")
109132
0f3ed79830e9 * net/dbus.el (dbus-send-signal): Declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 109127
diff changeset
42 (declare-function dbus-send-signal "dbusbind.c")
91728
58bf306db72e * net/dbus.el: Remove `no-byte-compile' cookie.
Michael Albinus <michael.albinus@gmx.de>
parents: 91589
diff changeset
43 (defvar dbus-debug)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
44 (defvar dbus-registered-objects-table)
91728
58bf306db72e * net/dbus.el: Remove `no-byte-compile' cookie.
Michael Albinus <michael.albinus@gmx.de>
parents: 91589
diff changeset
45
58bf306db72e * net/dbus.el: Remove `no-byte-compile' cookie.
Michael Albinus <michael.albinus@gmx.de>
parents: 91589
diff changeset
46 ;; Pacify byte compiler.
58bf306db72e * net/dbus.el: Remove `no-byte-compile' cookie.
Michael Albinus <michael.albinus@gmx.de>
parents: 91589
diff changeset
47 (eval-when-compile
58bf306db72e * net/dbus.el: Remove `no-byte-compile' cookie.
Michael Albinus <michael.albinus@gmx.de>
parents: 91589
diff changeset
48 (require 'cl))
91484
7ddf7059d131 * dbus.el (top): Check (featurep 'dbusbind).
Michael Albinus <michael.albinus@gmx.de>
parents: 87885
diff changeset
49
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
50 (require 'xml)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
51
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
52 (defconst dbus-service-dbus "org.freedesktop.DBus"
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
53 "The bus name used to talk to the bus itself.")
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
54
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
55 (defconst dbus-path-dbus "/org/freedesktop/DBus"
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
56 "The object path used to talk to the bus itself.")
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
57
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
58 (defconst dbus-interface-dbus "org.freedesktop.DBus"
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
59 "The interface exported by the object with `dbus-service-dbus' and `dbus-path-dbus'.")
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
60
91588
83afe69ce25e * net/dbus.el (dbus-interface-peer): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 91484
diff changeset
61 (defconst dbus-interface-peer (concat dbus-interface-dbus ".Peer")
83afe69ce25e * net/dbus.el (dbus-interface-peer): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 91484
diff changeset
62 "The interface for peer objects.")
83afe69ce25e * net/dbus.el (dbus-interface-peer): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 91484
diff changeset
63
83afe69ce25e * net/dbus.el (dbus-interface-peer): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 91484
diff changeset
64 (defconst dbus-interface-introspectable
83afe69ce25e * net/dbus.el (dbus-interface-peer): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 91484
diff changeset
65 (concat dbus-interface-dbus ".Introspectable")
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
66 "The interface supported by introspectable objects.")
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
67
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
68 (defconst dbus-interface-properties (concat dbus-interface-dbus ".Properties")
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
69 "The interface for property objects.")
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
70
98668
a7acd2697027 * net/dbus.el (dbus-service-emacs, dbus-path-emacs): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 97692
diff changeset
71 (defconst dbus-service-emacs "org.gnu.Emacs"
a7acd2697027 * net/dbus.el (dbus-service-emacs, dbus-path-emacs): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 97692
diff changeset
72 "The well known service name of Emacs.")
a7acd2697027 * net/dbus.el (dbus-service-emacs, dbus-path-emacs): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 97692
diff changeset
73
a7acd2697027 * net/dbus.el (dbus-service-emacs, dbus-path-emacs): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 97692
diff changeset
74 (defconst dbus-path-emacs "/org/gnu/Emacs"
a7acd2697027 * net/dbus.el (dbus-service-emacs, dbus-path-emacs): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 97692
diff changeset
75 "The object path head used by Emacs.")
a7acd2697027 * net/dbus.el (dbus-service-emacs, dbus-path-emacs): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 97692
diff changeset
76
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
77 (defconst dbus-message-type-invalid 0
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
78 "This value is never a valid message type.")
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
79
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
80 (defconst dbus-message-type-method-call 1
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
81 "Message type of a method call message.")
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
82
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
83 (defconst dbus-message-type-method-return 2
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
84 "Message type of a method return message.")
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
85
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
86 (defconst dbus-message-type-error 3
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
87 "Message type of an error reply message.")
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
88
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
89 (defconst dbus-message-type-signal 4
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
90 "Message type of a signal message.")
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
91
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
92 (defmacro dbus-ignore-errors (&rest body)
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
93 "Execute BODY; signal D-Bus error when `dbus-debug' is non-nil.
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
94 Otherwise, return result of last form in BODY, or all other errors."
110034
c87f89486bb7 Use `declare' in defmacros.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109962
diff changeset
95 (declare (indent 0) (debug t))
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
96 `(condition-case err
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
97 (progn ,@body)
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
98 (dbus-error (when dbus-debug (signal (car err) (cdr err))))))
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
99 (font-lock-add-keywords 'emacs-lisp-mode '("\\<dbus-ignore-errors\\>"))
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
100
101525
5951f5343bb5 * net/dbus.el (dbus-event-error-hooks): New variable.
Michael Albinus <michael.albinus@gmx.de>
parents: 100855
diff changeset
101 (defvar dbus-event-error-hooks nil
5951f5343bb5 * net/dbus.el (dbus-event-error-hooks): New variable.
Michael Albinus <michael.albinus@gmx.de>
parents: 100855
diff changeset
102 "Functions to be called when a D-Bus error happens in the event handler.
101619
df3f6041e002 * net/dbus.el (dbus-event-error-hooks): Fix docstring. Describe
Michael Albinus <michael.albinus@gmx.de>
parents: 101525
diff changeset
103 Every function must accept two arguments, the event and the error variable
101525
5951f5343bb5 * net/dbus.el (dbus-event-error-hooks): New variable.
Michael Albinus <michael.albinus@gmx.de>
parents: 100855
diff changeset
104 catched in `condition-case' by `dbus-error'.")
5951f5343bb5 * net/dbus.el (dbus-event-error-hooks): New variable.
Michael Albinus <michael.albinus@gmx.de>
parents: 100855
diff changeset
105
87050
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
106
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
107 ;;; Hash table of registered functions.
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
108
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
109 (defvar dbus-return-values-table (make-hash-table :test 'equal)
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
110 "Hash table for temporary storing arguments of reply messages.
109962
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
111 A key in this hash table is a list (BUS SERIAL). BUS is either a
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
112 Lisp symbol, `:system' or `:session', or a string denoting the
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
113 bus address. SERIAL is the serial number of the reply message.
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
114 See `dbus-call-method-non-blocking-handler' and
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
115 `dbus-call-method-non-blocking'.")
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
116
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
117 (defun dbus-list-hash-table ()
87586
9554989ee375 * net/dbus.el (dbus-list-hash-table)
Michael Albinus <michael.albinus@gmx.de>
parents: 87537
diff changeset
118 "Returns all registered member registrations to D-Bus.
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
119 The return value is a list, with elements of kind (KEY . VALUE).
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
120 See `dbus-registered-objects-table' for a description of the
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
121 hash table."
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
122 (let (result)
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
123 (maphash
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
124 '(lambda (key value) (add-to-list 'result (cons key value) 'append))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
125 dbus-registered-objects-table)
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
126 result))
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
127
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
128 (defun dbus-unregister-object (object)
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
129 "Unregister OBJECT from D-Bus.
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
130 OBJECT must be the result of a preceding `dbus-register-method',
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
131 `dbus-register-property' or `dbus-register-signal' call. It
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
132 returns `t' if OBJECT has been unregistered, `nil' otherwise.
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
133
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
134 When OBJECT identifies the last method or property, which is
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
135 registered for the respective service, Emacs releases its
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
136 association to the service from D-Bus."
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
137 ;; Check parameter.
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
138 (unless (and (consp object) (not (null (car object))) (consp (cdr object)))
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
139 (signal 'wrong-type-argument (list 'D-Bus object)))
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
140
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
141 ;; Find the corresponding entry in the hash table.
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
142 (let* ((key (car object))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
143 (value (cdr object))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
144 (entry (gethash key dbus-registered-objects-table))
105926
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
145 ret)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
146 ;; entry has the structure ((UNAME SERVICE PATH MEMBER) ...).
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
147 ;; value has the structure ((SERVICE PATH [HANDLER]) ...).
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
148 ;; MEMBER is either a string (the handler), or a cons cell (a
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
149 ;; property value). UNAME and property values are not taken into
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
150 ;; account for comparision.
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
151
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
152 ;; Loop over the registered functions.
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
153 (dolist (elt entry)
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
154 (when (equal
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
155 (car value)
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
156 (butlast (cdr elt) (- (length (cdr elt)) (length (car value)))))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
157 ;; Compute new hash value. If it is empty, remove it from the
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
158 ;; hash table.
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
159 (unless (puthash key (delete elt entry) dbus-registered-objects-table)
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
160 (remhash key dbus-registered-objects-table))
105926
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
161 (setq ret t)))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
162 ;; Check, whether there is still a registered function or property
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
163 ;; for the given service. If not, unregister the service from the
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
164 ;; bus.
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
165 (dolist (elt entry)
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
166 (let ((service (cadr elt))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
167 (bus (car key))
105926
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
168 found)
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
169 (maphash
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
170 (lambda (k v)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
171 (dolist (e v)
105926
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
172 (ignore-errors
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
173 (when (and (equal bus (car k)) (string-equal service (cadr e)))
105928
d91d3722b71f *** empty log message ***
Michael Albinus <michael.albinus@gmx.de>
parents: 105926
diff changeset
174 (setq found t)))))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
175 dbus-registered-objects-table)
105926
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
176 (unless found
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
177 (dbus-call-method
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
178 bus dbus-service-dbus dbus-path-dbus dbus-interface-dbus
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
179 "ReleaseName" service))))
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
180 ;; Return.
2b4cc3e45a7b * net/dbus.el (dbus-unregister-object): Release service, if no
Michael Albinus <michael.albinus@gmx.de>
parents: 104602
diff changeset
181 ret))
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
182
106050
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
183 (defun dbus-unregister-service (bus service)
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
184 "Unregister all objects related to SERVICE from D-Bus BUS.
109962
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
185 BUS is either a Lisp symbol, `:system' or `:session', or a string
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
186 denoting the bus address. SERVICE must be a known service name."
106050
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
187 (maphash
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
188 (lambda (key value)
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
189 (dolist (elt value)
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
190 (ignore-errors
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
191 (when (and (equal bus (car key)) (string-equal service (cadr elt)))
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
192 (unless
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
193 (puthash key (delete elt value) dbus-registered-objects-table)
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
194 (remhash key dbus-registered-objects-table))))))
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
195 dbus-registered-objects-table)
112181
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
196 (let ((reply (dbus-call-method
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
197 bus dbus-service-dbus dbus-path-dbus dbus-interface-dbus
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
198 "ReleaseName" service)))
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
199 (case reply
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
200 (1 :released)
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
201 (2 :non-existent)
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
202 (3 :not-owner)
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
203 (t (signal 'dbus-error "Could not unregister service")))))
106050
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
204
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
205 (defun dbus-call-method-non-blocking-handler (&rest args)
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
206 "Handler for reply messages of asynchronous D-Bus message calls.
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
207 It calls the function stored in `dbus-registered-objects-table'.
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
208 The result will be made available in `dbus-return-values-table'."
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
209 (puthash (list (dbus-event-bus-name last-input-event)
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
210 (dbus-event-serial-number last-input-event))
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
211 (if (= (length args) 1) (car args) args)
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
212 dbus-return-values-table))
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
213
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
214 (defun dbus-call-method-non-blocking
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
215 (bus service path interface method &rest args)
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
216 "Call METHOD on the D-Bus BUS, but don't block the event queue.
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
217 This is necessary for communicating to registered D-Bus methods,
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
218 which are running in the same Emacs process.
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
219
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
220 The arguments are the same as in `dbus-call-method'.
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
221
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
222 usage: (dbus-call-method-non-blocking
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
223 BUS SERVICE PATH INTERFACE METHOD
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
224 &optional :timeout TIMEOUT &rest ARGS)"
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
225
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
226 (let ((key
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
227 (apply
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
228 'dbus-call-method-asynchronously
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
229 bus service path interface method
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
230 'dbus-call-method-non-blocking-handler args)))
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
231 ;; Wait until `dbus-call-method-non-blocking-handler' has put the
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
232 ;; result into `dbus-return-values-table'.
104081
4c431a52ce37 * net/dbus.el (dbus-call-method-non-blocking): Handle the case the
Michael Albinus <michael.albinus@gmx.de>
parents: 101619
diff changeset
233 (while (eq (gethash key dbus-return-values-table :ignore) :ignore)
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
234 (read-event nil nil 0.1))
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
235
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
236 ;; Cleanup `dbus-return-values-table'. Return the result.
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
237 (prog1
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
238 (gethash key dbus-return-values-table nil)
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
239 (remhash key dbus-return-values-table))))
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
240
87492
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
241 (defun dbus-name-owner-changed-handler (&rest args)
87586
9554989ee375 * net/dbus.el (dbus-list-hash-table)
Michael Albinus <michael.albinus@gmx.de>
parents: 87537
diff changeset
242 "Reapplies all member registrations to D-Bus.
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
243 This handler is applied when a \"NameOwnerChanged\" signal has
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
244 arrived. SERVICE is the object name for which the name owner has
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
245 been changed. OLD-OWNER is the previous owner of SERVICE, or the
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
246 empty string if SERVICE was not owned yet. NEW-OWNER is the new
111333
de02b794c330 Don't be so lax with spelling.
Glenn Morris <rgm@gnu.org>
parents: 110034
diff changeset
247 owner of SERVICE, or the empty string if SERVICE loses any name owner.
87492
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
248
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
249 usage: (dbus-name-owner-changed-handler service old-owner new-owner)"
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
250 (save-match-data
87492
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
251 ;; Check the arguments. We should silently ignore it when they
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
252 ;; are wrong.
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
253 (if (and (= (length args) 3)
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
254 (stringp (car args))
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
255 (stringp (cadr args))
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
256 (stringp (caddr args)))
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
257 (let ((service (car args))
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
258 (old-owner (cadr args))
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
259 (new-owner (caddr args)))
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
260 ;; Check whether SERVICE is a known name.
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
261 (when (not (string-match "^:" service))
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
262 (maphash
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
263 '(lambda (key value)
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
264 (dolist (elt value)
87586
9554989ee375 * net/dbus.el (dbus-list-hash-table)
Michael Albinus <michael.albinus@gmx.de>
parents: 87537
diff changeset
265 ;; key has the structure (BUS INTERFACE MEMBER).
87492
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
266 ;; elt has the structure (UNAME SERVICE PATH HANDLER).
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
267 (when (string-equal old-owner (car elt))
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
268 ;; Remove old key, and add new entry with changed name.
87537
84ece2f8e012 * net/dbus.el (dbus-name-owner-changed-handler): Use
Magnus Henoch <mange@freemail.hu>
parents: 87492
diff changeset
269 (dbus-unregister-object (list key (cdr elt)))
87492
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
270 ;; Maybe we could arrange the lists a little bit better
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
271 ;; that we don't need to extract every single element?
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
272 (dbus-register-signal
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
273 ;; BUS SERVICE PATH
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
274 (nth 0 key) (nth 1 elt) (nth 2 elt)
87586
9554989ee375 * net/dbus.el (dbus-list-hash-table)
Michael Albinus <michael.albinus@gmx.de>
parents: 87537
diff changeset
275 ;; INTERFACE MEMBER HANDLER
87492
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
276 (nth 1 key) (nth 2 key) (nth 3 elt)))))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
277 (copy-hash-table dbus-registered-objects-table))))
87492
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
278 ;; The error is reported only in debug mode.
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
279 (when dbus-debug
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
280 (signal
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
281 'dbus-error
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
282 (cons
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
283 (format "Wrong arguments of %s.NameOwnerChanged" dbus-interface-dbus)
bb538e56f976 * net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents: 87308
diff changeset
284 args))))))
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
285
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
286 ;; Register the handler.
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
287 (when nil ;ignore-errors
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
288 (dbus-register-signal
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
289 :system dbus-service-dbus dbus-path-dbus dbus-interface-dbus
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
290 "NameOwnerChanged" 'dbus-name-owner-changed-handler)
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
291 (dbus-register-signal
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
292 :session dbus-service-dbus dbus-path-dbus dbus-interface-dbus
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
293 "NameOwnerChanged" 'dbus-name-owner-changed-handler))
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
294
87050
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
295
99951
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
296 ;;; D-Bus type conversion.
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
297
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
298 (defun dbus-string-to-byte-array (string)
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
299 "Transforms STRING to list (:array :byte c1 :byte c2 ...).
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
300 STRING shall be UTF8 coded."
100855
4502d2277f2c * net/dbus.el (dbus-string-to-byte-array): Handle empty array.
Michael Albinus <michael.albinus@gmx.de>
parents: 99968
diff changeset
301 (if (zerop (length string))
4502d2277f2c * net/dbus.el (dbus-string-to-byte-array): Handle empty array.
Michael Albinus <michael.albinus@gmx.de>
parents: 99968
diff changeset
302 '(:array :signature "y")
4502d2277f2c * net/dbus.el (dbus-string-to-byte-array): Handle empty array.
Michael Albinus <michael.albinus@gmx.de>
parents: 99968
diff changeset
303 (let (result)
4502d2277f2c * net/dbus.el (dbus-string-to-byte-array): Handle empty array.
Michael Albinus <michael.albinus@gmx.de>
parents: 99968
diff changeset
304 (dolist (elt (string-to-list string) (append '(:array) result))
4502d2277f2c * net/dbus.el (dbus-string-to-byte-array): Handle empty array.
Michael Albinus <michael.albinus@gmx.de>
parents: 99968
diff changeset
305 (setq result (append result (list :byte elt)))))))
99951
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
306
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
307 (defun dbus-byte-array-to-string (byte-array)
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
308 "Transforms BYTE-ARRAY into UTF8 coded string.
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
309 BYTE-ARRAY must be a list of structure (c1 c2 ...)."
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
310 (apply 'string byte-array))
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
311
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
312 (defun dbus-escape-as-identifier (string)
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
313 "Escape an arbitrary STRING so it follows the rules for a C identifier.
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
314 The escaped string can be used as object path component, interface element
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
315 component, bus name component or member name in D-Bus.
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
316
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
317 The escaping consists of replacing all non-alphanumerics, and the
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
318 first character if it's a digit, with an underscore and two
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
319 lower-case hex digits:
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
320
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
321 \"0123abc_xyz\\x01\\xff\" -> \"_30123abc_5fxyz_01_ff\"
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
322
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
323 i.e. similar to URI encoding, but with \"_\" taking the role of \"%\",
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
324 and a smaller allowed set. As a special case, \"\" is escaped to
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
325 \"_\".
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
326
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
327 Returns the escaped string. Algorithm taken from
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
328 telepathy-glib's `tp-escape-as-identifier'."
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
329 (if (zerop (length string))
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
330 "_"
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
331 (replace-regexp-in-string
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
332 "^[0-9]\\|[^A-Za-z0-9]"
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
333 (lambda (x) (format "_%2x" (aref x 0)))
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
334 string)))
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
335
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
336 (defun dbus-unescape-from-identifier (string)
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
337 "Retrieve the original string from the encoded STRING.
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
338 STRING must have been coded with `dbus-escape-as-identifier'"
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
339 (if (string-equal string "_")
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
340 ""
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
341 (replace-regexp-in-string
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
342 "_.."
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
343 (lambda (x) (format "%c" (string-to-number (substring x 1) 16)))
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
344 string)))
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
345
b265d0564f99 * net/dbus.el (dbus-string-to-byte-array)
Michael Albinus <michael.albinus@gmx.de>
parents: 98668
diff changeset
346
87050
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
347 ;;; D-Bus events.
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
348
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
349 (defun dbus-check-event (event)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
350 "Checks whether EVENT is a well formed D-Bus event.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
351 EVENT is a list which starts with symbol `dbus-event':
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
352
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
353 (dbus-event BUS TYPE SERIAL SERVICE PATH INTERFACE MEMBER HANDLER &rest ARGS)
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
354
87586
9554989ee375 * net/dbus.el (dbus-list-hash-table)
Michael Albinus <michael.albinus@gmx.de>
parents: 87537
diff changeset
355 BUS identifies the D-Bus the message is coming from. It is
109962
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
356 either a Lisp symbol, `:system' or `:session', or a string
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
357 denoting the bus address. TYPE is the D-Bus message type which
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
358 has caused the event, SERIAL is the serial number of the received
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
359 D-Bus message. SERVICE and PATH are the unique name and the
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
360 object path of the D-Bus object emitting the message. INTERFACE
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
361 and MEMBER denote the message which has been sent. HANDLER is
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
362 the function which has been registered for this message. ARGS
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
363 are the arguments passed to HANDLER, when it is called during
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
364 event handling in `dbus-handle-event'.
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
365
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
366 This function raises a `dbus-error' signal in case the event is
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
367 not well formed."
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
368 (when dbus-debug (message "DBus-Event %s" event))
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
369 (unless (and (listp event)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
370 (eq (car event) 'dbus-event)
87050
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
371 ;; Bus symbol.
109962
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
372 (or (symbolp (nth 1 event))
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
373 (stringp (nth 1 event)))
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
374 ;; Type.
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
375 (and (natnump (nth 2 event))
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
376 (< dbus-message-type-invalid (nth 2 event)))
87586
9554989ee375 * net/dbus.el (dbus-list-hash-table)
Michael Albinus <michael.albinus@gmx.de>
parents: 87537
diff changeset
377 ;; Serial.
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
378 (natnump (nth 3 event))
87050
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
379 ;; Service.
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
380 (or (= dbus-message-type-method-return (nth 2 event))
97213
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
381 (= dbus-message-type-error (nth 2 event))
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
382 (stringp (nth 4 event)))
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
383 ;; Object path.
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
384 (or (= dbus-message-type-method-return (nth 2 event))
97213
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
385 (= dbus-message-type-error (nth 2 event))
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
386 (stringp (nth 5 event)))
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
387 ;; Interface.
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
388 (or (= dbus-message-type-method-return (nth 2 event))
97213
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
389 (= dbus-message-type-error (nth 2 event))
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
390 (stringp (nth 6 event)))
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
391 ;; Member.
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
392 (or (= dbus-message-type-method-return (nth 2 event))
97213
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
393 (= dbus-message-type-error (nth 2 event))
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
394 (stringp (nth 7 event)))
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
395 ;; Handler.
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
396 (functionp (nth 8 event)))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
397 (signal 'dbus-error (list "Not a valid D-Bus event" event))))
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
398
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
399 ;;;###autoload
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
400 (defun dbus-handle-event (event)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
401 "Handle events from the D-Bus.
87050
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
402 EVENT is a D-Bus event, see `dbus-check-event'. HANDLER, being
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
403 part of the event, is called with arguments ARGS.
108938
319b48a599cf * net/dbus.el: Fix typos and declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 107255
diff changeset
404 If the HANDLER returns a `dbus-error', it is propagated as return message."
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
405 (interactive "e")
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
406 (condition-case err
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
407 (let (result)
97213
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
408 ;; We ignore not well-formed events.
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
409 (dbus-check-event event)
97213
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
410 ;; Error messages must be propagated.
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
411 (when (= dbus-message-type-error (nth 2 event))
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
412 (signal 'dbus-error (nthcdr 9 event)))
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
413 ;; Apply the handler.
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
414 (setq result (apply (nth 8 event) (nthcdr 9 event)))
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
415 ;; Return a message when it is a message call.
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
416 (when (= dbus-message-type-method-call (nth 2 event))
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
417 (dbus-ignore-errors
104081
4c431a52ce37 * net/dbus.el (dbus-call-method-non-blocking): Handle the case the
Michael Albinus <michael.albinus@gmx.de>
parents: 101619
diff changeset
418 (if (eq result :ignore)
4c431a52ce37 * net/dbus.el (dbus-call-method-non-blocking): Handle the case the
Michael Albinus <michael.albinus@gmx.de>
parents: 101619
diff changeset
419 (dbus-method-return-internal
4c431a52ce37 * net/dbus.el (dbus-call-method-non-blocking): Handle the case the
Michael Albinus <michael.albinus@gmx.de>
parents: 101619
diff changeset
420 (nth 1 event) (nth 3 event) (nth 4 event))
4c431a52ce37 * net/dbus.el (dbus-call-method-non-blocking): Handle the case the
Michael Albinus <michael.albinus@gmx.de>
parents: 101619
diff changeset
421 (apply 'dbus-method-return-internal
4c431a52ce37 * net/dbus.el (dbus-call-method-non-blocking): Handle the case the
Michael Albinus <michael.albinus@gmx.de>
parents: 101619
diff changeset
422 (nth 1 event) (nth 3 event) (nth 4 event)
4c431a52ce37 * net/dbus.el (dbus-call-method-non-blocking): Handle the case the
Michael Albinus <michael.albinus@gmx.de>
parents: 101619
diff changeset
423 (if (consp result) result (list result)))))))
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
424 ;; Error handling.
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
425 (dbus-error
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
426 ;; Return an error message when it is a message call.
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
427 (when (= dbus-message-type-method-call (nth 2 event))
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
428 (dbus-ignore-errors
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
429 (dbus-method-error-internal
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
430 (nth 1 event) (nth 3 event) (nth 4 event) (cadr err))))
97213
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
431 ;; Propagate D-Bus error messages.
101619
df3f6041e002 * net/dbus.el (dbus-event-error-hooks): Fix docstring. Describe
Michael Albinus <michael.albinus@gmx.de>
parents: 101525
diff changeset
432 (run-hook-with-args 'dbus-event-error-hooks event err)
97213
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
433 (when (or dbus-debug (= dbus-message-type-error (nth 2 event)))
f7035abd999b * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus
Michael Albinus <michael.albinus@gmx.de>
parents: 97167
diff changeset
434 (signal (car err) (cdr err))))))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
435
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
436 (defun dbus-event-bus-name (event)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
437 "Return the bus name the event is coming from.
109962
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
438 The result is either a Lisp symbol, `:system' or `:session', or a
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
439 string denoting the bus address. EVENT is a D-Bus event, see
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
440 `dbus-check-event'. This function raises a `dbus-error' signal
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
441 in case the event is not well formed."
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
442 (dbus-check-event event)
87159
bcf59f3d73d7 * net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents: 87093
diff changeset
443 (nth 1 event))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
444
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
445 (defun dbus-event-message-type (event)
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
446 "Return the message type of the corresponding D-Bus message.
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
447 The result is a number. EVENT is a D-Bus event, see
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
448 `dbus-check-event'. This function raises a `dbus-error' signal
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
449 in case the event is not well formed."
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
450 (dbus-check-event event)
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
451 (nth 2 event))
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
452
87586
9554989ee375 * net/dbus.el (dbus-list-hash-table)
Michael Albinus <michael.albinus@gmx.de>
parents: 87537
diff changeset
453 (defun dbus-event-serial-number (event)
9554989ee375 * net/dbus.el (dbus-list-hash-table)
Michael Albinus <michael.albinus@gmx.de>
parents: 87537
diff changeset
454 "Return the serial number of the corresponding D-Bus message.
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
455 The result is a number. The serial number is needed for
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
456 generating a reply message. EVENT is a D-Bus event, see
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
457 `dbus-check-event'. This function raises a `dbus-error' signal
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
458 in case the event is not well formed."
87586
9554989ee375 * net/dbus.el (dbus-list-hash-table)
Michael Albinus <michael.albinus@gmx.de>
parents: 87537
diff changeset
459 (dbus-check-event event)
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
460 (nth 3 event))
87586
9554989ee375 * net/dbus.el (dbus-list-hash-table)
Michael Albinus <michael.albinus@gmx.de>
parents: 87537
diff changeset
461
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
462 (defun dbus-event-service-name (event)
87050
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
463 "Return the name of the D-Bus object the event is coming from.
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
464 The result is a string. EVENT is a D-Bus event, see `dbus-check-event'.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
465 This function raises a `dbus-error' signal in case the event is
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
466 not well formed."
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
467 (dbus-check-event event)
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
468 (nth 4 event))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
469
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
470 (defun dbus-event-path-name (event)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
471 "Return the object path of the D-Bus object the event is coming from.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
472 The result is a string. EVENT is a D-Bus event, see `dbus-check-event'.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
473 This function raises a `dbus-error' signal in case the event is
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
474 not well formed."
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
475 (dbus-check-event event)
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
476 (nth 5 event))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
477
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
478 (defun dbus-event-interface-name (event)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
479 "Return the interface name of the D-Bus object the event is coming from.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
480 The result is a string. EVENT is a D-Bus event, see `dbus-check-event'.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
481 This function raises a `dbus-error' signal in case the event is
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
482 not well formed."
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
483 (dbus-check-event event)
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
484 (nth 6 event))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
485
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
486 (defun dbus-event-member-name (event)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
487 "Return the member name the event is coming from.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
488 It is either a signal name or a method name. The result is is a
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
489 string. EVENT is a D-Bus event, see `dbus-check-event'. This
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
490 function raises a `dbus-error' signal in case the event is not
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
491 well formed."
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
492 (dbus-check-event event)
97167
125ed717ddbb * net/dbus.el (top): Don't register for "NameOwnerChanged".
Michael Albinus <michael.albinus@gmx.de>
parents: 96801
diff changeset
493 (nth 7 event))
87050
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
494
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
495
7d80e0f3d8f8 * net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 86941
diff changeset
496 ;;; D-Bus registered names.
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
497
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
498 (defun dbus-list-activatable-names ()
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
499 "Return the D-Bus service names which can be activated as list.
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
500 The result is a list of strings, which is `nil' when there are no
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
501 activatable service names at all."
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
502 (dbus-ignore-errors
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
503 (dbus-call-method
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
504 :system dbus-service-dbus
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
505 dbus-path-dbus dbus-interface-dbus "ListActivatableNames")))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
506
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
507 (defun dbus-list-names (bus)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
508 "Return the service names registered at D-Bus BUS.
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
509 The result is a list of strings, which is `nil' when there are no
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
510 registered service names at all. Well known names are strings
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
511 like \"org.freedesktop.DBus\". Names starting with \":\" are
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
512 unique names for services."
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
513 (dbus-ignore-errors
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
514 (dbus-call-method
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
515 bus dbus-service-dbus dbus-path-dbus dbus-interface-dbus "ListNames")))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
516
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
517 (defun dbus-list-known-names (bus)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
518 "Retrieve all services which correspond to a known name in BUS.
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
519 A service has a known name if it doesn't start with \":\"."
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
520 (let (result)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
521 (dolist (name (dbus-list-names bus) result)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
522 (unless (string-equal ":" (substring name 0 1))
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
523 (add-to-list 'result name 'append)))))
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
524
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
525 (defun dbus-list-queued-owners (bus service)
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
526 "Return the unique names registered at D-Bus BUS and queued for SERVICE.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
527 The result is a list of strings, or `nil' when there are no
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
528 queued name owners service names at all."
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
529 (dbus-ignore-errors
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
530 (dbus-call-method
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
531 bus dbus-service-dbus dbus-path-dbus
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
532 dbus-interface-dbus "ListQueuedOwners" service)))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
533
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
534 (defun dbus-get-name-owner (bus service)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
535 "Return the name owner of SERVICE registered at D-Bus BUS.
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
536 The result is either a string, or `nil' if there is no name owner."
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
537 (dbus-ignore-errors
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
538 (dbus-call-method
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
539 bus dbus-service-dbus dbus-path-dbus
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
540 dbus-interface-dbus "GetNameOwner" service)))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
541
104602
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
542 (defun dbus-ping (bus service &optional timeout)
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
543 "Check whether SERVICE is registered for D-Bus BUS.
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
544 TIMEOUT, a nonnegative integer, specifies the maximum number of
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
545 milliseconds `dbus-ping' must return. The default value is 25,000.
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
546
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
547 Note, that this autoloads SERVICE if it is not running yet. If
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
548 it shall be checked whether SERVICE is already running, one shall
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
549 apply
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
550
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
551 \(member service \(dbus-list-known-names bus))"
91588
83afe69ce25e * net/dbus.el (dbus-interface-peer): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 91484
diff changeset
552 ;; "Ping" raises a D-Bus error if SERVICE does not exist.
91589
12b2f1526656 * net/dbus.el (dbus-interface-peer): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 91588
diff changeset
553 ;; Otherwise, it returns silently with `nil'.
91588
83afe69ce25e * net/dbus.el (dbus-interface-peer): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 91484
diff changeset
554 (condition-case nil
91589
12b2f1526656 * net/dbus.el (dbus-interface-peer): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 91588
diff changeset
555 (not
104602
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
556 (if (natnump timeout)
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
557 (dbus-call-method
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
558 bus service dbus-path-dbus dbus-interface-peer
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
559 "Ping" :timeout timeout)
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
560 (dbus-call-method
d74b934b16e5 * net/dbus.el (dbus-ping): Add optional parameter TIMEOUT.
Michael Albinus <michael.albinus@gmx.de>
parents: 104382
diff changeset
561 bus service dbus-path-dbus dbus-interface-peer "Ping")))
91588
83afe69ce25e * net/dbus.el (dbus-interface-peer): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 91484
diff changeset
562 (dbus-error nil)))
83afe69ce25e * net/dbus.el (dbus-interface-peer): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 91484
diff changeset
563
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
564
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
565 ;;; D-Bus introspection.
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
566
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
567 (defun dbus-introspect (bus service path)
108938
319b48a599cf * net/dbus.el: Fix typos and declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 107255
diff changeset
568 "Return all interfaces and sub-nodes of SERVICE,
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
569 registered at object path PATH at bus BUS.
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
570
109962
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
571 BUS is either a Lisp symbol, `:system' or `:session', or a string
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
572 denoting the bus address. SERVICE must be a known service name,
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
573 and PATH must be a valid object path. The last two parameters
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
574 are strings. The result, the introspection data, is a string in
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
575 XML format."
97692
2a8cbdcbe61d * net/dbus.el (dbus-introspect): Use `dbus-call-method-non-blocking'.
Michael Albinus <michael.albinus@gmx.de>
parents: 97261
diff changeset
576 ;; We don't want to raise errors. `dbus-call-method-non-blocking'
2a8cbdcbe61d * net/dbus.el (dbus-introspect): Use `dbus-call-method-non-blocking'.
Michael Albinus <michael.albinus@gmx.de>
parents: 97261
diff changeset
577 ;; is used, because the handler can be registered in our Emacs
2a8cbdcbe61d * net/dbus.el (dbus-introspect): Use `dbus-call-method-non-blocking'.
Michael Albinus <michael.albinus@gmx.de>
parents: 97261
diff changeset
578 ;; instance; caller an callee would block each other.
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
579 (dbus-ignore-errors
107255
6ea11661a516 * net/dbus.el (dbus-introspect, dbus-get-property)
Michael Albinus <albinus@detlef>
parents: 106815
diff changeset
580 (funcall
6ea11661a516 * net/dbus.el (dbus-introspect, dbus-get-property)
Michael Albinus <albinus@detlef>
parents: 106815
diff changeset
581 (if noninteractive 'dbus-call-method 'dbus-call-method-non-blocking)
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
582 bus service path dbus-interface-introspectable "Introspect")))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
583
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
584 (defun dbus-introspect-xml (bus service path)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
585 "Return the introspection data of SERVICE in D-Bus BUS at object path PATH.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
586 The data are a parsed list. The root object is a \"node\",
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
587 representing the object path PATH. The root object can contain
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
588 \"interface\" and further \"node\" objects."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
589 ;; We don't want to raise errors.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
590 (xml-node-name
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
591 (ignore-errors
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
592 (with-temp-buffer
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
593 (insert (dbus-introspect bus service path))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
594 (xml-parse-region (point-min) (point-max))))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
595
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
596 (defun dbus-introspect-get-attribute (object attribute)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
597 "Return the ATTRIBUTE value of D-Bus introspection OBJECT.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
598 ATTRIBUTE must be a string according to the attribute names in
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
599 the D-Bus specification."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
600 (xml-get-attribute-or-nil object (intern attribute)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
601
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
602 (defun dbus-introspect-get-node-names (bus service path)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
603 "Return all node names of SERVICE in D-Bus BUS at object path PATH.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
604 It returns a list of strings. The node names stand for further
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
605 object paths of the D-Bus service."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
606 (let ((object (dbus-introspect-xml bus service path))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
607 result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
608 (dolist (elt (xml-get-children object 'node) result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
609 (add-to-list
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
610 'result (dbus-introspect-get-attribute elt "name") 'append))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
611
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
612 (defun dbus-introspect-get-all-nodes (bus service path)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
613 "Return all node names of SERVICE in D-Bus BUS at object path PATH.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
614 It returns a list of strings, which are further object paths of SERVICE."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
615 (let ((result (list path)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
616 (dolist (elt
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
617 (dbus-introspect-get-node-names bus service path)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
618 result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
619 (setq elt (expand-file-name elt path))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
620 (setq result
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
621 (append result (dbus-introspect-get-all-nodes bus service elt))))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
622
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
623 (defun dbus-introspect-get-interface-names (bus service path)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
624 "Return all interface names of SERVICE in D-Bus BUS at object path PATH.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
625 It returns a list of strings.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
626
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
627 There will be always the default interface
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
628 \"org.freedesktop.DBus.Introspectable\". Another default
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
629 interface is \"org.freedesktop.DBus.Properties\". If present,
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
630 \"interface\" objects can also have \"property\" objects as
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
631 children, beside \"method\" and \"signal\" objects."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
632 (let ((object (dbus-introspect-xml bus service path))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
633 result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
634 (dolist (elt (xml-get-children object 'interface) result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
635 (add-to-list
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
636 'result (dbus-introspect-get-attribute elt "name") 'append))))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
637
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
638 (defun dbus-introspect-get-interface (bus service path interface)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
639 "Return the INTERFACE of SERVICE in D-Bus BUS at object path PATH.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
640 The return value is an XML object. INTERFACE must be a string,
108938
319b48a599cf * net/dbus.el: Fix typos and declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 107255
diff changeset
641 element of the list returned by `dbus-introspect-get-interface-names'.
319b48a599cf * net/dbus.el: Fix typos and declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 107255
diff changeset
642 The resulting \"interface\" object can contain \"method\", \"signal\",
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
643 \"property\" and \"annotation\" children."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
644 (let ((elt (xml-get-children
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
645 (dbus-introspect-xml bus service path) 'interface)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
646 (while (and elt
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
647 (not (string-equal
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
648 interface
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
649 (dbus-introspect-get-attribute (car elt) "name"))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
650 (setq elt (cdr elt)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
651 (car elt)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
652
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
653 (defun dbus-introspect-get-method-names (bus service path interface)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
654 "Return a list of strings of all method names of INTERFACE.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
655 SERVICE is a service of D-Bus BUS at object path PATH."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
656 (let ((object (dbus-introspect-get-interface bus service path interface))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
657 result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
658 (dolist (elt (xml-get-children object 'method) result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
659 (add-to-list
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
660 'result (dbus-introspect-get-attribute elt "name") 'append))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
661
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
662 (defun dbus-introspect-get-method (bus service path interface method)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
663 "Return method METHOD of interface INTERFACE as XML object.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
664 It must be located at SERVICE in D-Bus BUS at object path PATH.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
665 METHOD must be a string, element of the list returned by
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
666 `dbus-introspect-get-method-names'. The resulting \"method\"
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
667 object can contain \"arg\" and \"annotation\" children."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
668 (let ((elt (xml-get-children
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
669 (dbus-introspect-get-interface bus service path interface)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
670 'method)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
671 (while (and elt
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
672 (not (string-equal
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
673 method (dbus-introspect-get-attribute (car elt) "name"))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
674 (setq elt (cdr elt)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
675 (car elt)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
676
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
677 (defun dbus-introspect-get-signal-names (bus service path interface)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
678 "Return a list of strings of all signal names of INTERFACE.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
679 SERVICE is a service of D-Bus BUS at object path PATH."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
680 (let ((object (dbus-introspect-get-interface bus service path interface))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
681 result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
682 (dolist (elt (xml-get-children object 'signal) result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
683 (add-to-list
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
684 'result (dbus-introspect-get-attribute elt "name") 'append))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
685
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
686 (defun dbus-introspect-get-signal (bus service path interface signal)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
687 "Return signal SIGNAL of interface INTERFACE as XML object.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
688 It must be located at SERVICE in D-Bus BUS at object path PATH.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
689 SIGNAL must be a string, element of the list returned by
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
690 `dbus-introspect-get-signal-names'. The resulting \"signal\"
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
691 object can contain \"arg\" and \"annotation\" children."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
692 (let ((elt (xml-get-children
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
693 (dbus-introspect-get-interface bus service path interface)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
694 'signal)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
695 (while (and elt
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
696 (not (string-equal
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
697 signal (dbus-introspect-get-attribute (car elt) "name"))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
698 (setq elt (cdr elt)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
699 (car elt)))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
700
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
701 (defun dbus-introspect-get-property-names (bus service path interface)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
702 "Return a list of strings of all property names of INTERFACE.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
703 SERVICE is a service of D-Bus BUS at object path PATH."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
704 (let ((object (dbus-introspect-get-interface bus service path interface))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
705 result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
706 (dolist (elt (xml-get-children object 'property) result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
707 (add-to-list
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
708 'result (dbus-introspect-get-attribute elt "name") 'append))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
709
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
710 (defun dbus-introspect-get-property (bus service path interface property)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
711 "This function returns PROPERTY of INTERFACE as XML object.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
712 It must be located at SERVICE in D-Bus BUS at object path PATH.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
713 PROPERTY must be a string, element of the list returned by
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
714 `dbus-introspect-get-property-names'. The resulting PROPERTY
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
715 object can contain \"annotation\" children."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
716 (let ((elt (xml-get-children
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
717 (dbus-introspect-get-interface bus service path interface)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
718 'property)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
719 (while (and elt
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
720 (not (string-equal
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
721 property
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
722 (dbus-introspect-get-attribute (car elt) "name"))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
723 (setq elt (cdr elt)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
724 (car elt)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
725
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
726 (defun dbus-introspect-get-annotation-names
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
727 (bus service path interface &optional name)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
728 "Return all annotation names as list of strings.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
729 If NAME is `nil', the annotations are children of INTERFACE,
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
730 otherwise NAME must be a \"method\", \"signal\", or \"property\"
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
731 object, where the annotations belong to."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
732 (let ((object
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
733 (if name
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
734 (or (dbus-introspect-get-method bus service path interface name)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
735 (dbus-introspect-get-signal bus service path interface name)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
736 (dbus-introspect-get-property bus service path interface name))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
737 (dbus-introspect-get-interface bus service path interface)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
738 result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
739 (dolist (elt (xml-get-children object 'annotation) result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
740 (add-to-list
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
741 'result (dbus-introspect-get-attribute elt "name") 'append))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
742
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
743 (defun dbus-introspect-get-annotation
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
744 (bus service path interface name annotation)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
745 "Return ANNOTATION as XML object.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
746 If NAME is `nil', ANNOTATION is a child of INTERFACE, otherwise
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
747 NAME must be the name of a \"method\", \"signal\", or
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
748 \"property\" object, where the ANNOTATION belongs to."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
749 (let ((elt (xml-get-children
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
750 (if name
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
751 (or (dbus-introspect-get-method
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
752 bus service path interface name)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
753 (dbus-introspect-get-signal
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
754 bus service path interface name)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
755 (dbus-introspect-get-property
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
756 bus service path interface name))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
757 (dbus-introspect-get-interface bus service path interface))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
758 'annotation)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
759 (while (and elt
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
760 (not (string-equal
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
761 annotation
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
762 (dbus-introspect-get-attribute (car elt) "name"))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
763 (setq elt (cdr elt)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
764 (car elt)))
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
765
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
766 (defun dbus-introspect-get-argument-names (bus service path interface name)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
767 "Return a list of all argument names as list of strings.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
768 NAME must be a \"method\" or \"signal\" object.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
769
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
770 Argument names are optional, the function can return `nil'
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
771 therefore, even if the method or signal has arguments."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
772 (let ((object
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
773 (or (dbus-introspect-get-method bus service path interface name)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
774 (dbus-introspect-get-signal bus service path interface name)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
775 result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
776 (dolist (elt (xml-get-children object 'arg) result)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
777 (add-to-list
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
778 'result (dbus-introspect-get-attribute elt "name") 'append))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
779
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
780 (defun dbus-introspect-get-argument (bus service path interface name arg)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
781 "Return argument ARG as XML object.
108938
319b48a599cf * net/dbus.el: Fix typos and declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 107255
diff changeset
782 NAME must be a \"method\" or \"signal\" object. ARG must be a string,
319b48a599cf * net/dbus.el: Fix typos and declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 107255
diff changeset
783 element of the list returned by `dbus-introspect-get-argument-names'."
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
784 (let ((elt (xml-get-children
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
785 (or (dbus-introspect-get-method bus service path interface name)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
786 (dbus-introspect-get-signal bus service path interface name))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
787 'arg)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
788 (while (and elt
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
789 (not (string-equal
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
790 arg (dbus-introspect-get-attribute (car elt) "name"))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
791 (setq elt (cdr elt)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
792 (car elt)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
793
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
794 (defun dbus-introspect-get-signature
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
795 (bus service path interface name &optional direction)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
796 "Return signature of a `method' or `signal', represented by NAME, as string.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
797 If NAME is a `method', DIRECTION can be either \"in\" or \"out\".
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
798 If DIRECTION is `nil', \"in\" is assumed.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
799
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
800 If NAME is a `signal', and DIRECTION is non-`nil', DIRECTION must
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
801 be \"out\"."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
802 ;; For methods, we use "in" as default direction.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
803 (let ((object (or (dbus-introspect-get-method
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
804 bus service path interface name)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
805 (dbus-introspect-get-signal
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
806 bus service path interface name))))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
807 (when (and (string-equal
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
808 "method" (dbus-introspect-get-attribute object "name"))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
809 (not (stringp direction)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
810 (setq direction "in"))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
811 ;; In signals, no direction is given.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
812 (when (string-equal "signal" (dbus-introspect-get-attribute object "name"))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
813 (setq direction nil))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
814 ;; Collect the signatures.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
815 (mapconcat
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
816 '(lambda (x)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
817 (let ((arg (dbus-introspect-get-argument
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
818 bus service path interface name x)))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
819 (if (or (not (stringp direction))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
820 (string-equal
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
821 direction
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
822 (dbus-introspect-get-attribute arg "direction")))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
823 (dbus-introspect-get-attribute arg "type")
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
824 "")))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
825 (dbus-introspect-get-argument-names bus service path interface name)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
826 "")))
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
827
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
828
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
829 ;;; D-Bus properties.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
830
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
831 (defun dbus-get-property (bus service path interface property)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
832 "Return the value of PROPERTY of INTERFACE.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
833 It will be checked at BUS, SERVICE, PATH. The result can be any
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
834 valid D-Bus value, or `nil' if there is no PROPERTY."
87885
b560a1744534 * net/dbus.el (dbus-ignore-errors): New macro.
Michael Albinus <michael.albinus@gmx.de>
parents: 87586
diff changeset
835 (dbus-ignore-errors
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
836 ;; "Get" returns a variant, so we must use the `car'.
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
837 (car
107255
6ea11661a516 * net/dbus.el (dbus-introspect, dbus-get-property)
Michael Albinus <albinus@detlef>
parents: 106815
diff changeset
838 (funcall
6ea11661a516 * net/dbus.el (dbus-introspect, dbus-get-property)
Michael Albinus <albinus@detlef>
parents: 106815
diff changeset
839 (if noninteractive 'dbus-call-method 'dbus-call-method-non-blocking)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
840 bus service path dbus-interface-properties
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
841 "Get" :timeout 500 interface property))))
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
842
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
843 (defun dbus-set-property (bus service path interface property value)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
844 "Set value of PROPERTY of INTERFACE to VALUE.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
845 It will be checked at BUS, SERVICE, PATH. When the value has
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
846 been set successful, the result is VALUE. Otherwise, `nil' is
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
847 returned."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
848 (dbus-ignore-errors
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
849 ;; "Set" requires a variant.
107255
6ea11661a516 * net/dbus.el (dbus-introspect, dbus-get-property)
Michael Albinus <albinus@detlef>
parents: 106815
diff changeset
850 (funcall
6ea11661a516 * net/dbus.el (dbus-introspect, dbus-get-property)
Michael Albinus <albinus@detlef>
parents: 106815
diff changeset
851 (if noninteractive 'dbus-call-method 'dbus-call-method-non-blocking)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
852 bus service path dbus-interface-properties
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
853 "Set" :timeout 500 interface property (list :variant value))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
854 ;; Return VALUE.
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
855 (dbus-get-property bus service path interface property)))
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
856
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
857 (defun dbus-get-all-properties (bus service path interface)
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
858 "Return all properties of INTERFACE at BUS, SERVICE, PATH.
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
859 The result is a list of entries. Every entry is a cons of the
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
860 name of the property, and its value. If there are no properties,
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
861 `nil' is returned."
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
862 (dbus-ignore-errors
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
863 ;; "GetAll" returns "a{sv}".
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
864 (let (result)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
865 (dolist (dict
107255
6ea11661a516 * net/dbus.el (dbus-introspect, dbus-get-property)
Michael Albinus <albinus@detlef>
parents: 106815
diff changeset
866 (funcall
6ea11661a516 * net/dbus.el (dbus-introspect, dbus-get-property)
Michael Albinus <albinus@detlef>
parents: 106815
diff changeset
867 (if noninteractive
6ea11661a516 * net/dbus.el (dbus-introspect, dbus-get-property)
Michael Albinus <albinus@detlef>
parents: 106815
diff changeset
868 'dbus-call-method
6ea11661a516 * net/dbus.el (dbus-introspect, dbus-get-property)
Michael Albinus <albinus@detlef>
parents: 106815
diff changeset
869 'dbus-call-method-non-blocking)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
870 bus service path dbus-interface-properties
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
871 "GetAll" :timeout 500 interface)
96801
282e0881421e * net/dbus.el (dbus-interface-properties): New defconst.
Michael Albinus <michael.albinus@gmx.de>
parents: 94677
diff changeset
872 result)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
873 (add-to-list 'result (cons (car dict) (caadr dict)) 'append)))))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
874
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
875 (defun dbus-register-property
112112
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
876 (bus service path interface property access value
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
877 &optional emits-signal dont-register-service)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
878 "Register property PROPERTY on the D-Bus BUS.
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
879
109962
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
880 BUS is either a Lisp symbol, `:system' or `:session', or a string
aa3e4f636621 * net/dbus.el: Accept UNIX domain sockets as bus address.
Michael Albinus <michael.albinus@gmx.de>
parents: 109132
diff changeset
881 denoting the bus address.
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
882
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
883 SERVICE is the D-Bus service name of the D-Bus. It must be a
112112
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
884 known name (See discussion of DONT-REGISTER-SERVICE below).
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
885
112112
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
886 PATH is the D-Bus object path SERVICE is registered (See
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
887 discussion of DONT-REGISTER-SERVICE below). INTERFACE is the
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
888 name of the interface used at PATH, PROPERTY is the name of the
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
889 property of INTERFACE. ACCESS indicates, whether the property
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
890 can be changed by other services via D-Bus. It must be either
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
891 the symbol `:read' or `:readwrite'. VALUE is the initial value
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
892 of the property, it can be of any valid type (see
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
893 `dbus-call-method' for details).
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
894
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
895 If PROPERTY already exists on PATH, it will be overwritten. For
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
896 properties with access type `:read' this is the only way to
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
897 change their values. Properties with access type `:readwrite'
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
898 can be changed by `dbus-set-property'.
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
899
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
900 The interface \"org.freedesktop.DBus.Properties\" is added to
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
901 PATH, including a default handler for the \"Get\", \"GetAll\" and
109127
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
902 \"Set\" methods of this interface. When EMITS-SIGNAL is non-nil,
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
903 the signal \"PropertiesChanged\" is sent when the property is
112112
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
904 changed by `dbus-set-property'.
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
905
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
906 When DONT-REGISTER-SERVICE is non-nil, the known name SERVICE is
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
907 not registered. This means that other D-Bus clients have no way
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
908 of noticing the newly registered property. When interfaces are
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
909 constructed incrementally by adding single methods or properties
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
910 at a time, DONT-REGISTER-SERVICE can be used to prevent other
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
911 clients from discovering the still incomplete interface."
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
912 (unless (member access '(:read :readwrite))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
913 (signal 'dbus-error (list "Access type invalid" access)))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
914
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
915 ;; Register SERVICE.
112112
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
916 (unless (or dont-register-service
318b7249ccd0 * net/dbus.el (dbus-register-property): Added optional parameter
Michael Albinus <michael.albinus@gmx.de>
parents: 111333
diff changeset
917 (member service (dbus-list-names bus)))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
918 (dbus-call-method
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
919 bus dbus-service-dbus dbus-path-dbus dbus-interface-dbus
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
920 "RequestName" service 0))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
921
112181
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
922 ;; Add handlers for the three property-related methods.
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
923 (dbus-register-method
112181
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
924 bus service path dbus-interface-properties "Get"
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
925 'dbus-property-handler t)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
926 (dbus-register-method
112181
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
927 bus service path dbus-interface-properties "GetAll"
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
928 'dbus-property-handler t)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
929 (dbus-register-method
112181
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
930 bus service path dbus-interface-properties "Set"
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
931 'dbus-property-handler t)
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
932
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
933 ;; Register the name SERVICE with BUS.
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
934 (unless dont-register-service
af71852e09a2 * net/dbus.el (dbus-unregister-service): Translate returned
Michael Albinus <michael.albinus@gmx.de>
parents: 112112
diff changeset
935 (dbus-register-service bus service))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
936
109127
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
937 ;; Send the PropertiesChanged signal.
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
938 (when emits-signal
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
939 (dbus-send-signal
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
940 bus service path dbus-interface-properties "PropertiesChanged"
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
941 (list (list :dict-entry property (list :variant value)))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
942 '(:array)))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
943
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
944 ;; Create a hash table entry. We use nil for the unique name,
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
945 ;; because the property might be accessed from anybody.
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
946 (let ((key (list bus interface property))
109127
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
947 (val
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
948 (list
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
949 (list
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
950 nil service path
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
951 (cons
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
952 (if emits-signal (list access :emits-signal) (list access))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
953 value)))))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
954 (puthash key val dbus-registered-objects-table)
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
955
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
956 ;; Return the object.
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
957 (list key (list service path))))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
958
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
959 (defun dbus-property-handler (&rest args)
108938
319b48a599cf * net/dbus.el: Fix typos and declare function.
Juanma Barranquero <lekktu@gmail.com>
parents: 107255
diff changeset
960 "Default handler for the \"org.freedesktop.DBus.Properties\" interface.
106050
533b0628d222 * net/dbus.el (dbus-unregister-service): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents: 105987
diff changeset
961 It will be registered for all objects created by `dbus-register-object'."
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
962 (let ((bus (dbus-event-bus-name last-input-event))
109127
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
963 (service (dbus-event-service-name last-input-event))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
964 (path (dbus-event-path-name last-input-event))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
965 (method (dbus-event-member-name last-input-event))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
966 (interface (car args))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
967 (property (cadr args)))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
968 (cond
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
969 ;; "Get" returns a variant.
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
970 ((string-equal method "Get")
109127
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
971 (let ((entry (gethash (list bus interface property)
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
972 dbus-registered-objects-table)))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
973 (when (string-equal path (nth 2 (car entry)))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
974 (list (list :variant (cdar (last (car entry))))))))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
975
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
976 ;; "Set" expects a variant.
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
977 ((string-equal method "Set")
109127
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
978 (let* ((value (caar (cddr args)))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
979 (entry (gethash (list bus interface property)
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
980 dbus-registered-objects-table))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
981 ;; The value of the hash table is a list; in case of
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
982 ;; properties it contains just one element (UNAME SERVICE
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
983 ;; PATH OBJECT). OBJECT is a cons cell of a list, which
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
984 ;; contains a list of annotations (like :read,
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
985 ;; :read-write, :emits-signal), and the value of the
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
986 ;; property.
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
987 (object (car (last (car entry)))))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
988 (unless (consp object)
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
989 (signal 'dbus-error
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
990 (list "Property not registered at path" property path)))
109127
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
991 (unless (member :readwrite (car object))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
992 (signal 'dbus-error
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
993 (list "Property not writable at path" property path)))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
994 (puthash (list bus interface property)
109127
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
995 (list (append (butlast (car entry))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
996 (list (cons (car object) value))))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
997 dbus-registered-objects-table)
109127
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
998 ;; Send the "PropertiesChanged" signal.
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
999 (when (member :emits-signal (car object))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
1000 (dbus-send-signal
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
1001 bus service path dbus-interface-properties "PropertiesChanged"
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
1002 (list (list :dict-entry property (list :variant value)))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
1003 '(:array)))
6b757d9cacac * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
Michael Albinus <albinus@detlef>
parents: 108938
diff changeset
1004 ;; Return empty reply.
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1005 :ignore))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1006
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1007 ;; "GetAll" returns "a{sv}".
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1008 ((string-equal method "GetAll")
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1009 (let (result)
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1010 (maphash
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1011 (lambda (key val)
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1012 (when (and (equal (butlast key) (list bus interface))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1013 (string-equal path (nth 2 (car val)))
106555
98a65639e9cf * net/dbus.el (dbus-property-handler): Filter lambda forms out
Michael Albinus <michael.albinus@gmx.de>
parents: 106050
diff changeset
1014 (not (functionp (car (last (car val))))))
105987
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1015 (add-to-list
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1016 'result
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1017 (list :dict-entry
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1018 (car (last key))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1019 (list :variant (cdar (last (car val))))))))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1020 dbus-registered-objects-table)
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1021 (list result))))))
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1022
57d249deafab * net/dbus.el (dbus-registered-objects-table): Renamed from
Michael Albinus <michael.albinus@gmx.de>
parents: 105928
diff changeset
1023
104355
7d92d0b5edc6 * net/dbus.el (top): Apply `dbus-init-bus' for the :session bus
Michael Albinus <michael.albinus@gmx.de>
parents: 104337
diff changeset
1024 ;; Initialize :system and :session buses. This adds their file
7d92d0b5edc6 * net/dbus.el (top): Apply `dbus-init-bus' for the :session bus
Michael Albinus <michael.albinus@gmx.de>
parents: 104337
diff changeset
1025 ;; descriptors to input_wait_mask, in order to detect incoming
7d92d0b5edc6 * net/dbus.el (top): Apply `dbus-init-bus' for the :session bus
Michael Albinus <michael.albinus@gmx.de>
parents: 104337
diff changeset
1026 ;; messages immediately.
104382
20810cc73f89 * net/dbus.el (top): Initialize only when `dbusbind' is loaded.
Michael Albinus <michael.albinus@gmx.de>
parents: 104377
diff changeset
1027 (when (featurep 'dbusbind)
20810cc73f89 * net/dbus.el (top): Initialize only when `dbusbind' is loaded.
Michael Albinus <michael.albinus@gmx.de>
parents: 104377
diff changeset
1028 (dbus-ignore-errors
20810cc73f89 * net/dbus.el (top): Initialize only when `dbusbind' is loaded.
Michael Albinus <michael.albinus@gmx.de>
parents: 104377
diff changeset
1029 (dbus-init-bus :system)
20810cc73f89 * net/dbus.el (top): Initialize only when `dbusbind' is loaded.
Michael Albinus <michael.albinus@gmx.de>
parents: 104377
diff changeset
1030 (dbus-init-bus :session)))
104355
7d92d0b5edc6 * net/dbus.el (top): Apply `dbus-init-bus' for the :session bus
Michael Albinus <michael.albinus@gmx.de>
parents: 104337
diff changeset
1031
86941
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
1032 (provide 'dbus)
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
1033
cbc23e728425 * net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff changeset
1034 ;;; dbus.el ends here