samples/hid/hid_mouse.c

Source file repositories/reference/linux-study-clean/samples/hid/hid_mouse.c

File Facts

System
Linux kernel
Corpus path
samples/hid/hid_mouse.c
Extension
.c
Size
2958 bytes
Lines
139
Domain
Support Tooling And Documentation
Bucket
samples
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

switch (opt) {
		default:
			usage(basename(argv[0]));
			return 1;
		}
	}

	if (optind == argc) {
		usage(basename(argv[0]));
		return 1;
	}

	sysfs_path = argv[optind];
	if (!sysfs_path) {
		perror("sysfs");
		return 1;
	}

	skel = hid_mouse__open();
	if (!skel) {
		fprintf(stderr, "%s  %s:%d", __func__, __FILE__, __LINE__);
		return -1;
	}

	hid_id = get_hid_id(sysfs_path);

	if (hid_id < 0) {
		fprintf(stderr, "can not open HID device: %m\n");
		return 1;
	}
	skel->struct_ops.mouse_invert->hid_id = hid_id;

	err = hid_mouse__load(skel);
	if (err < 0) {
		fprintf(stderr, "can not load HID-BPF program: %m\n");
		return 1;
	}

	link = bpf_map__attach_struct_ops(skel->maps.mouse_invert);
	if (!link) {
		fprintf(stderr, "can not attach HID-BPF program: %m\n");
		return 1;
	}

	signal(SIGINT, int_exit);
	signal(SIGTERM, int_exit);

	while (running)
		sleep(1);

	hid_mouse__destroy(skel);

	return 0;
}

Annotation

Implementation Notes