From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#41744: 27.0.91; Various D-Bus cleanups Date: Sun, 07 Jun 2020 00:26:50 +0100 Message-ID: <87mu5fpyh1.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="73383"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: michael albinus To: 41744@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 07 01:28:23 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jhiEg-000J2j-UN for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Jun 2020 01:28:23 +0200 Original-Received: from localhost ([::1]:35552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhiEg-0007IN-0H for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Jun 2020 19:28:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhiEN-00074i-0h for bug-gnu-emacs@gnu.org; Sat, 06 Jun 2020 19:28:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41197) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhiEM-0006RL-Na for bug-gnu-emacs@gnu.org; Sat, 06 Jun 2020 19:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jhiEM-000418-ED; Sat, 06 Jun 2020 19:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: michael.albinus@gmx.de, bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 Jun 2020 23:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41744 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: michael albinus Original-Received: via spool by submit@debbugs.gnu.org id=B.159148602315373 (code B ref -1); Sat, 06 Jun 2020 23:28:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Jun 2020 23:27:03 +0000 Original-Received: from localhost ([127.0.0.1]:52743 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jhiDP-0003zt-8q for submit@debbugs.gnu.org; Sat, 06 Jun 2020 19:27:03 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:35872) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jhiDO-0003zm-HU for submit@debbugs.gnu.org; Sat, 06 Jun 2020 19:27:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhiDO-0006Lj-B9 for bug-gnu-emacs@gnu.org; Sat, 06 Jun 2020 19:27:02 -0400 Original-Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:46393) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhiDH-0006AL-HK for bug-gnu-emacs@gnu.org; Sat, 06 Jun 2020 19:27:01 -0400 Original-Received: by mail-wr1-x42f.google.com with SMTP id x6so13522286wrm.13 for ; Sat, 06 Jun 2020 16:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:user-agent:mime-version; bh=8YG4T+2igRpoXIbIcvgXMVuvTxOu7KzekBj36a7xXSA=; b=1udIuDfdRuvDW3+5zPwepMC9MEykA246gUcwwMtU6+UXuP/JhZArI7WbQ681RkUdtA QWEg6fL7vlzkF7gkamL6rtmrWq7nFTyib6kiAQ3/lr0H0ON3m5teaiJvzBbB9/eMLpur cHgPDlxMLSwzdd4eqJENeB9TfALGdPUYtyise+X6PUCa12e3OksuuTXezMNMXrLjyUXQ zUTlMhmuiCeEQK5f9FeILx29zfysJkRaREAn4VLdm9YjL97zybxOJH5Y8hcQ+isENy10 hyw6RxnAt/VG55WwvHlWlrWT6OIA3EKZtMaRasY5LJT9DFsOeTFDkznkABQOQUY8xYfO XWsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version; bh=8YG4T+2igRpoXIbIcvgXMVuvTxOu7KzekBj36a7xXSA=; b=Wso+Q1Spuiehqv94tAmI81N/EW+U9cq82mAwAJ79nf5etB4WT+06PHthjTPHHFKE/V g1E38NN9e2v0Anq+Zd40opV9vXj5gSI/bErU3EBu+Tp67WewnGVdMWZUEDL+9Gl4z7IB 8mMvh2yktpjAbYX/5ZGMNpLUZ3DdiaZoSPORbycOfl5jvsvnRg7f3uQcrR372UOy8j9s Ql9jaVppwzYm3/P1mJgbPq2r6h/gXzqa3eGZXpyspReaj8aDYMH9K/Xo+Y2eUHk35lZY 8NszEOLa1e6TVdC5XR7un+3xZ/Vnhd92OGI5w8bi3wewEhlDxlzaoODpoKbXwnedSvdD ulTg== X-Gm-Message-State: AOAM532/G+IK8jl98THkwGQmXHpNeltlz93f5AT2IeDsNKxw1B1viTyP YlUXiBSTeK2lu1tsPBiIJWsJ2LNFgvs= X-Google-Smtp-Source: ABdhPJwlBNZKHGudSdEOT3lhVmc0GDM6nBophcM7+ALJZ7MGfOIjvhOzVPc5nD5pabkU/mBEvmuCPw== X-Received: by 2002:a5d:4e87:: with SMTP id e7mr15499865wru.427.1591486013100; Sat, 06 Jun 2020 16:26:53 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:92bd:1bfd:38fc:fae2]) by smtp.gmail.com with ESMTPSA id k17sm19017504wrl.54.2020.06.06.16.26.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jun 2020 16:26:52 -0700 (PDT) Received-SPF: none client-ip=2a00:1450:4864:20::42f; envelope-from=contovob@tcd.ie; helo=mail-wr1-x42f.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181648 Archived-At: --=-=-= Content-Type: text/plain X-Debbugs-Cc: Michael Albinus Severity: minor Tags: patch While reading through the D-Bus manual and implementation, I noticed some opportunities for small cleanups. I propose these documentation cleanups for emacs-27: --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0001-Clean-up-D-Bus-documentation.patch Content-Transfer-Encoding: quoted-printable >From 962f2af23a0d71638e14bb143de866862d51d0d2 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Sat, 6 Jun 2020 00:58:37 +0100 Subject: [PATCH] Clean up D-Bus documentation * doc/lispref/errors.texi (Standard Errors): The error symbol dbus-error is defined even when Emacs is built without D-Bus. * doc/misc/dbus.texi (Bus Names, Introspection) (Nodes and Interfaces, Methods and Signal) (Properties and Annotations, Arguments and Signatures) (Synchronous Methods, Receiving Method Calls, Signals) (Alternative Buses, Errors and Events): Clarify wording. Fix indentation of and simplify examples where possible. Improve Texinfo markup and cross-referencing where possible. (Type Conversion): Ditto. Remove mentions of Emacs' fixnum range now that we have bignums. * lisp/net/dbus.el (dbus-return-values-table) (dbus-call-method-asynchronously, dbus-send-signal) (dbus-register-signal, dbus-register-method) (dbus-string-to-byte-array, dbus-byte-array-to-string) (dbus-escape-as-identifier, dbus-check-event, dbus-event-bus-name) (dbus-event-message-type, dbus-event-serial-number) (dbus-event-service-name, dbus-event-path-name) (dbus-event-interface-name, dbus-event-member-name) (dbus-list-activatable-names, dbus-list-queued-owners, dbus-ping) (dbus-introspect-get-interface-names, dbus-introspect-get-interface) (dbus-introspect-get-method, dbus-introspect-get-signal) (dbus-introspect-get-property, dbus-introspect-get-annotation-names) (dbus-introspect-get-annotation, dbus-introspect-get-argument-names) (dbus-introspect-get-argument, dbus-introspect-get-signature) (dbus-set-property, dbus-register-property) (dbus-get-all-managed-objects, dbus-init-bus): Clarify docstring and improve formatting where possible. (dbus-call-method): Ditto. Remove mentions of Emacs' fixnum range now that we have bignums. --- doc/lispref/errors.texi | 5 +- doc/misc/dbus.texi | 795 ++++++++++++++++++++-------------------- lisp/net/dbus.el | 228 ++++++------ 3 files changed, 511 insertions(+), 517 deletions(-) diff --git a/doc/lispref/errors.texi b/doc/lispref/errors.texi index dc6877c9ec..cd8694be8a 100644 --- a/doc/lispref/errors.texi +++ b/doc/lispref/errors.texi @@ -79,9 +79,8 @@ Standard Errors a loop}. @xref{Variable Aliases}. =20 @item dbus-error -The message is @samp{D-Bus error}. This is only defined if Emacs was -compiled with D-Bus support. @xref{Errors and Events,,, dbus, D-Bus -integration in Emacs}. +The message is @samp{D-Bus error}. @xref{Errors and Events,,, dbus, +D-Bus integration in Emacs}. =20 @item end-of-buffer The message is @samp{End of buffer}. @xref{Character Motion}. diff --git a/doc/misc/dbus.texi b/doc/misc/dbus.texi index 9e5f1ccc6f..eaf77ffa8f 100644 --- a/doc/misc/dbus.texi +++ b/doc/misc/dbus.texi @@ -167,7 +167,7 @@ Bus names described in a service registration file. Under GNU/Linux, such files are located at @file{/usr/share/dbus-1/system-services/} (for the @code{:system} bus) or @file{/usr/share/dbus-1/services/}. An -activatable service is not necessarily registered at @var{bus} at already. +activatable service is not necessarily registered at @var{bus} already. =20 The result is a list of strings, which is @code{nil} when there are no activatable service names at all. Example: @@ -180,8 +180,8 @@ Bus names @end defun =20 @defun dbus-list-names bus -All service names, which are registered at D-Bus @var{bus}, are -returned. The result is a list of strings, which is @code{nil} when +This function returns all service names, which are registered at D-Bus +@var{bus}. The result is a list of strings, which is @code{nil} when there are no registered service names at all. Well known names are strings like @samp{org.freedesktop.DBus}. Names starting with @samp{:} are unique names for services. @@ -191,10 +191,10 @@ Bus names @end defun =20 @defun dbus-list-known-names bus -Retrieves all registered services which correspond to a known name in @var= {bus}. -A service has a known name if it doesn't start with @samp{:}. The -result is a list of strings, which is @code{nil} when there are no -known names at all. +This function retrieves all registered services which correspond to a +known name in @var{bus}. A service has a known name if it doesn't +start with @samp{:}. The result is a list of strings, which is +@code{nil} when there are no known names at all. =20 @var{bus} must be either the symbol @code{:system} or the symbol @code{:session}. @@ -202,9 +202,9 @@ Bus names =20 @defun dbus-list-queued-owners bus service For a given service, registered at D-Bus @var{bus} under the name -@var{service}, all queued unique names are returned. The result is a -list of strings, or @code{nil} when there are no queued names for -@var{service} at all. +@var{service}, this function returns all queued unique names. The +result is a list of strings, or @code{nil} when there are no queued +names for @var{service} at all. =20 @var{bus} must be either the symbol @code{:system} or the symbol @code{:session}. @var{service} must be a known service name as @@ -213,9 +213,9 @@ Bus names =20 @defun dbus-get-name-owner bus service For a given service, registered at D-Bus @var{bus} under the name -@var{service}, the unique name of the name owner is returned. The -result is a string, or @code{nil} when there exist no name owner of -@var{service}. +@var{service}, this function returns the unique name of the name +owner. The result is a string, or @code{nil} when there is no name +owner of @var{service}. =20 @var{bus} must be either the symbol @code{:system} or the symbol @code{:session}. @var{service} must be a known service name as @@ -223,26 +223,28 @@ Bus names @end defun =20 @defun dbus-ping bus service &optional timeout -Check whether the service name @var{service} is registered at D-Bus -@var{bus}. @var{service} might not have been started yet, it is -autostarted if possible. The result is either @code{t} or @code{nil}. +This function checks whether the service name @var{service} is +registered at D-Bus @var{bus}. If @var{service} has not yet started, +it is autostarted if possible. The result is either @code{t} or +@code{nil}. =20 @var{bus} must be either the symbol @code{:system} or the symbol @code{:session}. @var{service} must be a string. @var{timeout}, a nonnegative integer, specifies the maximum number of milliseconds -@code{dbus-ping} must return. The default value is 25,000. Example: +before @code{dbus-ping} must return. The default value is 25,000. +Example: =20 @lisp (message - "%s screensaver on board." - (cond - ((dbus-ping :session "org.gnome.ScreenSaver" 100) "Gnome") - ((dbus-ping :session "org.freedesktop.ScreenSaver" 100) "KDE") - (t "No"))) + "%s screensaver on board." + (cond + ((dbus-ping :session "org.gnome.ScreenSaver" 100) "Gnome") + ((dbus-ping :session "org.freedesktop.ScreenSaver" 100) "KDE") + (t "No"))) @end lisp =20 -If it shall be checked whether @var{service} is already running -without autostarting it, one shall apply +To check whether @var{service} is already running without autostarting +it, you can instead write: =20 @lisp (member service (dbus-list-known-names bus)) @@ -250,8 +252,9 @@ Bus names @end defun =20 @defun dbus-get-unique-name bus -The unique name, under which Emacs is registered at D-Bus @var{bus}, -is returned as string. +@anchor{dbus-get-unique-name} +This function returns the unique name, under which Emacs is registered +at D-Bus @var{bus}, as a string. =20 @var{bus} must be either the symbol @code{:system} or the symbol @code{:session}. @@ -380,8 +383,8 @@ Introspection =20 @lisp (dbus-introspect - :system "org.freedesktop.Hal" - "/org/freedesktop/Hal/devices/computer") + :system "org.freedesktop.Hal" + "/org/freedesktop/Hal/devices/computer") =20 @result{} " t or nil - DBUS_TYPE_BYTE =3D> number - DBUS_TYPE_UINT16 =3D> number + DBUS_TYPE_BYTE =3D> natural number + DBUS_TYPE_UINT16 =3D> natural number DBUS_TYPE_INT16 =3D> integer - DBUS_TYPE_UINT32 =3D> number or float - DBUS_TYPE_UNIX_FD =3D> number or float - DBUS_TYPE_INT32 =3D> integer or float - DBUS_TYPE_UINT64 =3D> number or float - DBUS_TYPE_INT64 =3D> integer or float + DBUS_TYPE_UINT32 =3D> natural number + DBUS_TYPE_UNIX_FD =3D> natural number + DBUS_TYPE_INT32 =3D> integer + DBUS_TYPE_UINT64 =3D> natural number + DBUS_TYPE_INT64 =3D> integer DBUS_TYPE_DOUBLE =3D> float DBUS_TYPE_STRING =3D> string DBUS_TYPE_OBJECT_PATH =3D> string @@ -268,9 +268,9 @@ dbus-call-method Example: =20 \(dbus-call-method - :session \"org.gnome.seahorse\" \"/org/gnome/seahorse/keys/openpgp\" - \"org.gnome.seahorse.Keys\" \"GetKeyField\" - \"openpgp:657984B8C7A966DD\" \"simple-name\") + :session \"org.gnome.seahorse\" \"/org/gnome/seahorse/keys/openpgp\" + \"org.gnome.seahorse.Keys\" \"GetKeyField\" + \"openpgp:657984B8C7A966DD\" \"simple-name\") =20 =3D> (t (\"Philip R. Zimmermann\")) =20 @@ -278,9 +278,9 @@ dbus-call-method object is returned instead of a list containing this single Lisp object. =20 \(dbus-call-method - :system \"org.freedesktop.Hal\" \"/org/freedesktop/Hal/devices/computer\" - \"org.freedesktop.Hal.Device\" \"GetPropertyString\" - \"system.kernel.machine\") + :system \"org.freedesktop.Hal\" \"/org/freedesktop/Hal/devices/computer\" + \"org.freedesktop.Hal.Device\" \"GetPropertyString\" + \"system.kernel.machine\") =20 =3D> \"i686\"" =20 @@ -357,10 +357,10 @@ dbus-call-method-asynchronously return message has arrived. If HANDLER is nil, no return message will be expected. =20 -If the parameter `:timeout' is given, the following integer TIMEOUT -specifies the maximum number of milliseconds the method call must -return. The default value is 25,000. If the method call doesn't -return in time, a D-Bus error is raised. +If the parameter `:timeout' is given, the following integer +TIMEOUT specifies the maximum number of milliseconds before the +method call must return. The default value is 25,000. If the +method call doesn't return in time, a D-Bus error is raised. =20 All other arguments ARGS are passed to METHOD as arguments. They are converted into D-Bus types via the following rules: @@ -377,19 +377,19 @@ dbus-call-method-asynchronously =20 If HANDLER is a Lisp function, the function returns a key into the hash table `dbus-registered-objects-table'. The corresponding entry -in the hash table is removed, when the return message has been arrived, +in the hash table is removed, when the return message arrives, and HANDLER is called. =20 Example: =20 \(dbus-call-method-asynchronously - :system \"org.freedesktop.Hal\" \"/org/freedesktop/Hal/devices/computer\" - \"org.freedesktop.Hal.Device\" \"GetPropertyString\" \\=3D'message - \"system.kernel.machine\") + :system \"org.freedesktop.Hal\" \"/org/freedesktop/Hal/devices/computer\" + \"org.freedesktop.Hal.Device\" \"GetPropertyString\" \\=3D'message + \"system.kernel.machine\") =20 - =3D> (:serial :system 2) + -| i686 =20 - -| i686" + =3D> (:serial :system 2)" =20 (or (featurep 'dbusbind) (signal 'dbus-error (list "Emacs not compiled with dbus support"))) @@ -438,8 +438,8 @@ dbus-send-signal Example: =20 \(dbus-send-signal - :session nil \"/org/gnu/Emacs\" \"org.gnu.Emacs.FileManager\" - \"FileModified\" \"/home/albinus/.emacs\")" + :session nil \"/org/gnu/Emacs\" \"org.gnu.Emacs.FileManager\" + \"FileModified\" \"/home/albinus/.emacs\")" =20 (or (featurep 'dbusbind) (signal 'dbus-error (list "Emacs not compiled with dbus support"))) @@ -625,17 +625,17 @@ dbus-register-signal It can be either a known name or the unique name of the D-Bus object sending the signal. =20 -PATH is the D-Bus object path SERVICE is registered. INTERFACE -is an interface offered by SERVICE. It must provide SIGNAL. -HANDLER is a Lisp function to be called when the signal is -received. It must accept as arguments the values SIGNAL is +PATH is the D-Bus object path SERVICE is registered at. +INTERFACE is an interface offered by SERVICE. It must provide +SIGNAL. HANDLER is a Lisp function to be called when the signal +is received. It must accept as arguments the values SIGNAL is sending. =20 SERVICE, PATH, INTERFACE and SIGNAL can be nil. This is interpreted as a wildcard for the respective argument. =20 The remaining arguments ARGS can be keywords or keyword string pairs. -The meaning is as follows: +Their meaning is as follows: =20 `:argN' STRING: `:pathN' STRING: This stands for the Nth argument of the @@ -643,8 +643,9 @@ dbus-register-signal matches as specified by D-Bus, while an `:argN' argument requires an exact match. =20 -`:arg-namespace' STRING: Register for the signals, which first -argument defines the service or interface namespace STRING. +`:arg-namespace' STRING: Register for those signals, whose first +argument names a service or interface within the namespace +STRING. =20 `:path-namespace' STRING: Register for the object path namespace STRING. All signals sent from an object path, which has STRING as @@ -660,8 +661,8 @@ dbus-register-signal (message \"Device %s added\" device)) =20 \(dbus-register-signal - :system \"org.freedesktop.Hal\" \"/org/freedesktop/Hal/Manager\" - \"org.freedesktop.Hal.Manager\" \"DeviceAdded\" \\=3D'my-signal-handler) + :system \"org.freedesktop.Hal\" \"/org/freedesktop/Hal/Manager\" + \"org.freedesktop.Hal.Manager\" \"DeviceAdded\" \\=3D'my-signal-handler) =20 =3D> ((:signal :system \"org.freedesktop.Hal.Manager\" \"DeviceAdded\") (\"org.freedesktop.Hal\" \"/org/freedesktop/Hal/Manager\" my-signal-= handler)) @@ -773,24 +774,24 @@ dbus-register-signal =20 (defun dbus-register-method (bus service path interface method handler &optional dont-register-servi= ce) - "Register for method METHOD on the D-Bus BUS. + "Register METHOD on the D-Bus BUS. =20 BUS is either a Lisp symbol, `:system' or `:session', or a string denoting the bus address. =20 SERVICE is the D-Bus service name of the D-Bus object METHOD is -registered for. It must be a known name (See discussion of +registered for. It must be a known name (see discussion of DONT-REGISTER-SERVICE below). =20 -PATH is the D-Bus object path SERVICE is registered (See discussion of -DONT-REGISTER-SERVICE below). INTERFACE is the interface offered by -SERVICE. It must provide METHOD. +PATH is the D-Bus object path SERVICE is registered at (see +discussion of DONT-REGISTER-SERVICE below). INTERFACE is the +interface offered by SERVICE. It must provide METHOD. =20 HANDLER is a Lisp function to be called when a method call is received. It must accept the input arguments of METHOD. The return value of HANDLER is used for composing the returning D-Bus message. -In case HANDLER shall return a reply message with an empty argument -list, HANDLER must return the symbol `:ignore'. +If HANDLER returns a reply message with an empty argument list, +HANDLER must return the symbol `:ignore'. =20 When DONT-REGISTER-SERVICE is non-nil, the known name SERVICE is not registered. This means that other D-Bus clients have no way of @@ -888,8 +889,8 @@ dbus-unregister-object ;;; D-Bus type conversion. =20 (defun dbus-string-to-byte-array (string) - "Transform STRING to list (:array :byte c1 :byte c2 ...). -STRING shall be UTF8 coded." + "Transform STRING to list (:array :byte C1 :byte C2 ...). +STRING shall be UTF-8 coded." (if (zerop (length string)) '(:array :signature "y") (let (result) @@ -897,7 +898,7 @@ dbus-string-to-byte-array (setq result (append result (list :byte elt))))))) =20 (defun dbus-byte-array-to-string (byte-array &optional multibyte) - "Transform BYTE-ARRAY into UTF8 coded string. + "Transform BYTE-ARRAY into UTF-8 coded string. BYTE-ARRAY must be a list of structure (c1 c2 ...), or a byte array as produced by `dbus-string-to-byte-array'. The resulting string is unibyte encoded, unless MULTIBYTE is non-nil." @@ -920,9 +921,9 @@ dbus-escape-as-identifier =20 \"0123abc_xyz\\x01\\xff\" -> \"_30123abc_5fxyz_01_ff\" =20 -i.e. similar to URI encoding, but with \"_\" taking the role of \"%\", -and a smaller allowed set. As a special case, \"\" is escaped to -\"_\". +i.e. similar to URI encoding, but with \"_\" taking the role of +\"%\", and a smaller allowed set. As a special case, \"\" is +escaped to \"_\". =20 Returns the escaped string. Algorithm taken from telepathy-glib's `tp_escape_as_identifier'." @@ -963,8 +964,8 @@ dbus-check-event are the arguments passed to HANDLER, when it is called during event handling in `dbus-handle-event'. =20 -This function raises a `dbus-error' signal in case the event is -not well formed." +This function signals a `dbus-error' if the event is not well +formed." (when dbus-debug (message "DBus-Event %s" event)) (unless (and (listp event) (eq (car event) 'dbus-event) @@ -1038,16 +1039,16 @@ dbus-event-bus-name "Return the bus name the event is coming from. The result is either a Lisp symbol, `:system' or `:session', or a string denoting the bus address. EVENT is a D-Bus event, see -`dbus-check-event'. This function raises a `dbus-error' signal -in case the event is not well formed." +`dbus-check-event'. This function signals a `dbus-error' if the +event is not well formed." (dbus-check-event event) (nth 1 event)) =20 (defun dbus-event-message-type (event) "Return the message type of the corresponding D-Bus message. The result is a number. EVENT is a D-Bus event, see -`dbus-check-event'. This function raises a `dbus-error' signal -in case the event is not well formed." +`dbus-check-event'. This function signals a `dbus-error' if the +event is not well formed." (dbus-check-event event) (nth 2 event)) =20 @@ -1055,41 +1056,40 @@ dbus-event-serial-number "Return the serial number of the corresponding D-Bus message. The result is a number. The serial number is needed for generating a reply message. EVENT is a D-Bus event, see -`dbus-check-event'. This function raises a `dbus-error' signal -in case the event is not well formed." +`dbus-check-event'. This function signals a `dbus-error' if the +event is not well formed." (dbus-check-event event) (nth 3 event)) =20 (defun dbus-event-service-name (event) "Return the name of the D-Bus object the event is coming from. The result is a string. EVENT is a D-Bus event, see `dbus-check-event'. -This function raises a `dbus-error' signal in case the event is -not well formed." +This function signals a `dbus-error' if the event is not well +formed." (dbus-check-event event) (nth 4 event)) =20 (defun dbus-event-path-name (event) "Return the object path of the D-Bus object the event is coming from. The result is a string. EVENT is a D-Bus event, see `dbus-check-event'. -This function raises a `dbus-error' signal in case the event is -not well formed." +This function signals a `dbus-error' if the event is not well +formed." (dbus-check-event event) (nth 5 event)) =20 (defun dbus-event-interface-name (event) "Return the interface name of the D-Bus object the event is coming from. The result is a string. EVENT is a D-Bus event, see `dbus-check-event'. -This function raises a `dbus-error' signal in case the event is -not well formed." +This function signals a `dbus-error' if the event is not well +formed." (dbus-check-event event) (nth 6 event)) =20 (defun dbus-event-member-name (event) "Return the member name the event is coming from. -It is either a signal name or a method name. The result is a +It is either a signal name or a method name. The result is a string. EVENT is a D-Bus event, see `dbus-check-event'. This -function raises a `dbus-error' signal in case the event is not -well formed." +function signals a `dbus-error' if the event is not well formed." (dbus-check-event event) (nth 7 event)) =20 @@ -1097,10 +1097,10 @@ dbus-event-member-name ;;; D-Bus registered names. =20 (defun dbus-list-activatable-names (&optional bus) - "Return the D-Bus service names which can be activated as list. -If BUS is left nil, `:system' is assumed. The result is a list -of strings, which is nil when there are no activatable service -names at all." + "Return a list of the D-Bus service names which can be activated. +BUS defaults to `:system' when nil or omitted. The result is a +list of strings, which is nil when there are no activatable +service names at all." (dbus-ignore-errors (dbus-call-method (or bus :system) dbus-service-dbus @@ -1126,8 +1126,8 @@ dbus-list-known-names =20 (defun dbus-list-queued-owners (bus service) "Return the unique names registered at D-Bus BUS and queued for SERVICE. -The result is a list of strings, or nil when there are no -queued name owners service names at all." +The result is a list of strings, or nil when there are no queued +name owner service names at all." (dbus-ignore-errors (dbus-call-method bus dbus-service-dbus dbus-path-dbus @@ -1144,13 +1144,13 @@ dbus-get-name-owner (defun dbus-ping (bus service &optional timeout) "Check whether SERVICE is registered for D-Bus BUS. TIMEOUT, a nonnegative integer, specifies the maximum number of -milliseconds `dbus-ping' must return. The default value is 25,000. +milliseconds before `dbus-ping' must return. The default value +is 25,000. =20 -Note, that this autoloads SERVICE if it is not running yet. If -it shall be checked whether SERVICE is already running, one shall -apply +Note, that this autoloads SERVICE if it is not running yet. To +check whether SERVICE is already running, you can instead write =20 - (member service \(dbus-list-known-names bus))" + (member service (dbus-list-known-names bus))" ;; "Ping" raises a D-Bus error if SERVICE does not exist. ;; Otherwise, it returns silently with nil. (condition-case nil @@ -1239,11 +1239,11 @@ dbus-introspect-get-interface-names "Return all interface names of SERVICE in D-Bus BUS at object path PATH. It returns a list of strings. =20 -There will be always the default interface -\"org.freedesktop.DBus.Introspectable\". Another default -interface is \"org.freedesktop.DBus.Properties\". If present, -\"interface\" objects can also have \"property\" objects as -children, beside \"method\" and \"signal\" objects." +The default interface \"org.freedesktop.DBus.Introspectable\" is +always present. Another default interface is +\"org.freedesktop.DBus.Properties\". If present, \"interface\" +objects can also have \"property\" objects as children, beside +\"method\" and \"signal\" objects." (let ((object (dbus-introspect-xml bus service path)) result) (dolist (elt (xml-get-children object 'interface) (nreverse result)) @@ -1251,9 +1251,10 @@ dbus-introspect-get-interface-names =20 (defun dbus-introspect-get-interface (bus service path interface) "Return the INTERFACE of SERVICE in D-Bus BUS at object path PATH. -The return value is an XML object. INTERFACE must be a string, -element of the list returned by `dbus-introspect-get-interface-names'. -The resulting \"interface\" object can contain \"method\", \"signal\", +The return value is an XML object. INTERFACE must be a string +and a member of the list returned by +`dbus-introspect-get-interface-names'. The resulting +\"interface\" object can contain \"method\", \"signal\", \"property\" and \"annotation\" children." (let ((elt (xml-get-children (dbus-introspect-xml bus service path) 'interface))) @@ -1273,9 +1274,9 @@ dbus-introspect-get-method-names (push (dbus-introspect-get-attribute elt "name") result)))) =20 (defun dbus-introspect-get-method (bus service path interface method) - "Return method METHOD of interface INTERFACE as XML object. + "Return method METHOD of interface INTERFACE as an XML object. It must be located at SERVICE in D-Bus BUS at object path PATH. -METHOD must be a string, element of the list returned by +METHOD must be a string and a member of the list returned by `dbus-introspect-get-method-names'. The resulting \"method\" object can contain \"arg\" and \"annotation\" children." (let ((elt (xml-get-children @@ -1296,7 +1297,7 @@ dbus-introspect-get-signal-names (push (dbus-introspect-get-attribute elt "name") result)))) =20 (defun dbus-introspect-get-signal (bus service path interface signal) - "Return signal SIGNAL of interface INTERFACE as XML object. + "Return signal SIGNAL of interface INTERFACE as an XML object. It must be located at SERVICE in D-Bus BUS at object path PATH. SIGNAL must be a string, element of the list returned by `dbus-introspect-get-signal-names'. The resulting \"signal\" @@ -1319,9 +1320,9 @@ dbus-introspect-get-property-names (push (dbus-introspect-get-attribute elt "name") result)))) =20 (defun dbus-introspect-get-property (bus service path interface property) - "Return PROPERTY of INTERFACE as XML object. + "Return PROPERTY of INTERFACE as an XML object. It must be located at SERVICE in D-Bus BUS at object path PATH. -PROPERTY must be a string, element of the list returned by +PROPERTY must be a string and a member of the list returned by `dbus-introspect-get-property-names'. The resulting PROPERTY object can contain \"annotation\" children." (let ((elt (xml-get-children @@ -1336,7 +1337,7 @@ dbus-introspect-get-property =20 (defun dbus-introspect-get-annotation-names (bus service path interface &optional name) - "Return all annotation names as list of strings. + "Return all annotation names as a list of strings. If NAME is nil, the annotations are children of INTERFACE, otherwise NAME must be a \"method\", \"signal\", or \"property\" object, where the annotations belong to." @@ -1352,7 +1353,7 @@ dbus-introspect-get-annotation-names =20 (defun dbus-introspect-get-annotation (bus service path interface name annotation) - "Return ANNOTATION as XML object. + "Return ANNOTATION as an XML object. If NAME is nil, ANNOTATION is a child of INTERFACE, otherwise NAME must be the name of a \"method\", \"signal\", or \"property\" object, where the ANNOTATION belongs to." @@ -1374,7 +1375,7 @@ dbus-introspect-get-annotation (car elt))) =20 (defun dbus-introspect-get-argument-names (bus service path interface name) - "Return a list of all argument names as list of strings. + "Return a list of all argument names as a list of strings. NAME must be a \"method\" or \"signal\" object. =20 Argument names are optional, the function can return nil @@ -1388,8 +1389,9 @@ dbus-introspect-get-argument-names =20 (defun dbus-introspect-get-argument (bus service path interface name arg) "Return argument ARG as XML object. -NAME must be a \"method\" or \"signal\" object. ARG must be a string, -element of the list returned by `dbus-introspect-get-argument-names'." +NAME must be a \"method\" or \"signal\" object. ARG must be a +string and a member of the list returned by +`dbus-introspect-get-argument-names'." (let ((elt (xml-get-children (or (dbus-introspect-get-method bus service path interface name) (dbus-introspect-get-signal bus service path interface name)) @@ -1402,7 +1404,7 @@ dbus-introspect-get-argument =20 (defun dbus-introspect-get-signature (bus service path interface name &optional direction) - "Return signature of a `method' or `signal', represented by NAME, as str= ing. + "Return signature of a `method' or `signal' represented by NAME as a str= ing. If NAME is a `method', DIRECTION can be either \"in\" or \"out\". If DIRECTION is nil, \"in\" is assumed. =20 @@ -1450,9 +1452,8 @@ dbus-get-property =20 (defun dbus-set-property (bus service path interface property value) "Set value of PROPERTY of INTERFACE to VALUE. -It will be checked at BUS, SERVICE, PATH. When the value has -been set successful, the result is VALUE. Otherwise, nil is -returned." +It will be checked at BUS, SERVICE, PATH. When the value is +successfully set return VALUE. Otherwise, return nil." (dbus-ignore-errors ;; "Set" requires a variant. (dbus-call-method @@ -1479,15 +1480,15 @@ dbus-get-all-properties (defun dbus-register-property (bus service path interface property access value &optional emits-signal dont-register-service) - "Register property PROPERTY on the D-Bus BUS. + "Register PROPERTY on the D-Bus BUS. =20 BUS is either a Lisp symbol, `:system' or `:session', or a string denoting the bus address. =20 SERVICE is the D-Bus service name of the D-Bus. It must be a -known name (See discussion of DONT-REGISTER-SERVICE below). +known name (see discussion of DONT-REGISTER-SERVICE below). =20 -PATH is the D-Bus object path SERVICE is registered (See +PATH is the D-Bus object path SERVICE is registered at (see discussion of DONT-REGISTER-SERVICE below). INTERFACE is the name of the interface used at PATH, PROPERTY is the name of the property of INTERFACE. ACCESS indicates, whether the property @@ -1625,8 +1626,8 @@ dbus-get-all-managed-objects "Return all objects at BUS, SERVICE, PATH, and the children of PATH. The result is a list of objects. Every object is a cons of an existing path name, and the list of available interface objects. -An interface object is another cons, which car is the interface -name, and the cdr is the list of properties as returned by +An interface object is another cons, whose car is the interface +name and cdr is the list of properties as returned by `dbus-get-all-properties' for that path and interface. Example: =20 \(dbus-get-all-managed-objects :session \"org.gnome.SettingsDaemon\" \"/\") @@ -1782,12 +1783,13 @@ dbus-init-bus the system and session buses, this function is called when loading `dbus.el', there is no need to call it again. =20 -The function returns a number, which counts the connections this Emacs -session has established to the BUS under the same unique name (see -`dbus-get-unique-name'). It depends on the libraries Emacs is linked -with, and on the environment Emacs is running. For example, if Emacs -is linked with the gtk toolkit, and it runs in a GTK-aware environment -like Gnome, another connection might already be established. +The function returns the number of connections this Emacs session +has established to the BUS under the same unique name (see +`dbus-get-unique-name'). It depends on the libraries Emacs is +linked with, and on the environment Emacs is running. For +example, if Emacs is linked with the GTK+ toolkit, and it runs in +a GTK+-aware environment like GNOME, another connection might +already be established. =20 When PRIVATE is non-nil, a new connection is established instead of reusing an existing one. It results in a new unique name at the bus. --=20 2.26.2 --=-=-= Content-Type: text/plain And these implementation cleanups for master: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Various-dbus.el-cleanups.patch >From dad68bc11e6b0a64a733029804f88e0f18a5401c Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Sat, 6 Jun 2020 13:20:06 +0100 Subject: [PATCH] Various dbus.el cleanups * lisp/net/dbus.el: Remove unneeded dependency on cl-lib.el. Quote function symbols as such. (dbus-ignore-errors): Don't add macro name to font-lock keywords, as emacs-lisp-mode now dynamically fontifies new macro definitions. (dbus-call-method-non-blocking): Define as obosolete alias using define-obsolete-function-alias. (dbus-register-signal, dbus-escape-as-identifier): Simplify. Use regexp \` and \' in place of ^ and $. (dbus--parse-xml-buffer): New function for libxml2 compatibility. (dbus-introspect-xml): Use it. (dbus-string-to-byte-array, dbus-byte-array-to-string) (dbus-unescape-from-identifier, dbus-list-known-names) (dbus-introspect-get-all-nodes, dbus-get-all-properties) (dbus-get-all-managed-objects): Simplify. (dbus--introspect-names, dbus--introspect-name): New convenience functions. (dbus-introspect-get-node-names) (dbus-introspect-get-interface-names) (dbus-introspect-get-interface, dbus-introspect-get-method-names) (dbus-introspect-get-method, dbus-introspect-get-signal-names) (dbus-introspect-get-signal, dbus-introspect-get-property-names) (dbus-introspect-get-property) (dbus-introspect-get-annotation-names) (dbus-introspect-get-annotation) (dbus-introspect-get-argument-names, dbus-introspect-get-argument): Use them to DRY. * test/lisp/net/dbus-tests.el (dbus-test-all): Quote function symbols as such. --- lisp/net/dbus.el | 269 +++++++++++++++--------------------- test/lisp/net/dbus-tests.el | 4 +- 2 files changed, 111 insertions(+), 162 deletions(-) diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el index 4538399c75..c882d1ae7a 100644 --- a/lisp/net/dbus.el +++ b/lisp/net/dbus.el @@ -51,9 +51,6 @@ dbus-registered-objects-table (unless (boundp 'dbus-debug) (defvar dbus-debug nil)) -;; Pacify byte compiler. -(eval-when-compile (require 'cl-lib)) - (require 'xml) (defconst dbus-service-dbus "org.freedesktop.DBus" @@ -169,7 +166,6 @@ dbus-ignore-errors `(condition-case err (progn ,@body) (dbus-error (when dbus-debug (signal (car err) (cdr err)))))) -(font-lock-add-keywords 'emacs-lisp-mode '("\\")) (define-obsolete-variable-alias 'dbus-event-error-hooks 'dbus-event-error-functions "24.3") @@ -181,7 +177,7 @@ dbus-event-error-functions ;;; Basic D-Bus message functions. -(defvar dbus-return-values-table (make-hash-table :test 'equal) +(defvar dbus-return-values-table (make-hash-table :test #'equal) "Hash table for temporary storing arguments of reply messages. A key in this hash table is a list (:serial BUS SERIAL), like in `dbus-registered-objects-table'. BUS is either a Lisp symbol, @@ -301,8 +297,8 @@ dbus-call-method (check-interval 0.001) (key (apply - 'dbus-message-internal dbus-message-type-method-call - bus service path interface method 'dbus-call-method-handler args)) + #'dbus-message-internal dbus-message-type-method-call + bus service path interface method #'dbus-call-method-handler args)) (result (cons :pending nil))) ;; Wait until `dbus-call-method-handler' has put the result into @@ -339,8 +335,8 @@ dbus-call-method (remhash key dbus-return-values-table)))) ;; `dbus-call-method' works non-blocking now. -(defalias 'dbus-call-method-non-blocking 'dbus-call-method) -(make-obsolete 'dbus-call-method-non-blocking 'dbus-call-method "24.3") +(define-obsolete-function-alias 'dbus-call-method-non-blocking + #'dbus-call-method "24.3") (defun dbus-call-method-asynchronously (bus service path interface method handler &rest args) @@ -406,7 +402,7 @@ dbus-call-method-asynchronously (or (null handler) (functionp handler) (signal 'wrong-type-argument (list 'functionp handler))) - (apply 'dbus-message-internal dbus-message-type-method-call + (apply #'dbus-message-internal dbus-message-type-method-call bus service path interface method handler args)) (defun dbus-send-signal (bus service path interface signal &rest args) @@ -454,7 +450,7 @@ dbus-send-signal (or (stringp signal) (signal 'wrong-type-argument (list 'stringp signal))) - (apply 'dbus-message-internal dbus-message-type-signal + (apply #'dbus-message-internal dbus-message-type-signal bus service path interface signal args)) (defun dbus-method-return-internal (bus service serial &rest args) @@ -470,7 +466,7 @@ dbus-method-return-internal (or (natnump serial) (signal 'wrong-type-argument (list 'natnump serial))) - (apply 'dbus-message-internal dbus-message-type-method-return + (apply #'dbus-message-internal dbus-message-type-method-return bus service serial args)) (defun dbus-method-error-internal (bus service serial &rest args) @@ -486,7 +482,7 @@ dbus-method-error-internal (or (natnump serial) (signal 'wrong-type-argument (list 'natnump serial))) - (apply 'dbus-message-internal dbus-message-type-error + (apply #'dbus-message-internal dbus-message-type-error bus service serial args)) @@ -552,13 +548,13 @@ dbus-register-service `:already-owner': Service is already the primary owner." ;; Add Peer handler. - (dbus-register-method - bus service nil dbus-interface-peer "Ping" 'dbus-peer-handler 'dont-register) + (dbus-register-method bus service nil dbus-interface-peer "Ping" + #'dbus-peer-handler 'dont-register) ;; Add ObjectManager handler. (dbus-register-method bus service nil dbus-interface-objectmanager "GetManagedObjects" - 'dbus-managed-objects-handler 'dont-register) + #'dbus-managed-objects-handler 'dont-register) (let ((arg 0) reply) @@ -680,7 +676,7 @@ dbus-register-signal (if (and (stringp service) (not (zerop (length service))) (not (string-equal service dbus-service-dbus)) - (not (string-match "^:" service))) + (/= (string-to-char service) ?:)) (setq uname (dbus-get-name-owner bus service)) (setq uname service)) @@ -709,7 +705,7 @@ dbus-register-signal ;; `:arg0' .. `:arg63', `:path0' .. `:path63'. ((and (keywordp key) (string-match - "^:\\(arg\\|path\\)\\([[:digit:]]+\\)$" + "\\`:\\(arg\\|path\\)\\([[:digit:]]+\\)\\'" (symbol-name key))) (setq counter (match-string 2 (symbol-name key)) args (cdr args) @@ -725,9 +721,7 @@ dbus-register-signal "path" "") value)) ;; `:arg-namespace', `:path-namespace'. - ((and (keywordp key) - (string-match - "^:\\(arg\\|path\\)-namespace$" (symbol-name key))) + ((memq key '(:arg-namespace :path-namespace)) (setq args (cdr args) value (car args)) (unless (stringp value) @@ -735,8 +729,7 @@ dbus-register-signal (list "Wrong argument" key value))) (format ",%s='%s'" - (if (string-equal (match-string 1 (symbol-name key)) "path") - "path_namespace" "arg0namespace") + (if (eq key :path-namespace) "path_namespace" "arg0namespace") value)) ;; `:eavesdrop'. ((eq key :eavesdrop) @@ -750,11 +743,11 @@ dbus-register-signal bus dbus-service-dbus dbus-path-dbus dbus-interface-dbus "AddMatch" rule) (dbus-error - (if (not (string-match "eavesdrop" rule)) + (if (not (string-match-p "eavesdrop" rule)) (signal (car err) (cdr err)) ;; The D-Bus spec says we shall fall back to a rule without eavesdrop. (when dbus-debug (message "Removing eavesdrop from rule %s" rule)) - (setq rule (replace-regexp-in-string ",eavesdrop='true'" "" rule)) + (setq rule (replace-regexp-in-string ",eavesdrop='true'" "" rule t t)) (dbus-call-method bus dbus-service-dbus dbus-path-dbus dbus-interface-dbus "AddMatch" rule)))) @@ -892,9 +885,7 @@ dbus-string-to-byte-array STRING shall be UTF8 coded." (if (zerop (length string)) '(:array :signature "y") - (let (result) - (dolist (elt (string-to-list string) (append '(:array) result)) - (setq result (append result (list :byte elt))))))) + (cons :array (mapcan (lambda (c) (list :byte c)) string)))) (defun dbus-byte-array-to-string (byte-array &optional multibyte) "Transform BYTE-ARRAY into UTF8 coded string. @@ -902,12 +893,9 @@ dbus-byte-array-to-string array as produced by `dbus-string-to-byte-array'. The resulting string is unibyte encoded, unless MULTIBYTE is non-nil." (apply - (if multibyte 'string 'unibyte-string) - (if (equal byte-array '(:array :signature "y")) - nil - (let (result) - (dolist (elt byte-array result) - (when (characterp elt) (setq result (append result `(,elt))))))))) + (if multibyte #'string #'unibyte-string) + (unless (equal byte-array '(:array :signature "y")) + (seq-filter #'characterp byte-array)))) (defun dbus-escape-as-identifier (string) "Escape an arbitrary STRING so it follows the rules for a C identifier. @@ -929,9 +917,9 @@ dbus-escape-as-identifier (if (zerop (length string)) "_" (replace-regexp-in-string - "^[0-9]\\|[^A-Za-z0-9]" + "\\`[0-9]\\|[^A-Za-z0-9]" (lambda (x) (format "_%2x" (aref x 0))) - string))) + string nil t))) (defun dbus-unescape-from-identifier (string) "Retrieve the original string from the encoded STRING as unibyte string. @@ -941,7 +929,7 @@ dbus-unescape-from-identifier (replace-regexp-in-string "_.." (lambda (x) (byte-to-string (string-to-number (substring x 1) 16))) - string))) + string nil t))) ;;; D-Bus events. @@ -1019,7 +1007,7 @@ dbus-handle-event (if (eq result :ignore) (dbus-method-return-internal (nth 1 event) (nth 4 event) (nth 3 event)) - (apply 'dbus-method-return-internal + (apply #'dbus-method-return-internal (nth 1 event) (nth 4 event) (nth 3 event) (if (consp result) result (list result))))))) ;; Error handling. @@ -1119,10 +1107,9 @@ dbus-list-names (defun dbus-list-known-names (bus) "Retrieve all services which correspond to a known name in BUS. A service has a known name if it doesn't start with \":\"." - (let (result) - (dolist (name (dbus-list-names bus) (nreverse result)) - (unless (string-equal ":" (substring name 0 1)) - (push name result))))) + (seq-remove (lambda (name) + (= (string-to-char name) ?:)) + (dbus-list-names bus))) (defun dbus-list-queued-owners (bus service) "Return the unique names registered at D-Bus BUS and queued for SERVICE. @@ -1182,6 +1169,18 @@ dbus-peer-handler ;;; D-Bus introspection. +(defsubst dbus--introspect-names (object tag) + "Return the names of the children of OBJECT with TAG." + (mapcar (lambda (elt) + (dbus-introspect-get-attribute elt "name")) + (xml-get-children object tag))) + +(defsubst dbus--introspect-name (object tag name) + "Return the first child of OBJECT with TAG, whose name is NAME." + (seq-find (lambda (elt) + (string-equal (dbus-introspect-get-attribute elt "name") name)) + (xml-get-children object tag))) + (defun dbus-introspect (bus service path) "Return all interfaces and sub-nodes of SERVICE, registered at object path PATH at bus BUS. @@ -1197,17 +1196,25 @@ dbus-introspect bus service path dbus-interface-introspectable "Introspect" :timeout 1000))) +(defalias 'dbus--parse-xml-buffer + (if (libxml-available-p) + (lambda () + (xml-remove-comments (point-min) (point-max)) + (libxml-parse-xml-region (point-min) (point-max))) + (lambda () + (car (xml-parse-region (point-min) (point-max))))) + "Compatibility shim for `libxml-parse-xml-region'.") + (defun dbus-introspect-xml (bus service path) "Return the introspection data of SERVICE in D-Bus BUS at object path PATH. The data are a parsed list. The root object is a \"node\", representing the object path PATH. The root object can contain \"interface\" and further \"node\" objects." - ;; We don't want to raise errors. - (xml-node-name - (ignore-errors - (with-temp-buffer - (insert (dbus-introspect bus service path)) - (xml-parse-region (point-min) (point-max)))))) + (with-temp-buffer + ;; We don't want to raise errors. + (ignore-errors + (insert (dbus-introspect bus service path)) + (dbus--parse-xml-buffer)))) (defun dbus-introspect-get-attribute (object attribute) "Return the ATTRIBUTE value of D-Bus introspection OBJECT. @@ -1219,21 +1226,15 @@ dbus-introspect-get-node-names "Return all node names of SERVICE in D-Bus BUS at object path PATH. It returns a list of strings. The node names stand for further object paths of the D-Bus service." - (let ((object (dbus-introspect-xml bus service path)) - result) - (dolist (elt (xml-get-children object 'node) (nreverse result)) - (push (dbus-introspect-get-attribute elt "name") result)))) + (dbus--introspect-names (dbus-introspect-xml bus service path) 'node)) (defun dbus-introspect-get-all-nodes (bus service path) "Return all node names of SERVICE in D-Bus BUS at object path PATH. It returns a list of strings, which are further object paths of SERVICE." - (let ((result (list path))) - (dolist (elt - (dbus-introspect-get-node-names bus service path) - result) - (setq elt (expand-file-name elt path)) - (setq result - (append result (dbus-introspect-get-all-nodes bus service elt)))))) + (cons path (mapcan (lambda (elt) + (setq elt (expand-file-name elt path)) + (dbus-introspect-get-all-nodes bus service elt)) + (dbus-introspect-get-node-names bus service path)))) (defun dbus-introspect-get-interface-names (bus service path) "Return all interface names of SERVICE in D-Bus BUS at object path PATH. @@ -1244,10 +1245,7 @@ dbus-introspect-get-interface-names interface is \"org.freedesktop.DBus.Properties\". If present, \"interface\" objects can also have \"property\" objects as children, beside \"method\" and \"signal\" objects." - (let ((object (dbus-introspect-xml bus service path)) - result) - (dolist (elt (xml-get-children object 'interface) (nreverse result)) - (push (dbus-introspect-get-attribute elt "name") result)))) + (dbus--introspect-names (dbus-introspect-xml bus service path) 'interface)) (defun dbus-introspect-get-interface (bus service path interface) "Return the INTERFACE of SERVICE in D-Bus BUS at object path PATH. @@ -1255,22 +1253,14 @@ dbus-introspect-get-interface element of the list returned by `dbus-introspect-get-interface-names'. The resulting \"interface\" object can contain \"method\", \"signal\", \"property\" and \"annotation\" children." - (let ((elt (xml-get-children - (dbus-introspect-xml bus service path) 'interface))) - (while (and elt - (not (string-equal - interface - (dbus-introspect-get-attribute (car elt) "name")))) - (setq elt (cdr elt))) - (car elt))) + (dbus--introspect-name (dbus-introspect-xml bus service path) + 'interface interface)) (defun dbus-introspect-get-method-names (bus service path interface) "Return a list of strings of all method names of INTERFACE. SERVICE is a service of D-Bus BUS at object path PATH." - (let ((object (dbus-introspect-get-interface bus service path interface)) - result) - (dolist (elt (xml-get-children object 'method) (nreverse result)) - (push (dbus-introspect-get-attribute elt "name") result)))) + (dbus--introspect-names + (dbus-introspect-get-interface bus service path interface) 'method)) (defun dbus-introspect-get-method (bus service path interface method) "Return method METHOD of interface INTERFACE as XML object. @@ -1278,22 +1268,15 @@ dbus-introspect-get-method METHOD must be a string, element of the list returned by `dbus-introspect-get-method-names'. The resulting \"method\" object can contain \"arg\" and \"annotation\" children." - (let ((elt (xml-get-children - (dbus-introspect-get-interface bus service path interface) - 'method))) - (while (and elt - (not (string-equal - method (dbus-introspect-get-attribute (car elt) "name")))) - (setq elt (cdr elt))) - (car elt))) + (dbus--introspect-name + (dbus-introspect-get-interface bus service path interface) + 'method method)) (defun dbus-introspect-get-signal-names (bus service path interface) "Return a list of strings of all signal names of INTERFACE. SERVICE is a service of D-Bus BUS at object path PATH." - (let ((object (dbus-introspect-get-interface bus service path interface)) - result) - (dolist (elt (xml-get-children object 'signal) (nreverse result)) - (push (dbus-introspect-get-attribute elt "name") result)))) + (dbus--introspect-names + (dbus-introspect-get-interface bus service path interface) 'signal)) (defun dbus-introspect-get-signal (bus service path interface signal) "Return signal SIGNAL of interface INTERFACE as XML object. @@ -1301,22 +1284,15 @@ dbus-introspect-get-signal SIGNAL must be a string, element of the list returned by `dbus-introspect-get-signal-names'. The resulting \"signal\" object can contain \"arg\" and \"annotation\" children." - (let ((elt (xml-get-children - (dbus-introspect-get-interface bus service path interface) - 'signal))) - (while (and elt - (not (string-equal - signal (dbus-introspect-get-attribute (car elt) "name")))) - (setq elt (cdr elt))) - (car elt))) + (dbus--introspect-name + (dbus-introspect-get-interface bus service path interface) + 'signal signal)) (defun dbus-introspect-get-property-names (bus service path interface) "Return a list of strings of all property names of INTERFACE. SERVICE is a service of D-Bus BUS at object path PATH." - (let ((object (dbus-introspect-get-interface bus service path interface)) - result) - (dolist (elt (xml-get-children object 'property) (nreverse result)) - (push (dbus-introspect-get-attribute elt "name") result)))) + (dbus--introspect-names + (dbus-introspect-get-interface bus service path interface) 'property)) (defun dbus-introspect-get-property (bus service path interface property) "Return PROPERTY of INTERFACE as XML object. @@ -1324,15 +1300,9 @@ dbus-introspect-get-property PROPERTY must be a string, element of the list returned by `dbus-introspect-get-property-names'. The resulting PROPERTY object can contain \"annotation\" children." - (let ((elt (xml-get-children - (dbus-introspect-get-interface bus service path interface) - 'property))) - (while (and elt - (not (string-equal - property - (dbus-introspect-get-attribute (car elt) "name")))) - (setq elt (cdr elt))) - (car elt))) + (dbus--introspect-name + (dbus-introspect-get-interface bus service path interface) + 'property property)) (defun dbus-introspect-get-annotation-names (bus service path interface &optional name) @@ -1340,15 +1310,13 @@ dbus-introspect-get-annotation-names If NAME is nil, the annotations are children of INTERFACE, otherwise NAME must be a \"method\", \"signal\", or \"property\" object, where the annotations belong to." - (let ((object - (if name - (or (dbus-introspect-get-method bus service path interface name) - (dbus-introspect-get-signal bus service path interface name) - (dbus-introspect-get-property bus service path interface name)) - (dbus-introspect-get-interface bus service path interface))) - result) - (dolist (elt (xml-get-children object 'annotation) (nreverse result)) - (push (dbus-introspect-get-attribute elt "name") result)))) + (dbus--introspect-names + (if name + (or (dbus-introspect-get-method bus service path interface name) + (dbus-introspect-get-signal bus service path interface name) + (dbus-introspect-get-property bus service path interface name)) + (dbus-introspect-get-interface bus service path interface)) + 'annotation)) (defun dbus-introspect-get-annotation (bus service path interface name annotation) @@ -1356,22 +1324,13 @@ dbus-introspect-get-annotation If NAME is nil, ANNOTATION is a child of INTERFACE, otherwise NAME must be the name of a \"method\", \"signal\", or \"property\" object, where the ANNOTATION belongs to." - (let ((elt (xml-get-children - (if name - (or (dbus-introspect-get-method - bus service path interface name) - (dbus-introspect-get-signal - bus service path interface name) - (dbus-introspect-get-property - bus service path interface name)) - (dbus-introspect-get-interface bus service path interface)) - 'annotation))) - (while (and elt - (not (string-equal - annotation - (dbus-introspect-get-attribute (car elt) "name")))) - (setq elt (cdr elt))) - (car elt))) + (dbus--introspect-name + (if name + (or (dbus-introspect-get-method bus service path interface name) + (dbus-introspect-get-signal bus service path interface name) + (dbus-introspect-get-property bus service path interface name)) + (dbus-introspect-get-interface bus service path interface)) + 'annotation annotation)) (defun dbus-introspect-get-argument-names (bus service path interface name) "Return a list of all argument names as list of strings. @@ -1379,26 +1338,19 @@ dbus-introspect-get-argument-names Argument names are optional, the function can return nil therefore, even if the method or signal has arguments." - (let ((object - (or (dbus-introspect-get-method bus service path interface name) - (dbus-introspect-get-signal bus service path interface name))) - result) - (dolist (elt (xml-get-children object 'arg) (nreverse result)) - (push (dbus-introspect-get-attribute elt "name") result)))) + (dbus--introspect-names + (or (dbus-introspect-get-method bus service path interface name) + (dbus-introspect-get-signal bus service path interface name)) + 'arg)) (defun dbus-introspect-get-argument (bus service path interface name arg) "Return argument ARG as XML object. NAME must be a \"method\" or \"signal\" object. ARG must be a string, element of the list returned by `dbus-introspect-get-argument-names'." - (let ((elt (xml-get-children - (or (dbus-introspect-get-method bus service path interface name) - (dbus-introspect-get-signal bus service path interface name)) - 'arg))) - (while (and elt - (not (string-equal - arg (dbus-introspect-get-attribute (car elt) "name")))) - (setq elt (cdr elt))) - (car elt))) + (dbus--introspect-name + (or (dbus-introspect-get-method bus service path interface name) + (dbus-introspect-get-signal bus service path interface name)) + 'arg arg)) (defun dbus-introspect-get-signature (bus service path interface name &optional direction) @@ -1468,13 +1420,10 @@ dbus-get-all-properties nil is returned." (dbus-ignore-errors ;; "GetAll" returns "a{sv}". - (let (result) - (dolist (dict - (dbus-call-method - bus service path dbus-interface-properties - "GetAll" :timeout 500 interface) - (nreverse result)) - (push (cons (car dict) (cl-caadr dict)) result))))) + (mapcar (lambda (dict) + (cons (car dict) (caadr dict))) + (dbus-call-method bus service path dbus-interface-properties + "GetAll" :timeout 500 interface)))) (defun dbus-register-property (bus service path interface property access value @@ -1519,13 +1468,13 @@ dbus-register-property ;; Add handlers for the three property-related methods. (dbus-register-method bus service path dbus-interface-properties "Get" - 'dbus-property-handler 'dont-register) + #'dbus-property-handler 'dont-register) (dbus-register-method bus service path dbus-interface-properties "GetAll" - 'dbus-property-handler 'dont-register) + #'dbus-property-handler 'dont-register) (dbus-register-method bus service path dbus-interface-properties "Set" - 'dbus-property-handler 'dont-register) + #'dbus-property-handler 'dont-register) ;; Register SERVICE. (unless (or dont-register-service (member service (dbus-list-names bus))) @@ -1672,7 +1621,7 @@ dbus-get-all-managed-objects (if (cadr entry2) ;; "sv". (dolist (entry3 (cadr entry2)) - (setcdr entry3 (cl-caadr entry3))) + (setcdr entry3 (caadr entry3))) (setcdr entry2 nil))))) ;; Fallback: collect the information. Slooow! @@ -1729,7 +1678,7 @@ dbus-managed-objects-handler (append (butlast last-input-event 4) (list object dbus-interface-properties - "GetAll" 'dbus-property-handler)))) + "GetAll" #'dbus-property-handler)))) (dbus-property-handler interface)))) (cdr (assoc object result))))))))) dbus-registered-objects-table) diff --git a/test/lisp/net/dbus-tests.el b/test/lisp/net/dbus-tests.el index e263c4563f..45c9851365 100644 --- a/test/lisp/net/dbus-tests.el +++ b/test/lisp/net/dbus-tests.el @@ -176,8 +176,8 @@ dbus-test03-peer-interface (defun dbus-test-all (&optional interactive) "Run all tests for \\[dbus]." (interactive "p") - (funcall - (if interactive 'ert-run-tests-interactively 'ert-run-tests-batch) "^dbus")) + (funcall (if interactive #'ert-run-tests-interactively #'ert-run-tests-batch) + "^dbus")) (provide 'dbus-tests) ;;; dbus-tests.el ends here -- 2.26.2 --=-=-= Content-Type: text/plain Are these changes acceptable? WDYT? Thanks, -- Basil In GNU Emacs 27.0.91 (build 12, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2020-06-06 built on thunk Repository revision: c1f4c0bc839324d2049ae45a74381684a5727f60 Repository branch: blc/27/dbus Windowing system distributor 'The X.Org Foundation', version 11.0.12008000 System Description: Debian GNU/Linux bullseye/sid Configured using: 'configure 'CC=ccache gcc' 'CFLAGS=-O0 -g3 -ggdb -gdwarf-4' --config-cache --prefix=/home/blc/.local --program-suffix=27 --enable-checking=yes,glyphs --enable-check-lisp-object-type --with-x-toolkit=lucid --with-file-notification=yes --with-x' Configured features: XAW3D XPM JPEG TIFF GIF PNG RSVG SOUND GPM DBUS GSETTINGS GLIB NOTIFY INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11 XDBE XIM MODULES THREADS LIBSYSTEMD JSON PDUMPER LCMS2 GMP --=-=-=--