unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#20193: 25.0.50; declarative type specification for D-Bus args
@ 2015-03-25  3:31 Daiki Ueno
  2015-03-26 11:34 ` Michael Albinus
  0 siblings, 1 reply; 17+ messages in thread
From: Daiki Ueno @ 2015-03-25  3:31 UTC (permalink / raw)
  To: 20193; +Cc: Michael Albinus

[-- Attachment #1: Type: text/plain, Size: 2445 bytes --]

Severity: wishlist

Hello Michael,

While using dbus.el, I found it a bit cumbersome to specify type symbols
for the arguments of dbus-call-method and dbus-send-signal.

Suppose a simple D-Bus signature "a{si}".  Since dbusbind treats positive
integers as uint32, one would need to write:

  (dbus-call-method :session
                    "org.example.Foo"
                    "/org/example/Foo"
                    "org.example.Foo"
                    "Test"
                    '(:array
                       (:dict-entry :string "a" :int32 1)
                       (:dict-entry :string "b" :int32 2)))

This is simple if the arguments are "fixed", but if one wants a wrapper,
she would need to write a loop by herself.

  (defun example-foo (alist)
    (dbus-call-method :session
                      "org.example.Foo"
                      "/org/example/Foo"
                      "org.example.Foo"
                      "Test"
                      (list :array
                            (mapcar (lambda (entry)
                                      (list :dict-entry
                                            :string (car entry)
                                            :int32 (cdr entry)))
                                    alist))))

So I would like to propose an alternative syntax, similar to the `:type'
keyword of `defcustom', like this:

  (dbus-call-method :session
                    "org.example.Foo"
                    "/org/example/Foo"
                    "org.example.Foo"
                    "Test"
                    '(:type (:array (:dict-entry :string :int32)))
                    '(("a" . 1) ("b" . 2)))

That is, if a type symbol is a cons cell and the car is :type, treat the
cdr as the type specification of the following value.

The the wrapper can be written as:

  (defun example-foo (alist)
    (dbus-call-method :session
                      "org.example.Foo"
                      "/org/example/Foo"
                      "org.example.Foo"
                      "Test"
                      '(:type (:array (:dict-entry :string :int32)))
                      alist))

Would this kind of change be considered?  As a proof-of-concept, I'm
attaching a small Elisp snippet that augments the argument value with
the given type information (though I guess it should be implemented in
the C level, to avoid duplication of signature computation code).

Comments appreciated.

Regards,
-- 
Daiki Ueno

[-- Attachment #2: dbus--annotate-arg.el --]
[-- Type: text/plain, Size: 1301 bytes --]

;; (setq lexical-binding t)

;; (dbus--annotate-arg '(:array :int32) '(1 2 3))
;; ;=> ((:array :int32 1 :int32 2 :int32 3))

;; (dbus--annotate-arg '(:array (:dict-entry :string :int32)) '(("a" . 1) ("b" . 2)))
;; ;=> ((:array (:dict-entry :string "a" :int32 1) (:dict-entry :string "b" :int32 2)))

;; (dbus--annotate-arg '(:struct :object-path (:array :signature) :string)
;;                     '("path" ("sig") "password"))
;; ;=> ((:struct :object-path "path" (:array :signature "sig") :string "password"))

(defun dbus--annotate-arg (type arg)
  (pcase type
    ((and basic (or :byte :boolean :int16 :uint16 :int32 :uint32
		    :double :string :object-path :signature :unix-fd))
     (list basic arg))
    (`(:array ,elttype)
     (list (cons :array (apply #'nconc
			       (mapcar (lambda (subarg)
					 (dbus--annotate-arg elttype subarg))
				       arg)))))
    (`(,(and symbol (or :variant :struct)) . ,memtypes)
     (list (cons symbol (apply #'nconc
			       (cl-mapcar
				(lambda (memtype subarg)
				  (dbus--annotate-arg memtype subarg))
				memtypes arg)))))
    (`(:dict-entry ,keytype ,valtype)
     (list (cons :dict-entry (nconc (dbus--annotate-arg keytype (car arg))
			      (dbus--annotate-arg valtype (cdr arg))))))
    (_ (error "Unknown type specification: %S" type))))

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-09-24 13:17 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-25  3:31 bug#20193: 25.0.50; declarative type specification for D-Bus args Daiki Ueno
2015-03-26 11:34 ` Michael Albinus
2015-03-27  7:29   ` Daiki Ueno
2015-03-27  7:40     ` Michael Albinus
2015-08-27  9:23       ` Daiki Ueno
2015-08-28  7:31         ` Daiki Ueno
2015-08-28  8:22           ` Michael Albinus
2015-08-30 13:54           ` Michael Albinus
2015-09-02  7:24             ` Daiki Ueno
2015-09-02 14:06               ` Michael Albinus
2015-09-03  9:29                 ` Daiki Ueno
2015-09-03 10:07                   ` Michael Albinus
2015-09-04  2:33                     ` Daiki Ueno
2015-09-04  7:29                       ` Michael Albinus
2020-09-18 13:23                         ` Lars Ingebrigtsen
2020-09-24 13:17                           ` Michael Albinus
2015-09-03 16:08               ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).