Last active
March 6, 2020 15:48
-
-
Save isoraqathedh/bbcb74e6cd5b39b3a783a3cf80b13212 to your computer and use it in GitHub Desktop.
Let's see how much code is needed to get this function exposed via dbus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; The actual function itself. It's pretty trivial. | |
(defun get-clock-string-or-nothing () | |
"Return the bare clock string, or NIL if there is no clock running." | |
(when (org-clock-is-active) | |
(format "%s,%s" (org-duration-from-minutes (org-clock-get-clocked-time)) | |
org-clock-heading))) | |
;;; Now the rest... | |
(require 'dbus) | |
;; Basic setup to get Emacs to register to dbus correctly | |
(dbus-register-service :session dbus-service-emacs) | |
(defun dbus-introspect-generic (&rest subnode-names) | |
"Generic XML for a node with only empty subnodes." | |
(let ((prefix " | |
<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" | |
\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\"> | |
<node> | |
<interface name='org.freedesktop.DBus.Introspectable'> | |
<method name='Introspect'> | |
<arg name='xml_data' type='s' direction='out' /> | |
</method> | |
</interface>") | |
(subnode " | |
<node name='%s' />") | |
(suffix " | |
</node>")) | |
(reduce #'concat | |
`(,prefix | |
,@(mapcar (lambda (x) (format subnode x)) subnode-names) | |
,suffix)))) | |
(defun dbus-introspect-/ () | |
(dbus-introspect-generic "org")) | |
(defun dbus-introspect-/org () | |
(dbus-introspect-generic "gnu")) | |
(defun dbus-introspect-/org/gnu () | |
(dbus-introspect-generic "Emacs")) | |
(defun dbus-introspect-/org/gnu/Emacs () | |
(dbus-introspect-generic my-service-name)) | |
(dbus-register-method | |
:session | |
dbus-service-emacs | |
"/" | |
dbus-interface-introspectable | |
"Introspect" | |
'dbus-introspect-/) | |
(dbus-register-method | |
:session | |
dbus-service-emacs | |
"/org" | |
dbus-interface-introspectable | |
"Introspect" | |
'dbus-introspect-/org) | |
(dbus-register-method | |
:session | |
dbus-service-emacs | |
"/org/gnu" | |
dbus-interface-introspectable | |
"Introspect" | |
'dbus-introspect-/org/gnu) | |
(dbus-register-method | |
:session | |
dbus-service-emacs | |
dbus-path-emacs | |
dbus-interface-introspectable | |
"Introspect" | |
'dbus-introspect-/org/gnu/Emacs) | |
;; Now the real part | |
(defun dbus-introspect-my-service () | |
" | |
<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" | |
\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\"> | |
<node> | |
<interface name='org.freedesktop.DBus.Introspectable'> | |
<method name='Introspect'> | |
<arg name='xml_data' type='s' direction='out' /> | |
</method> | |
</interface> | |
<interface name='org.gnu.Emacs.isoraqathedh'> | |
<method name='currentClock'> | |
<arg name='clockstring' direction='out' type='s' /> | |
</method> | |
</interface> | |
</node> | |
") | |
(dbus-register-method | |
:session | |
dbus-service-emacs | |
(concat dbus-path-emacs "/" my-service-name) | |
dbus-interface-introspectable | |
"Introspect" | |
'dbus-introspect-my-service) | |
(defun get-clock-string/dbus () | |
(list :string (or (get-clock-string-or-nothing) | |
"(no task),---"))) | |
(setq get-clock-string/dbus-method | |
(dbus-register-method | |
:session | |
dbus-service-emacs | |
(concat dbus-path-emacs "/" my-service-name) | |
(concat dbus-service-emacs "." my-service-name) | |
"currentClock" | |
'get-clock-string/dbus)) | |
(provide 'org-clock-dbus) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment