[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/bluetooth 5a49391b00 07/32: clean up device property ha
From: |
Stefan Kangas |
Subject: |
[elpa] externals/bluetooth 5a49391b00 07/32: clean up device property handling (breaks info view code) |
Date: |
Mon, 3 Jan 2022 15:11:06 -0500 (EST) |
branch: externals/bluetooth
commit 5a49391b0043bc0ff995b4dc1fe916ed0f236b83
Author: Raffael Stocker <r.stocker@mnet-mail.de>
Commit: Raffael Stocker <r.stocker@mnet-mail.de>
clean up device property handling (breaks info view code)
* bluetooth.el (bluetooth--devices): changed name from
bluetooth--get-devices
(bluetooth-device-property): changed name from bluetooth--device-property
(bluetooth--device-properties): removed
---
bluetooth.el | 45 ++++++++++++++++++++-------------------------
1 file changed, 20 insertions(+), 25 deletions(-)
diff --git a/bluetooth.el b/bluetooth.el
index 824f79ffdf..cdd58af108 100644
--- a/bluetooth.el
+++ b/bluetooth.el
@@ -150,9 +150,10 @@ The generated function name has the form
`bluetoothPREFIX-NAME'."
(defun bluetooth--choose-uuid ()
"Ask for a UUID and return it in a form suitable for ‘interactive’."
(if current-prefix-arg
- (let* ((dev-id (tabulated-list-get-id))
+ (let* ((device (gethash (tabulated-list-get-id)
+
bluetooth--device-info))
(uuids (bluetooth--device-uuids
- (bluetooth--device-properties dev-id)))
+ (bluetooth-device-properties device)))
(profile (completing-read "Profile: "
(mapcar (lambda (x)
(concat (caadr x)
@@ -334,36 +335,34 @@ profiles."
;;;; internal functions
-;; This function returns a list of bluetooth adapters and devices
-;; in the form
-;; (("hci0"
-;; ("dev_78_AB_BB_DA_6C_7E" "dev_90_F1_AA_06_24_72")))
-;;
-;; The first element of each (sub-) list is an adapter name, followed
-;; by a list of devices known to this adapter.
(cl-defstruct bluetooth-device
+ "A bluetooth device. This structure holds all the device
+properties."
(id nil :read-only t)
properties)
-(defun bluetooth--device-property (device prop-name)
- (cdr (assoc prop-name (bluetooth-device-properties device))))
+(defun bluetooth-device-property (device prop-name)
+ "Return DEVICE's property PROP-NAME."
+ (cl-rest (assoc prop-name (bluetooth-device-properties device))))
+
(defun bluetooth--adapters ()
"Return a list of bluetooth adapters."
(dbus-introspect-get-node-names
bluetooth-bluez-bus bluetooth--service bluetooth--root))
-(defun bluetooth--get-devices ()
+;; TODO don't return the adapter names, as they are in the devices?
+;; do this per adapter?
+(defun bluetooth--devices ()
"Return a list of bluetooth adapters and devices connected to them."
(mapcar (lambda (a)
(list a (dbus-introspect-get-node-names
bluetooth-bluez-bus bluetooth--service
(concat bluetooth--root "/" a))))
- (dbus-introspect-get-node-names
- bluetooth-bluez-bus bluetooth--service bluetooth--root)))
+ (bluetooth--adapters)))
(defun bluetooth--dev-state (key device)
"Return state information regarding KEY for DEVICE."
- (let ((value (bluetooth--device-property device key)))
+ (let ((value (bluetooth-device-property device key)))
(cond ((stringp value) value)
((null value) "no")
(t "yes"))))
@@ -391,6 +390,7 @@ NOTE: the strings MUST correspond to Bluez device properties
as they are used to gather the information from Bluez.")
(defun bluetooth--create-device (adapter dev-id)
+ "Create a bluetooth device struct for DEV-ID on ADAPTER."
(let* ((path (mapconcat #'identity
(list bluetooth--root adapter
dev-id)
"/"))
@@ -401,15 +401,15 @@ as they are used to gather the information from Bluez.")
:device bluetooth--interfaces))))
(make-bluetooth-device :id dev-id :properties props)))
-
(defun bluetooth--update-device-info ()
+ "Update the bluetooth devices list."
(mapc (lambda (devlist)
(mapc (lambda (dev)
(puthash dev
(bluetooth--create-device
(cl-first devlist) dev)
bluetooth--device-info))
(cl-second devlist)))
- (bluetooth--get-devices)))
+ (bluetooth--devices)))
;; This function provides the list entries for the tabulated-list
;; view. It is called from `tabulated-list-print'.
@@ -455,11 +455,12 @@ as they are used to gather the information from Bluez.")
do (forward-line 1)
collect (cons (elt entry 0) pos)))
+;; TODO operate on device structs, not ids
(defun bluetooth--call-method (dev-id api function &rest args)
"For DEV-ID, invoke D-Bus FUNCTION on API, passing ARGS."
(let ((path (cond ((and (eq :device api)
(not (null dev-id)))
- (concat (bluetooth--device-property
+ (concat (bluetooth-device-property
(gethash dev-id
bluetooth--device-info)
"Adapter")
"/" dev-id))
@@ -588,12 +589,6 @@ adapter reported by Bluez."
(alist-get
:adapter
bluetooth--interfaces)))))
-(defun bluetooth--device-properties (dev-id)
- "Return all properties of device DEV-ID."
- (bluetooth--call-method
- (car (last (split-string dev-id "/"))) :device
- #'dbus-get-all-properties))
-
(defun bluetooth--device-uuids (properties)
"Extract a UUID alist from device PROPERTIES.
Each list element contains a UUID as the key and the
@@ -648,7 +643,7 @@ scanning the bus, displaying device info etc."
(declare (indent defun))
`(let* ((dev (gethash (car (last (split-string ,device "/")))
bluetooth--device-info))
- (alias (or (bluetooth--device-property dev "Alias")
+ (alias (or (bluetooth-device-property dev "Alias")
(replace-regexp-in-string "_" ":" dev
nil nil nil 4))))
,@body))
- [elpa] externals/bluetooth 6aebc228b5 02/32: fix a typo in the info display, (continued)
- [elpa] externals/bluetooth 6aebc228b5 02/32: fix a typo in the info display, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 72cb48584f 01/32: widen address field in tab view to accommodate var-pitch fonts, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 3d0fe7ed9d 09/32: use a struct for the adapter property display in the mode line, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth ada89f2faa 10/32: clean up the signal handler function, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth f971b21d66 03/32: use a structure and hash table for device-info, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 8edeb34f61 05/32: add bluetooth--adapter-properties function, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth bd95b1ca0b 15/32: revert to mapc instead of --map when used for side-effects only, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 273306e1e0 25/32: update the list view more intelligently, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 9878aa8051 14/32: add adapter parameters in adapter-properties and devices functions, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth f2d43ebab5 16/32: make bluetooth--choose-uuid somewhat more readable, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 5a49391b00 07/32: clean up device property handling (breaks info view code),
Stefan Kangas <=
- [elpa] externals/bluetooth 0627cceab3 08/32: clean up the info view code and add an adapter info view, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth f75ac5e43d 11/32: clean up the method registration function, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth e69e4151ff 12/32: clean things up for readability, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth a411243fbe 17/32: add a function for bluetooth device info access, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 7a78351220 19/32: set tabulated-list-padding to 0, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 1f048b5949 20/32: clean up and drop multiple adapter plans, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth fa3761da3c 21/32: add timer to periodically update the device table in discovery mode, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth c75d2e3495 22/32: handle removal of devices in list view, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth ddad595699 23/32: move command definitions to bottom of file, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 1254ec44d2 24/32: add signal handlers for paired devices, Stefan Kangas, 2022/01/03