modem.fnl (1235B)
1 (local { : GLib } (require :lgi)) 2 (local dbus (require :dbus_proxy)) 3 (local { : view } (require :fennel)) 4 (local GV GLib.Variant) 5 (local variant dbus.variant) 6 7 ;; https://www.freedesktop.org/software/ModemManager/api/latest/ref-dbus.html 8 9 (fn modem-manager [] 10 (dbus.Proxy:new 11 { 12 :bus dbus.Bus.SYSTEM 13 :name "org.freedesktop.ModemManager1" 14 :interface "org.freedesktop.DBus.ObjectManager" 15 :path "/org/freedesktop/ModemManager1" 16 })) 17 18 ;; this is a function because the path to the modem may change 19 ;; (e.g. due to suspend/resume cycles causing services to be stopped 20 ;; and started) 21 22 (fn modem-interface [manager] 23 (let [modem-path (next (: (assert manager) :GetManagedObjects))] 24 (dbus.Proxy:new 25 { 26 :bus dbus.Bus.SYSTEM 27 :name "org.freedesktop.ModemManager1" 28 :interface "org.freedesktop.ModemManager1.Modem.Simple" 29 :path modem-path 30 }))) 31 32 (fn new-modem-status [] 33 (let [manager (modem-manager)] 34 { 35 :read #(let [m (modem-interface manager)] 36 (variant.strip (m:GetStatus))) 37 })) 38 39 (comment 40 (let [ctx (: (GLib.MainLoop) :get_context) 41 s (new-modem-status)] 42 (while true 43 (ctx:iteration) 44 (print (view (s:value) ))))) 45 46 { :new new-modem-status }