Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions all.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@
#:define-dbus-object
#:define-dbus-method
#:define-dbus-signal-handler
#:define-dbus-property
#:publish-objects))
4 changes: 4 additions & 0 deletions examples/publish.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
(:interface "org.adeht.MyService")
(concatenate 'string s1 s2))

(define-dbus-property (my-service my-property)
(:interface "org.adeht.MyService")
"initial-property-value")

(define-dbus-signal-handler (my-service on-signal) ((s :string))
(:interface "org.adeht.MyService")
(format t "Got signal with arg ~S~%" s))
Expand Down
24 changes: 22 additions & 2 deletions publish.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#:define-dbus-object
#:define-dbus-method
#:define-dbus-signal-handler
#:define-dbus-property
#:publish-objects))

(in-package #:dbus/publish)
Expand All @@ -30,7 +31,8 @@
((name :initarg :name :reader dbus-object-name)
(path :initarg :path :accessor dbus-object-path)
(method-handlers :initform (make-hash-table :test 'equal) :reader dbus-object-method-handlers)
(signal-handlers :initform (make-hash-table :test 'equal) :reader dbus-object-signal-handlers)))
(signal-handlers :initform (make-hash-table :test 'equal) :reader dbus-object-signal-handlers)
(properties :initform (make-hash-table :test 'equal) :reader dbus-object-properties)))

(defgeneric dbus-object-handler-lookup-table (message object))

Expand Down Expand Up @@ -81,7 +83,18 @@
(dolist (option options)
(when (and (consp option) (eq (car option) :path))
(setf path (cadr option))))
`(register-dbus-object ',name ,path)))
`(prog1
(register-dbus-object ',name ,path)
(define-dbus-method (,name get) ((interface :string) (property :string)) (:variant)
(:interface "org.freedesktop.DBus.Properties")
(let* ((obj (find-dbus-object ',name))
(value (gethash (cons interface property) (dbus-object-properties obj)))
(type-to-dbus (typecase value
((or null boolean) "b")
(string "s")
(integer "t")
(float "d"))))
(list type-to-dbus value))))))

;;; Define handlers

Expand Down Expand Up @@ -192,6 +205,13 @@ sans dashes."
(lambda (,@parameter-names)
,@body))))

(defmacro define-dbus-property ((object-name property-name) &body body)
`(setf
(gethash
',(cons (getf (car body) :interface) (stringify-lisp-name (symbol-name property-name)))
(dbus-object-properties (find-dbus-object ',object-name)))
',(cadr body)))

;;; Publishing objects

(defgeneric publish-objects (connection &optional object-names))
Expand Down