Mercurial > emacs
annotate lisp/net/dbus.el @ 87537:84ece2f8e012
* net/dbus.el (dbus-name-owner-changed-handler): Use
dbus-unregister-object instead of dbus-unregister-signal.
author | Magnus Henoch <mange@freemail.hu> |
---|---|
date | Thu, 03 Jan 2008 16:37:32 +0000 |
parents | bb538e56f976 |
children | 9554989ee375 |
rev | line source |
---|---|
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
1 ;;; -*- no-byte-compile: t; -*- |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
2 ;;; dbus.el --- Elisp bindings for D-Bus. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
3 |
87537
84ece2f8e012
* net/dbus.el (dbus-name-owner-changed-handler): Use
Magnus Henoch <mange@freemail.hu>
parents:
87492
diff
changeset
|
4 ;; Copyright (C) 2007, 2008 Free Software Foundation, Inc. |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
5 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
6 ;; Author: Michael Albinus <michael.albinus@gmx.de> |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
7 ;; Keywords: comm, hardware |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
8 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
10 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
14 ;; any later version. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
15 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
16 ;; 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
|
17 ;; 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
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
20 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, see |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
23 ;; <http://www.gnu.org/licenses/>. |
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 ;;; Commentary: |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
26 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
27 ;; 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
|
28 ;; 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
|
29 ;; one another. See <http://dbus.freedesktop.org/> for details. |
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 ;; 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
|
32 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
33 ;;; Code: |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
34 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
35 (require 'xml) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
36 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
37 (defconst dbus-service-dbus "org.freedesktop.DBus" |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
38 "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
|
39 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
40 (defconst dbus-path-dbus "/org/freedesktop/DBus" |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
41 "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
|
42 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
43 (defconst dbus-interface-dbus "org.freedesktop.DBus" |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
44 "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
|
45 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
46 (defconst dbus-interface-introspectable "org.freedesktop.DBus.Introspectable" |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
47 "The interface supported by introspectable objects.") |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
48 |
87050
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
49 |
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
50 ;;; Hash table of registered functions. |
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
51 |
87176
d5feab53f4f8
* net/dbus.el (dbus-hash-table=): Remove function. We cannot
Michael Albinus <michael.albinus@gmx.de>
parents:
87159
diff
changeset
|
52 ;; We create it here. So we have a simple test in dbusbind.c, whether |
d5feab53f4f8
* net/dbus.el (dbus-hash-table=): Remove function. We cannot
Michael Albinus <michael.albinus@gmx.de>
parents:
87159
diff
changeset
|
53 ;; the Lisp code has been loaded. |
d5feab53f4f8
* net/dbus.el (dbus-hash-table=): Remove function. We cannot
Michael Albinus <michael.albinus@gmx.de>
parents:
87159
diff
changeset
|
54 (setq dbus-registered-functions-table (make-hash-table :test 'equal)) |
87050
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
55 |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
56 (defun dbus-list-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
|
57 "Returns all registered signal registrations to D-Bus. |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
58 The return value is a list, with elements of kind (KEY . VALUE). |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
59 See `dbus-registered-functions-table' for a description of the |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
60 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
|
61 (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
|
62 (maphash |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
63 '(lambda (key value) (add-to-list 'result (cons key value) 'append)) |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
64 dbus-registered-functions-table) |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
65 result)) |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
66 |
87492
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
67 (defun dbus-name-owner-changed-handler (&rest 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
|
68 "Reapplies all signal registrations to D-Bus. |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 empty string if SERVICE was not owned yet. NEW-OWNER is the new |
87492
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
73 owner of SERVICE, or the empty string if SERVICE looses any name owner. |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
74 |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
75 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
|
76 (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
|
77 ;; 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
|
78 ;; are wrong. |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
79 (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
|
80 (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
|
81 (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
|
82 (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
|
83 (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
|
84 (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
|
85 (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
|
86 ;; 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
|
87 (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
|
88 (maphash |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
89 '(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
|
90 (dolist (elt value) |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
91 ;; key has the structure (BUS INTERFACE SIGNAL). |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
92 ;; 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
|
93 (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
|
94 ;; 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
|
95 (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
|
96 ;; 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
|
97 ;; 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
|
98 (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
|
99 ;; 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
|
100 (nth 0 key) (nth 1 elt) (nth 2 elt) |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
101 ;; INTERFACE SIGNAL HANDLER |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
102 (nth 1 key) (nth 2 key) (nth 3 elt))))) |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
103 (copy-hash-table dbus-registered-functions-table)))) |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
104 ;; 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
|
105 (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
|
106 (signal |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
107 'dbus-error |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
108 (cons |
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
109 (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
|
110 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
|
111 |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
112 ;; Register the handler. |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
113 (condition-case nil |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
114 (progn |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
115 (dbus-register-signal |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
116 :system dbus-service-dbus dbus-path-dbus dbus-interface-dbus |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
117 "NameOwnerChanged" 'dbus-name-owner-changed-handler) |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
118 (dbus-register-signal |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
119 :session dbus-service-dbus dbus-path-dbus dbus-interface-dbus |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
120 "NameOwnerChanged" 'dbus-name-owner-changed-handler)) |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
121 (dbus-error)) |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
122 |
87050
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
123 |
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
124 ;;; D-Bus events. |
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
125 |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
126 (defun dbus-check-event (event) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
127 "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
|
128 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
|
129 |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
130 (dbus-event BUS SERVICE PATH INTERFACE MEMBER HANDLER &rest ARGS) |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
131 |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
132 BUS identifies the D-Bus the signal is coming from. It is either |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
133 the symbol `:system' or the symbol `:session'. SERVICE and PATH |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
134 are the unique name and the object path of the D-Bus object |
87050
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
135 emitting the signal. INTERFACE and MEMBER denote the signal |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
136 which has been sent. HANDLER is the function which has been |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
137 registered for this signal. ARGS are the arguments passed to |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
138 HANDLER, when it is called during event handling in |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
139 `dbus-handle-event'. |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
140 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
141 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
|
142 not well formed." |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
143 (when dbus-debug (message "DBus-Event %s" event)) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
144 (unless (and (listp event) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
145 (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
|
146 ;; Bus symbol. |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
147 (symbolp (nth 1 event)) |
87050
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
148 ;; Service. |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
149 (stringp (nth 2 event)) |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
150 ;; Object path. |
87050
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
151 (stringp (nth 3 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
|
152 ;; Interface. |
87050
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
153 (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
|
154 ;; Member. |
87050
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
155 (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
|
156 ;; Handler. |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
157 (functionp (nth 6 event))) |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
158 (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
|
159 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
160 ;;;###autoload |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
161 (defun dbus-handle-event (event) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
162 "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
|
163 EVENT is a D-Bus event, see `dbus-check-event'. HANDLER, being |
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
164 part of the event, is called with arguments ARGS." |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
165 (interactive "e") |
87050
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
166 ;; We don't want to raise an error, because this function is called |
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
167 ;; in the event handling loop. |
87492
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
168 (condition-case err |
87050
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
169 (progn |
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
170 (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
|
171 (apply (nth 6 event) (nthcdr 7 event))) |
87492
bb538e56f976
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
Michael Albinus <michael.albinus@gmx.de>
parents:
87308
diff
changeset
|
172 (dbus-error (when dbus-debug (signal (car err) (cdr err)))))) |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
173 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
174 (defun dbus-event-bus-name (event) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
175 "Return the bus name the event is coming from. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
176 The result is either the symbol `:system' or the symbol `:session'. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
177 EVENT is a D-Bus event, see `dbus-check-event'. This function |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
178 raises a `dbus-error' signal in case the event is not well |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
179 formed." |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
180 (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
|
181 (nth 1 event)) |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
182 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
183 (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
|
184 "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
|
185 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
|
186 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
|
187 not well formed." |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
188 (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
|
189 (nth 2 event)) |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
190 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
191 (defun dbus-event-path-name (event) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
192 "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
|
193 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
|
194 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
|
195 not well formed." |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
196 (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
|
197 (nth 3 event)) |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
198 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
199 (defun dbus-event-interface-name (event) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
200 "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
|
201 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
|
202 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
|
203 not well formed." |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
204 (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
|
205 (nth 4 event)) |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
206 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
207 (defun dbus-event-member-name (event) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
208 "Return the member name the event is coming from. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 well formed." |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
213 (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
|
214 (nth 5 event)) |
87050
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
215 |
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
216 |
7d80e0f3d8f8
* net/dbus.el (dbus-hash-table=): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
86941
diff
changeset
|
217 ;;; D-Bus registered names. |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
218 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
219 (defun dbus-list-activatable-names () |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
220 "Return the D-Bus service names which can be activated as list. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
221 The result is a list of strings, which is nil when there are no |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
222 activatable service names at all." |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
223 (condition-case nil |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
224 (dbus-call-method |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
225 :system dbus-service-dbus |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
226 dbus-path-dbus dbus-interface-dbus "ListActivatableNames") |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
227 (dbus-error))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
228 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
229 (defun dbus-list-names (bus) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
230 "Return the service names registered at D-Bus BUS. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
231 The result is a list of strings, which is nil when there are no |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
232 registered service names at all. Well known names are strings like |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
233 \"org.freedesktop.DBus\". Names starting with \":\" are unique names |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
234 for services." |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
235 (condition-case nil |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
236 (dbus-call-method |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
237 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
|
238 (dbus-error))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
239 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
240 (defun dbus-list-known-names (bus) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
241 "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
|
242 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
|
243 (let (result) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
244 (dolist (name (dbus-list-names bus) result) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
245 (unless (string-equal ":" (substring name 0 1)) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
246 (add-to-list 'result name 'append))))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
247 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
248 (defun dbus-list-queued-owners (bus service) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
249 "Return the unique names registered at D-Bus BUS and queued for SERVICE. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
250 The result is a list of strings, or nil when there are no queued name |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
251 owners service names at all." |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
252 (condition-case nil |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
253 (dbus-call-method |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
254 bus dbus-service-dbus dbus-path-dbus |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
255 dbus-interface-dbus "ListQueuedOwners" service) |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
256 (dbus-error))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
257 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
258 (defun dbus-get-name-owner (bus service) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
259 "Return the name owner of SERVICE registered at D-Bus BUS. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
260 The result is either a string, or nil if there is no name owner." |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
261 (condition-case nil |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
262 (dbus-call-method |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
263 bus dbus-service-dbus dbus-path-dbus |
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
264 dbus-interface-dbus "GetNameOwner" service) |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
265 (dbus-error))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
266 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
267 (defun dbus-introspect (bus service path) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
268 "Return the introspection data of SERVICE in D-Bus BUS at object path PATH. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
269 The data are in XML format. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
270 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
271 Example: |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
272 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
273 \(dbus-introspect |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
274 :system \"org.freedesktop.Hal\" |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
275 \"/org/freedesktop/Hal/devices/computer\")" |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
276 (condition-case nil |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
277 (dbus-call-method |
87159
bcf59f3d73d7
* net/dbus.el (dbus-hash-table=): Fix for new hash table key
Michael Albinus <michael.albinus@gmx.de>
parents:
87093
diff
changeset
|
278 bus service path dbus-interface-introspectable "Introspect") |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
279 (dbus-error))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
280 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
281 (if nil ;; Must be reworked. Shall we offer D-Bus signatures at all? |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
282 (defun dbus-get-signatures (bus interface signal) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
283 "Retrieve SIGNAL's type signatures from D-Bus. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
284 The result is a list of SIGNAL's type signatures. Example: |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
285 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
286 \(\"s\" \"b\" \"ai\"\) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
287 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
288 This list represents 3 parameters of SIGNAL. The first parameter |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
289 is of type string, the second parameter is of type boolean, and |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
290 the third parameter is of type array of integer. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
291 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
292 If INTERFACE or SIGNAL do not exist, or if they do not support |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
293 the D-Bus method org.freedesktop.DBus.Introspectable.Introspect, |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
294 the function returns nil." |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
295 (condition-case nil |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
296 (let ((introspect-xml |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
297 (with-temp-buffer |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
298 (insert (dbus-introspect bus interface)) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
299 (xml-parse-region (point-min) (point-max)))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
300 node interfaces signals args result) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
301 ;; Get the root node. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
302 (setq node (xml-node-name introspect-xml)) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
303 ;; Get all interfaces. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
304 (setq interfaces (xml-get-children node 'interface)) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
305 (while interfaces |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
306 (when (string-equal (xml-get-attribute (car interfaces) 'name) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
307 interface) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
308 ;; That's the requested interface. Check for signals. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
309 (setq signals (xml-get-children (car interfaces) 'signal)) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
310 (while signals |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
311 (when (string-equal (xml-get-attribute (car signals) 'name) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
312 signal) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
313 ;; The signal we are looking for. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
314 (setq args (xml-get-children (car signals) 'arg)) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
315 (while args |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
316 (unless (xml-get-attribute (car args) 'type) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
317 ;; This shouldn't happen, let's escape. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
318 (signal 'dbus-error "")) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
319 ;; We append the signature. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
320 (setq |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
321 result (append result |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
322 (list (xml-get-attribute (car args) 'type)))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
323 (setq args (cdr args))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
324 (setq signals nil)) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
325 (setq signals (cdr signals))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
326 (setq interfaces nil)) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
327 (setq interfaces (cdr interfaces))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
328 result) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
329 ;; We ignore `dbus-error'. There might be no introspectable interface. |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
330 (dbus-error nil))) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
331 ) ;; (if nil ... |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
332 |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
333 (provide 'dbus) |
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
334 |
87053 | 335 ;; arch-tag: a47caf84-9162-4811-90cc-5d388e37b9bd |
86941
cbc23e728425
* net/dbus.el: New file.
Michael Albinus <michael.albinus@gmx.de>
parents:
diff
changeset
|
336 ;;; dbus.el ends here |