6 #include "../linux/event.h"
18 #define IN_MAX_DEVS 10
20 static in_dev_t in_devices[IN_MAX_DEVS];
21 static int in_dev_count = 0;
23 static int in_bind_count(int drv_id)
27 if (drv_id == IN_DRVID_EVDEV)
28 count = in_evdev_bind_count();
31 printf("input: failed to get bind count for drv %d\n", drv_id);
36 static int *in_alloc_binds(int drv_id)
40 count = in_bind_count(drv_id);
42 printf("input: failed to get bind count for drv %d\n", drv_id);
46 ret = malloc(count * sizeof(*ret));
50 static void in_free(in_dev_t *dev)
54 if (dev->drv_id == IN_DRVID_EVDEV)
55 in_evdev_free(dev->drv_data);
66 /* to be called by drivers */
67 void in_register(const char *nname, int drv_id, void *drv_data)
69 int i, dupe_count = 0, *binds;
70 char name[256], *name_end, *tmp;
72 strncpy(name, nname, sizeof(name));
73 name[sizeof(name)-12] = 0;
74 name_end = name + strlen(name);
76 for (i = 0; i < in_dev_count; i++)
78 if (in_devices[i].name == NULL)
80 if (strcmp(in_devices[i].name, name) == 0)
82 if (in_devices[i].probed) {
84 sprintf(name_end, " [%d]", dupe_count);
93 /* try to find unused device */
94 for (i = 0; i < IN_MAX_DEVS; i++)
95 if (!in_devices[i].probed) break;
96 if (i >= IN_MAX_DEVS) {
97 printf("input: too many devices, can't add %s\n", name);
100 in_free(&in_devices[i]);
107 binds = in_alloc_binds(drv_id);
113 in_devices[i].name = tmp;
114 in_devices[i].binds = binds;
115 if (i + 1 > in_dev_count)
116 in_dev_count = i + 1;
118 printf("input: new device #%d \"%s\"\n", i, name);
120 in_devices[i].probed = 1;
121 in_devices[i].drv_id = drv_id;
122 in_devices[i].drv_data = drv_data;
128 for (i = 0; i < in_dev_count; i++)
129 in_devices[i].probed = 0;
135 /* get rid of devs without binds and probes */
136 for (i = 0; i < in_dev_count; i++) {
137 if (!in_devices[i].probed && in_devices[i].binds == NULL) {
139 if (i < in_dev_count) {
140 free(in_devices[i].name);
141 memmove(&in_devices[i], &in_devices[i+1],
142 (in_dev_count - i) * sizeof(in_devices[0]));
148 void in_clear_binds(const char *devname)
152 count = in_bind_count(drv_id);
154 printf("input: failed to get bind count for drv %d\n", dev->drv_id);
164 for (i = 0; i < in_dev_count; i++) {
165 if (in_devices[i].probed && in_devices[i].binds != NULL) {
167 result |= in_evdev_update(in_devices[i].drv_data, in_devices[i].binds);
177 memset(in_devices, 0, sizeof(in_devices));