From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: joakim@verona.se Newsgroups: gmane.emacs.devel Subject: Re: on-the-fly D-Bus proxy creation Date: Tue, 24 Feb 2015 16:13:49 +0100 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1424790902 13493 80.91.229.3 (24 Feb 2015 15:15:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 24 Feb 2015 15:15:02 +0000 (UTC) Cc: martin rudalics , emacs-devel@gnu.org To: Daiki Ueno Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Feb 24 16:14:52 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YQHCD-0005wE-69 for ged-emacs-devel@m.gmane.org; Tue, 24 Feb 2015 16:14:49 +0100 Original-Received: from localhost ([::1]:49781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQHC7-0002a5-3L for ged-emacs-devel@m.gmane.org; Tue, 24 Feb 2015 10:14:43 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50135) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQHBt-0002Wa-DQ for emacs-devel@gnu.org; Tue, 24 Feb 2015 10:14:30 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQHBl-0008Bu-Oj for emacs-devel@gnu.org; Tue, 24 Feb 2015 10:14:29 -0500 Original-Received: from mx1.bahnhof.se ([213.80.101.11]:41030) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQHBl-0008AP-FD; Tue, 24 Feb 2015 10:14:21 -0500 Original-Received: from localhost (mf.bahnhof.se [213.80.101.20]) by mx1-reinject (Postfix) with ESMTP id 2F63141074; Tue, 24 Feb 2015 16:14:15 +0100 (CET) X-Virus-Scanned: by amavisd-new using ClamAV at bahnhof.se (MF3) Original-Received: from mf3.bahnhof.se ([127.0.0.1]) by localhost (mf3.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YlPckgavD2nq; Tue, 24 Feb 2015 16:14:06 +0100 (CET) Original-Received: from mta.verona.se (h-235-62.a149.priv.bahnhof.se [85.24.235.62]) by mf3.bahnhof.se (Postfix) with ESMTP id 406823E8CD4; Tue, 24 Feb 2015 16:14:05 +0100 (CET) Original-Received: from localhost (unknown [127.0.0.1]) by mta.verona.se (Postfix) with ESMTP id C55B052D1A0; Tue, 24 Feb 2015 15:14:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at verona.se Original-Received: from mta.verona.se ([127.0.0.1]) by localhost (exodia.verona.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fkWoqhAwEfqC; Tue, 24 Feb 2015 16:13:49 +0100 (CET) Original-Received: from exodia.verona.se (www.verona.se [192.168.200.15]) by mta.verona.se (Postfix) with ESMTP id 2064F52D19A; Tue, 24 Feb 2015 16:13:49 +0100 (CET) In-Reply-To: (Daiki Ueno's message of "Tue, 24 Feb 2015 17:05:34 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 213.80.101.11 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:183450 Archived-At: Daiki Ueno writes: > Hello, Hello Daiki, > > There are several programming languages with support for D-Bus client > implementation. For example, with the following code: > https://git.gnome.org/browse/gnome-shell/tree/js/ui/keyboard.js#n56 > > const CaribouDaemonIface = ' \ > \ > \ > \ > \ > '; I use Jan Moringens dbus-proxy in my Inkmacs project, which is an Emacs interface for Inkscape. It would be nice if there were comparable functionality directly in Emacs or ELPA. > > const CaribouDaemonProxy = Gio.DBusProxy.makeProxyWrapper(CaribouDaemonIface); > > One can call a D-Bus method as a normal method of CaribouDaemonProxy. > This is really handy and I wished to have similar feature in Elisp > (though I haven't ever written any practical D-Bus code in Elisp). > > Thanks to cl-generic, I gave it a try. With the attached code (far from > complete though), a client can be implemented as: > > (dbus-define-proxy search-provider "\ > > > > > > > > > ") > > Then you can create a client and call D-Bus methods: > > (setq search-provider > (search-provider-make :session > "org.gnome.Weather.BackgroundService" > "/org/gnome/Weather/BackgroundService")) > (search-provider-call-GetInitialResultSet search-provider '("tokyo")) > > If this seems to be useful, I can finish it off as a patch. > > Thanks, > -- > Daiki Ueno > > (require 'dbus) > > (eval-when-compile (require 'cl-lib)) > (eval-when-compile (require 'xml)) > > (cl-defstruct dbus-proxy > (bus :read-only t) > (service :read-only t) > (path :read-only t)) > > (defmacro dbus-define-proxy (name xml) > (let* ((node (car (with-temp-buffer > (insert xml) > (xml-parse-region (point-min) (point-max))))) > (interface (car (xml-get-children node 'interface))) > (methods (xml-get-children interface 'method)) > (interface-name (xml-get-attribute-or-nil interface 'name))) > `(progn > (cl-defstruct (,name (:include dbus-proxy) > (:constructor nil) > (:constructor ,(intern (format "%s-make" name)) > (bus service path))) > ;; FIXME: slots for cached properties? > ) > ,@(mapcar > (lambda (method) > (let ((method-name (xml-get-attribute-or-nil method 'name)) > ;; FIXME: parse argument types? > (in-args > (mapcar #'intern > (delq nil > (mapcar > (lambda (arg) > (let ((direction (xml-get-attribute-or-nil > arg 'direction))) > (if (or (null direction) > (not (equal direction "out"))) > (xml-get-attribute-or-nil > arg 'name)))) > (xml-get-children method 'arg)))))) > ;; FIXME: un-CamelCasify method-name? > `(cl-defmethod ,(intern (format "%s-call-%s" name method-name)) > ((proxy ,name) ,@in-args &rest args) > (apply #'dbus-call-method > (dbus-proxy-bus proxy) > (dbus-proxy-service proxy) > (dbus-proxy-path proxy) > ,interface-name > ,method-name > ,@in-args > args)))) > methods) > ;; FIXME: asynchronous method calls, signals? > ))) > > (dbus-define-proxy search-provider "\ > > > > > > > > > ") > > ;; (setq search-provider > ;; (search-provider-make :session > ;; "org.gnome.Weather.BackgroundService" > ;; "/org/gnome/Weather/BackgroundService")) > ;; (search-provider-call-GetInitialResultSet search-provider '("tokyo")) > -- Joakim Verona