Hotplug event example
This example shows how to trigger hotplug events when some hotpluggable device is attached or removed from the system.
Currently only FreeBSD's hotplug system is supported.
Compilation
Easiest way to get this example running is to go to examples directory in package root, and run:
$ ./build.sh hotplug_events
build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.
Preview
; ------------------------------------------------------------------------------
; hotplug_events.ano
;
; To compile:
;
; $ ./build/ano ./examples/hotplug_events/hotplug_events.ano > \
; engine/dsl_ano.h
; ------------------------------------------------------------------------------
;
; @ANO_SCRIPT_NAME hotplug_events
; @ANO_SCRIPT_VERSION 0.0.1
; @ANO_SCRIPT_DESCRIPTION Simple hotplug event example
;
; @ANO_FLAGS_USE_PROTOS [ ]
; @ANO_FLAGS_VAR_NAME_SUBS [ ]
; @ANO_FLAGS_VAR_WARN_UNUSED [ ]
;
; Copyright © 2016-2026, Jani Salonen <salojan@goto10.co>
; All rights reserved.
;
; This example shows how to trigger hotplug events when some hotpluggable
; device is attached or removed from the system.
;
; Currently only FreeBSD's hotplug system is supported.
;
main {
; Initialize hotplug notifications if it is enabled.
;
hotplug_enabled {
hotplug_init (\
cb_attach: "hp_attach", \
cb_detach: "hp_detach", \
cb_notify: "hp_notify")
print "Now attach or remove some USB device for example to" \
" see callback doing its\nwork.\n"
print "Waiting for inotify events, "
}
print "press <ctrl-c> to break.\n"
}
_HOTPLUG_EVENT_ callback hp_attach (_hnd, _key, _val) {
; Hotplug device attached.
;
print "Device attached, details below:\n"
dump _hnd
dump _key
dump _val
print "\n"
}
_HOTPLUG_EVENT_ callback hp_detach (_hnd, _key, _val) {
; Hotplug device detached.
;
print "Device detached, details below:\n"
dump _hnd
dump _key
dump _val
print "\n"
}
_HOTPLUG_EVENT_ callback hp_notify (_hnd, _key, _val) {
; Hotplug device notify.
;
print "Device notification, details below:\n"
dump _hnd
dump _key
dump _val
print "\n"
}
; ------------------------------------------------------------------------------ ; hotplug_events.w2c ; ; To compile: ; ; $ ./build/widget ./examples/hotplug_events/hotplug_events.w2c > \ ; engine/widget_defs.h ; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------ ; hotplug_events.m2c ; ; To compile: ; ; $ ./build/menu ./examples/hotplug_events/hotplug_events.m2c > \ ; engine/menu_defs.h ; ------------------------------------------------------------------------------
Copyright © 2026, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.