Extend the input service beyond the keyboard so mouse and joystick/gamepad drivers can broadcast too, with per-device publish and subscribe methods. - protocol: KeyEvent joins MouseEvent (motion/buttons/scroll) and JoystickEvent (axes/buttons), all carried in a common InputEvent envelope tagged with a DeviceKind. A subscribe request carries a device_mask, so a subscriber names the classes it wants and the service routes each event only to interested subscribers (a mouse-only listener never wakes for keystrokes). - runtime: per-device publish methods (publishKeyboardEvent/publishMouseEvent/ publishJoystickEvent) and subscribe helpers (subscribeKeyboard/Mouse/Joystick, each typed, plus subscribe(mask)/subscribeAll returning the tagged envelope). - service: subscriber table gains a device_mask; broadcast routes by the event's device class. - mouse driver now publishes (synthetic) mouse events like the keyboard driver; input-source cycles all three classes; input-test subscribes to all and only emits its "ok" marker once it has received one of each class — so the passing test proves per-device routing, not just delivery. Real HID decoding stays a follow-up. No kernel changes: ipc_send is generic and the 36-byte InputEvent fits its 64-byte payload. Full QEMU suite 48/48; serial log confirms keyboard, mouse, and joystick all reach one subscription.
57 lines
2.5 KiB
Zig
57 lines
2.5 KiB
Zig
//! system/services/input-test — the input service's client and test oracle, the input
|
|
//! counterpart of vfs-test. It subscribes to *all* device classes and loops receiving the
|
|
//! events a source broadcasts, logging each with its class. It emits the success marker
|
|
//! `"input-test: ok"` only **after it has received at least one of each class** (keyboard,
|
|
//! mouse, and joystick), then heartbeats it. So the in-kernel `input` test case seeing that
|
|
//! marker proves not just that IPC delivery works but that the service *routed* all three
|
|
//! device classes to one subscription — source -> service -> subscriber, per device.
|
|
|
|
const std = @import("std");
|
|
const runtime = @import("runtime");
|
|
const input = runtime.input;
|
|
const system = runtime.system;
|
|
|
|
fn writeLine(comptime fmt: []const u8, arguments: anytype) void {
|
|
var line: [128]u8 = undefined;
|
|
_ = system.write(std.fmt.bufPrint(&line, fmt, arguments) catch return);
|
|
}
|
|
|
|
pub fn main() void {
|
|
var listener = input.subscribeAll() orelse {
|
|
_ = system.write("input-test: could not subscribe\n");
|
|
return;
|
|
};
|
|
_ = system.write("input-test: subscribed\n");
|
|
|
|
var seen_keyboard = false;
|
|
var seen_mouse = false;
|
|
var seen_joystick = false;
|
|
while (true) {
|
|
const event = listener.next() orelse continue;
|
|
// Decode the class-specific payload from the tagged envelope and note the class.
|
|
if (event.asKeyboard()) |key| {
|
|
seen_keyboard = true;
|
|
writeLine("input-test: got keyboard code={d} char={d}\n", .{ key.keycode, key.character });
|
|
} else if (event.asMouse()) |mouse| {
|
|
seen_mouse = true;
|
|
writeLine("input-test: got mouse dx={d} dy={d} buttons={d}\n", .{ mouse.dx, mouse.dy, mouse.buttons });
|
|
} else if (event.asJoystick()) |joystick| {
|
|
seen_joystick = true;
|
|
writeLine("input-test: got joystick control={d} value={d}\n", .{ joystick.control, joystick.value });
|
|
} else {
|
|
writeLine("input-test: got device={d}\n", .{event.device});
|
|
}
|
|
|
|
// The success marker: only once every class has been routed here does this appear,
|
|
// and then it heartbeats. Seeing "input-test: ok" proves per-device fan-out works.
|
|
if (seen_keyboard and seen_mouse and seen_joystick) {
|
|
_ = system.write("input-test: ok all classes received (keyboard, mouse, joystick)\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
pub const panic = runtime.panic;
|
|
comptime {
|
|
_ = &runtime.start._start;
|
|
}
|