forked from lucashpandolfo/dbus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convenience.lisp
40 lines (32 loc) · 1.79 KB
/
convenience.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
;;;; +----------------------------------------------------------------+
;;;; | DBUS DEATH, 2010-2011 |
;;;; +----------------------------------------------------------------+
(in-package #:dbus)
;;;; Higher-level interface
(defun hello (connection)
(invoke-method connection "Hello"
:path "/org/freedesktop/DBus"
:interface "org.freedesktop.DBus"
:destination "org.freedesktop.DBus"))
(defclass bus ()
((connection :initarg :connection :reader bus-connection)
(name :initarg :name :reader bus-name)))
(defun call-with-open-bus (function event-base server-addresses)
(with-open-connection (connection event-base server-addresses)
(authenticate (supported-authentication-mechanisms connection) connection)
(funcall function (make-instance 'bus :name (hello connection) :connection connection))))
(defmacro with-open-bus ((bus-var server-addresses &key event-base multiplexer) &body forms)
(if (null event-base)
(with-gensyms (event-base)
`(with-event-base (,event-base :mux ',(cdr (assoc (or multiplexer :select)
(available-multiplexers))))
(with-open-bus (,bus-var ,server-addresses :event-base ,event-base)
,@forms)))
(once-only (server-addresses event-base)
`(call-with-open-bus (lambda (,bus-var) ,@forms) ,event-base ,server-addresses))))
(defmacro with-introspected-object ((name bus path destination) &body forms)
(with-gensyms (object)
`(let ((,object (make-object-from-introspection (bus-connection ,bus) ,path ,destination)))
(flet ((,name (interface-name method-name &rest args)
(apply #'object-invoke ,object interface-name method-name args)))
,@forms))))