devout: support search for sysfs attributes

This commit is contained in:
Daniel Barlow 2024-06-01 21:20:41 +01:00
parent 7d00b39249
commit 19aba0d873
1422 changed files with 1505 additions and 22 deletions

View File

@ -26,10 +26,27 @@
(string.format "%s=%s" (string.upper k) v ))
"\n")))
(fn attrs-match? [event expected]
(accumulate [match? true
name value (pairs expected)]
(and match? (= value (event:attr name)))))
(fn event-matches? [e terms]
(accumulate [match? true
name value (pairs terms)]
(and match? (= value (. e.properties name)))))
(and match?
(case name
:attr (attrs-match? e value)
:attrs true
other (= value (. e.properties name))))))
(fn read-if-exists [pathname]
(match (ll.open pathname 0 0)
fd (let [s (ll.read fd 4096)
s1 (string.gsub s "[ \n]*(.-)[ \n]*" "%1")]
(ll.close fd)
s1)
nil nil))
(fn parse-event [s]
(let [at (string.find s "@" 1 true)
@ -44,6 +61,8 @@
:action (string.sub s 1 (- at 1))
:format format-event
:matches? event-matches?
:attr (fn [self name]
(read-if-exists (.. self.sys-path "/" self.path "/" name)))
}))
(fn find-in-database [db terms]
@ -53,24 +72,28 @@
(doto found (table.insert e))
found)))
(fn record-event [db subscribers str]
(let [e (parse-event str)]
(match e.action
:add (tset db e.path e)
:change (tset db e.path e)
;; should we do something for bind?
:remove (tset db e.path nil)
)
(each [_ { : terms : callback } (pairs subscribers)]
(if (e:matches? terms) (callback e)))
e))
(fn record-event [db subscribers e]
(match e.action
:add (tset db e.path e)
:change (tset db e.path e)
;; should we do something for bind?
:remove (tset db e.path nil)
)
(each [_ { : terms : callback } (pairs subscribers)]
(if (e:matches? terms) (callback e)))
e)
(fn database []
(fn database [options]
(let [db {}
subscribers []]
subscribers []
{ : sys-path } (or options {:sysfs-path "/sys" })]
{
:find (fn [_ terms] (find-in-database db terms))
:add (fn [_ event-string] (when event-string (record-event db subscribers event-string)))
:add (fn [_ event-string]
(when event-string
(let [e (doto (parse-event event-string)
(tset :sys-path sys-path))]
(record-event db subscribers e))))
:at-path (fn [_ path] (. db path))
:subscribe (fn [_ id callback terms]
(let [past-events (find-in-database db terms)]
@ -146,13 +169,7 @@
:_tbl #(do fds) ;exposed for tests
}))
(fn read-if-exists [pathname]
(match (ll.open pathname 0 0)
fd (let [s (ll.read fd 4096)
s1 (string.gsub s "[ \n]*(.-)[ \n]*" "%1")]
(ll.close fd)
s1)
nil nil))
(fn sysfs [fspath]
{

View File

@ -0,0 +1 @@
0x0c0330

View File

@ -0,0 +1 @@
0x9d2f

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
platform:intel_xhci_usb_sw

View File

@ -0,0 +1,2 @@
DRIVER=intel_xhci_usb_sw
MODALIAS=platform:intel_xhci_usb_sw

View File

@ -0,0 +1,2 @@
DEVTYPE=usb_role_switch
USB_ROLE_SWITCH=intel_xhci_usb_sw-role-switch

View File

@ -0,0 +1 @@
131

View File

@ -0,0 +1 @@
pci:v00008086d00009D2Fsv000017AAsd00002238bc0Csc03i30

View File

@ -0,0 +1,13 @@
poolinfo - 0.1
buffer-2048 0 0 2048 0
buffer-512 0 0 512 0
buffer-128 0 32 128 1
buffer-32 0 0 32 0
xHCI 1KB stream ctx arrays 0 0 1024 0
xHCI 256 byte stream ctx arrays 0 0 256 0
xHCI input/output contexts 6 11 2112 11
xHCI ring segments 26 42 4096 42
buffer-2048 0 0 2048 0
buffer-512 0 0 512 0
buffer-128 0 32 128 1
buffer-32 0 0 32 0

View File

@ -0,0 +1 @@
enabled

View File

@ -0,0 +1 @@
enabled

View File

@ -0,0 +1,13 @@
0x00000000e1320000 0x00000000e132ffff 0x0000000000140204
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000

View File

@ -0,0 +1 @@
0x21

View File

@ -0,0 +1,6 @@
DRIVER=xhci_hcd
PCI_CLASS=C0330
PCI_ID=8086:9D2F
PCI_SUBSYS_ID=17AA:2238
PCI_SLOT_NAME=0000:00:14.0
MODALIAS=pci:v00008086d00009D2Fsv000017AAsd00002238bc0Csc03i30

View File

@ -0,0 +1 @@
usb:v1D6Bp0002d0601dc09dsc00dp01ic09isc00ip00in00

View File

@ -0,0 +1,6 @@
DEVTYPE=usb_interface
DRIVER=hub
PRODUCT=1d6b/2/601
TYPE=9/0/1
INTERFACE=9/0/0
MODALIAS=usb:v1D6Bp0002d0601dc09dsc00dp01ic09isc00ip00in00

Some files were not shown because too many files have changed in this diff Show More