#!%GUILE% --no-auto-compile -*- scheme -*- !# ;;;; This file is part of Guile Netlink ;;;; ;;;; Copyright (C) 2025 Dale Mellor ;;;; ;;;; This library is free software: you can redistribute it and/or modify ;;;; it under the terms of the GNU General Public License as published by ;;;; the Free Software Foundation, either version 3 of the License, or ;;;; (at your option) any later version. ;;;; ;;;; This library is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;;; GNU General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU General Public License ;;;; along with this library. If not, see . (unless (getenv "NETLINK_UNINSTALLED") (set! %load-path (cons "%modsrcdir%" %load-path)) (set! %load-compiled-path (cons "%modbuilddir%" %load-compiled-path))) ;; This is both an example of use of guile-netlinkʼs ACPI notifications ;; interface‒it being the simplest such application that we can think of‒, and ;; a useful diagnostic tool in its own right to help fathom the meaning of the ;; messages coming out of the Linux kernel, as these are not at all well ;; documented and depend critically on the nature of the physical computer ;; system and the kernel build configuration. ;; ;; There are no command-line arguments; the program will simply sit and listen ;; for kernel ACPI events to be broadcast, and then report the data returned ;; on the screen. It is left as an exercise to the end user (hah!) to work ;; out the actual meanings of these data. ;; Use guile-netlinkʼs ACPI interface. The use of a prefix is discretionary; ;; it is useful to have in example code. (use-modules ((netlink acpi) #:prefix ACPI::)) (define (event-action event) "Print the contents of the EVENT object in a line on the screen." ((@ (ice-9 format) format) #t "device: ~20a, bus ID: ~15a, type: ~8,'0x, data: ~8,'0x\n" (ACPI::event-device-class event) (ACPI::event-bus-id event) (ACPI::event-kind event) (ACPI::event-data event))) ;; Connect to the kernelʼs Netlink ACPI notifier and obtain the three control ;; procedures for this connection. ((@ (ice-9 receive) receive) (ACPI::read-selector ACPI::process-events ACPI::close-connection) (ACPI::connect-events) ;; In a tight loop use the first procedure in a (select _) call to wait ;; for data from the connection, then use the second procedure to actually ;; read and interpret those data and call the above event-action function ;; on any ACPI event data found there. (let loop () (select (list (ACPI::read-selector)) '() '()) (ACPI::process-events event-action) (loop)) ;; We wonʼt ever get here, but if for some reason we did... use the third ;; procedure given us from the connection to shut that connection down. (ACPI::close-connection))