## **************************************************************************
## For copyright and licensing terms, see the file named COPYING.
## **************************************************************************

# The old Mewburn rc has linkage from devd to various services for HIDs.
# These rules replace the Mewburn rc linkage with linkage to nosh services.

# USB web cameras spin up instances of the webcamd service.

notify 102 {
	match "system"		"USB";
	match "subsystem"	"INTERFACE";
	match "type"		"ATTACH";
	match "intclass"	"0x0e";
	action "cd /run/service-bundles && /etc/service-bundles/generators/generate $cdev webcamd && /etc/service-bundles/generators/spin-up $cdev webcamd";
};

notify 102 {
	match "system"		"USB";
	match "subsystem"	"INTERFACE";
	match "type"		"DETACH";
	match "intclass"	"0x0e";
	action "cd /run/service-bundles && /etc/service-bundles/generators/spin-down $cdev webcamd";
};

# Mice spin up two things, controlled by -run- package presets:
#  * Instances of the old moused service that feed mice to /dev/sysmouse .
#  * Instances of the new console-pcat-mouse-realizer that feed mice to user-space VTs.
#
# USB mouse devices and real PS/2 mouse devices are created by the kernel.
# Virtual PC/AT mouse devices are created by uhidd.
# uhidd should not be preset on when user-space VTs are being realized.
#
# The sysmouse concentrator is not handled by devd so needs a static instance of the service.

attach 102 {
	match "bus" "atkbdc[0-9]+";
	match "device-name" "psm[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/generate $device-name moused && /etc/service-bundles/generators/spin-up $device-name moused";
	# Yes the "b" prefix is intentional.
	# psmN is non-blocking, bpsmN blocking; and O_NONBLOCK is ignored.
	action "cd /run/service-bundles && /etc/service-bundles/generators/generate b$device-name console-pcat-mouse-realizer && /etc/service-bundles/generators/spin-up b$device-name console-pcat-mouse-realizer";
};
notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "CREATE";
	match "cdev" "ums[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/generate $cdev moused console-pcat-mouse-realizer && /etc/service-bundles/generators/spin-up $cdev moused console-pcat-mouse-realizer";
};
notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "CREATE";
	match "cdev" "atp[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/generate $cdev moused console-pcat-mouse-realizer && /etc/service-bundles/generators/spin-up $cdev moused console-pcat-mouse-realizer";
};
notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "CREATE";
	match "cdev" "wsp[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/generate $cdev moused console-pcat-mouse-realizer && /etc/service-bundles/generators/spin-up $cdev moused console-pcat-mouse-realizer";
};

detach 102 {
	match "bus" "atkbdc[0-9]+";
	match "device-name" "psm[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/spin-down $device-name moused";
	# Yes the "b" prefix is intentional; see earlier.
	action "cd /run/service-bundles && /etc/service-bundles/generators/spin-down b$device-name console-pcat-mouse-realizer";
};
notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "DESTROY";
	match "cdev" "ums[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/spin-down $cdev moused console-pcat-mouse-realizer";
};
notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "DESTROY";
	match "cdev" "atp[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/spin-down $cdev moused console-pcat-mouse-realizer";
};
notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "DESTROY";
	match "cdev" "wsp[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/spin-down $cdev moused console-pcat-mouse-realizer";
};

# Keyboards spin up one thing, controlled by -run- package presets:
#  * Instances of the new console-pcat-keyboard-realizer that feed keyboards to user-space VTs.
#
# USB keyboard devices and real PS/2 keyboard devices are created by the kernel.
# Virtual keyboard devices are created by uhidd and our various realizers.
# uhidd should not be preset on when user-space VTs are being realized.
#
# The kbdmux concentrator is not handled by devd so needs a static instance of the service.

notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "CREATE";
	match "cdev" "atkbd[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/generate $cdev console-pcat-kbd-realizer && /etc/service-bundles/generators/spin-up $cdev console-pcat-kbd-realizer";
};
notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "CREATE";
	match "cdev" "ukbd[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/generate $cdev console-pcat-kbd-realizer && /etc/service-bundles/generators/spin-up $cdev console-pcat-kbd-realizer";
};

notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "DESTROY";
	match "cdev" "atkbd[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/spin-down $cdev console-pcat-kbd-realizer";
};
notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "DESTROY";
	match "cdev" "ukbd[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/spin-down $cdev console-pcat-kbd-realizer";
};

# Generic USB devices spin up two things, controlled by -run- package presets:
#  * Instances of the old uhidd service that create old PC/AT keyboard and mouse virtual devices.
#  * Instances of the new console-ugen-hid-realizer that feed Generic USB to user-space VTs.

notify 102 {
	match "system" "USB";
	match "subsystem" "INTERFACE";
	match "type" "ATTACH";
	match "cdev" "ugen[0-9]+.[0-9]+";
	match "intclass" "0x03";
	action "cd /run/service-bundles && /etc/service-bundles/generators/generate $cdev uhidd console-ugen-hid-realizer && /etc/service-bundles/generators/spin-up $cdev uhidd console-ugen-hid-realizer";
};

notify 102 {
	match "system" "USB";
	match "subsystem" "INTERFACE";
	match "type" "DETACH";
	match "cdev" "ugen[0-9]+.[0-9]+";
	match "intclass" "0x03";
	action "cd /run/service-bundles && /etc/service-bundles/generators/spin-down $cdev uhidd console-ugen-hid-realizer";
};

# USB HID devices spin up one thing, controlled by -run- package presets:
#  * Instances of the new console-uhid-realizer that feed USB HID to user-space VTs.
#
# USB HID devices are created by either the kernel or uhidd.
# uhidd should not be preset on when user-space VTs are being realized.

notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "CREATE";
	match "cdev" "uv?hid[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/generate $cdev console-uhid-realizer && /etc/service-bundles/generators/spin-up $cdev console-uhid-realizer";
};

notify 102 {
	match "system" "DEVFS";
	match "subsystem" "CDEV";
	match "type" "DESTROY";
	match "cdev" "uv?hid[0-9]+";
	action "cd /run/service-bundles && /etc/service-bundles/generators/spin-down $cdev console-uhid-realizer";
};
