forked from death/dbus
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstandard-interfaces.lisp
105 lines (95 loc) · 3.24 KB
/
standard-interfaces.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(in-package #:dbus)
(defun get-property (bus service object interface property)
"Invokes the Get method to retrieve an object property."
(dbus:invoke-method (dbus:bus-connection bus)
"Get"
:destination service
:path object
:interface "org.freedesktop.DBus.Properties"
:signature "ss"
:arguments (list interface property)))
(defun get-all-properties (bus service object interface)
"Invokes the GetAll method to retrieve all the properties of an object."
(dbus:invoke-method (dbus:bus-connection bus)
"GetAll"
:destination service
:path object
:interface "org.freedesktop.DBus.Properties"
:signature "s"
:arguments (list interface)))
(defun get-managed-objects (bus service object)
(dbus:invoke-method (dbus:bus-connection bus)
"GetManagedObjects"
:destination service
:path object
:interface "org.freedesktop.DBus.ObjectManager"
:signature ""))
(defun add-match (bus &rest parameters)
"Invokes AddMatch bus method. Valid parameters are:
:type (:signal, :method-call, :method-return, :error)
:sender bus-name
:interface interface-name
:member (method-name, symbol-name)
:path object-path
:path-namespace object-path
:destination unique-name
:argN [N=0~63] string"
(when (oddp (length parameters))
(error "Even number of parameters needed.~%"))
(flet ((unlispify-symbols (list)
(loop for item in list
collecting (if (symbolp item)
(substitute #\_ #\- (format nil "~(~a~)" item))
(format nil "~a" item)))))
(dbus:invoke-method
(dbus:bus-connection bus)
"AddMatch"
:destination "org.freedesktop.DBus"
:path "/org/freedesktop/DBus"
:interface "org.freedesktop.DBus"
:signature "s"
:arguments
(list
(format nil "~{~(~a~)=~a~^,~}" (unlispify-symbols parameters))))))
(defun request-name (bus name &rest flags)
"Asks DBus to asign a name to the bus. Valid flags
are :allow-replacement, :replace-existing and :do-not-queue."
(let ((flags-value
(reduce #'logior
(mapcar (lambda (flag)
(case flag
(:allow-replacement 1)
(:replace-existing 2)
(:do-not-queue 4)
(t (error "Invalid flag ~a~%" flag))))
flags))))
(case
(dbus:invoke-method (dbus:bus-connection bus)
"RequestName"
:destination "org.freedesktop.DBus"
:path "/org/freedesktop/DBus"
:interface "org.freedesktop.DBus"
:signature "su"
:arguments (list name flags-value))
(1 :primary-owner)
(2 :in-queue)
(3 :exists)
(4 :already-owner)
(t (error "Unknown response received~%")))))
(defun list-names (bus)
"Returns a list of all currently-owned names on the bus via
ListNames method invocation."
(dbus:invoke-method (dbus:bus-connection bus)
"ListNames"
:destination "org.freedesktop.DBus"
:path "/"
:interface "org.freedesktop.DBus"
:signature ""))
(defun get-machine-id ()
""
(dbus:with-open-bus (bus (dbus:system-server-addresses))
(dbus:invoke-method (dbus:bus-connection bus)
"GetMachineId"
:destination "org.freedesktop.DBus"
:interface "org.freedesktop.DBus.Peer"
:path "/")))