-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_input_handler.c~
47 lines (47 loc) · 1.25 KB
/
simple_input_handler.c~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <linux/config.h>
#include <linux/input.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/module.h>
static struct input_handler printdev_handler;
void printdev_event(struct input_handle *handle, unsigned int type,
unsigned int code, int down)
{
printk(KERN_INFO "device: %p, type: %d, code: %d, value: %d",
handle->dev, type, code, value);
}
static struct input_handle *printdev_connect(struct input_handler *handler,
struct input_dev *dev)
{
struct input_handle *handle;
if (!test_bit(EV_KEY, dev->evbit))
return NULL;
if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL)))
return NULL;
memset(handle, 0, sizeof(struct input_handle));
handle->dev = dev;
handle->handler = handler;
input_open_device(handle);
return handle;
}
static void printdev_disconnect(struct input_handle *handle)
{
input_close_device(handle);
kfree(handle);
}
static struct input_handler printdev_handler = {
event: printdev_event,
connect: printdev_connect,
disconnect: printdev_disconnect,
};
static int __init printdev_init(void)
{
input_register_handler(&printdev_handler);
return 0;
}
static void __exit printdev_exit(void)
{
input_unregister_handler(&printdev_handler);
}
module_init(printdev_init);
module_exit(printdev_exit);