summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2014-09-23 15:11:43 -0400
committerChris Michael <cp.michael@samsung.com>2014-09-23 15:31:12 -0400
commita0395b07c5b51fff61ec4b2e62bbe12fd2badd8f (patch)
treea721a04ac61d930bc6e4e376c8b482d88eb01ece
parent777e64fea540f85f939b7f9b255a6abc2a72035e (diff)
ecore-drm: Port ecore_drm_inputs code to use Eeze instead of udev
Summary: This changes all of our internal ecore-drm input code to use Eeze library instead of udev directly. @feature Signed-off-by: Chris Michael <cp.michael@samsung.com>
-rw-r--r--src/lib/ecore_drm/ecore_drm_inputs.c202
1 files changed, 82 insertions, 120 deletions
diff --git a/src/lib/ecore_drm/ecore_drm_inputs.c b/src/lib/ecore_drm/ecore_drm_inputs.c
index 0774b8fc34..cec69135c2 100644
--- a/src/lib/ecore_drm/ecore_drm_inputs.c
+++ b/src/lib/ecore_drm/ecore_drm_inputs.c
@@ -87,7 +87,7 @@ _cb_device_opened(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending
87 87
88 if (!(d = data)) return; 88 if (!(d = data)) return;
89 89
90 DBG("Device Opened: %s", d->node); 90 /* DBG("Input Device Opened: %s", d->node); */
91 91
92 /* DBUS_TYPE_UNIX_FD == 'h' */ 92 /* DBUS_TYPE_UNIX_FD == 'h' */
93 if (!eldbus_message_arguments_get(msg, "hb", &fd, &b)) 93 if (!eldbus_message_arguments_get(msg, "hb", &fd, &b))
@@ -142,37 +142,43 @@ _seat_get(Ecore_Drm_Input *input, const char *seat)
142} 142}
143 143
144static Eina_Bool 144static Eina_Bool
145_device_add(Ecore_Drm_Input *input, struct udev_device *device) 145_device_add(Ecore_Drm_Input *input, const char *device)
146{ 146{
147 Ecore_Drm_Device_Open_Data *data;
148 Ecore_Drm_Seat *seat; 147 Ecore_Drm_Seat *seat;
149 const char *dev_seat, *wl_seat; 148 Ecore_Drm_Device_Open_Data *data;
150 const char *node; 149 const char *devseat, *wlseat;
151 char n[PATH_MAX];
152 150
153 if (!(dev_seat = udev_device_get_property_value(device, "ID_SEAT"))) 151 DBG("Add Input Device: %s", device);
154 dev_seat = "seat0";
155 152
156 if (strcmp(dev_seat, input->seat)) return EINA_FALSE; 153 if (!(devseat = eeze_udev_syspath_get_property(device, "ID_SEAT")))
154 devseat = eina_stringshare_add("seat0");
157 155
158 if (!(wl_seat = udev_device_get_property_value(device, "WL_SEAT"))) 156 if (strcmp(devseat, input->seat)) goto seat_err;
159 wl_seat = "seat0";
160 157
161 if (!(seat = _seat_get(input, wl_seat))) 158 if (!(wlseat = eeze_udev_syspath_get_property(device, "WL_SEAT")))
162 return EINA_FALSE; 159 wlseat = eina_stringshare_add("seat0");
163 160
164 node = udev_device_get_devnode(device); 161 if (!(seat = _seat_get(input, wlseat)))
165 strcpy(n, node); 162 {
163 ERR("\tCould not get matching seat");
164 goto seat_get_err;
165 }
166 166
167 if (!(data = calloc(1, sizeof(Ecore_Drm_Device_Open_Data)))) 167 if (!(data = calloc(1, sizeof(Ecore_Drm_Device_Open_Data))))
168 return EINA_FALSE; 168 goto seat_get_err;
169 169
170 data->seat = seat; 170 data->seat = seat;
171 data->node = eina_stringshare_add(n); 171 data->node = eeze_udev_syspath_get_devpath(device);
172 172
173 _ecore_drm_dbus_device_open(n, _cb_device_opened, data); 173 _ecore_drm_dbus_device_open(data->node, _cb_device_opened, data);
174 174
175 return EINA_TRUE; 175 return EINA_TRUE;
176
177seat_get_err:
178 eina_stringshare_del(wlseat);
179seat_err:
180 eina_stringshare_del(devseat);
181 return EINA_FALSE;
176} 182}
177 183
178static void 184static void
@@ -200,79 +206,61 @@ _device_remove(Ecore_Drm_Input *input, const char *device)
200 } 206 }
201} 207}
202 208
203static Eina_Bool 209static void
204_cb_input_event(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED) 210_cb_input_event(const char *device, Eeze_Udev_Event event, void *data, Eeze_Udev_Watch *watch EINA_UNUSED)
205{ 211{
206 Ecore_Drm_Input *input; 212 Ecore_Drm_Input *input;
207 struct udev_device *udevice;
208 const char *act;
209
210 if (!(input = data)) return EINA_FALSE;
211
212 if (!(udevice = udev_monitor_receive_device(input->monitor)))
213 return EINA_TRUE;
214
215 if (!(act = udev_device_get_action(udevice))) return EINA_TRUE;
216 213
217 if (strncmp("event", udev_device_get_sysname(udevice), 5) != 0) 214 if (!(input = data)) return;
218 goto err;
219 215
220 if (!strcmp(act, "add")) 216 switch (event)
221 _device_add(input, udevice);
222 else if (!strcmp(act, "remove"))
223 { 217 {
224 const char *node; 218 case EEZE_UDEV_EVENT_ADD:
225 219 _device_add(input, device);
226 node = udev_device_get_devnode(udevice); 220 break;
221 case EEZE_UDEV_EVENT_REMOVE:
222 {
223 const char *node;
227 224
228 _device_remove(input, node); 225 node = eeze_udev_syspath_get_devpath(device);
226 _device_remove(input, node);
227 eina_stringshare_del(node);
228 }
229 break;
230 default:
231 break;
229 } 232 }
230
231 return EINA_TRUE;
232
233err:
234 if (udevice) udev_device_unref(udevice);
235 return EINA_TRUE;
236} 233}
237 234
238static Eina_Bool 235static Eina_Bool
239_devices_add(Ecore_Drm_Input *input) 236_devices_add(Ecore_Drm_Input *input)
240{ 237{
241 struct udev_enumerate *uenum; 238 Eina_List *devices;
242 struct udev_list_entry *uentry;
243 struct udev_device *udevice;
244 const char *path, *name;
245 Eina_Bool found = EINA_FALSE; 239 Eina_Bool found = EINA_FALSE;
246 240 const char *device;
247 uenum = udev_enumerate_new(udev); 241
248 udev_enumerate_add_match_subsystem(uenum, "input"); 242 /* NB: This really sucks !! We cannot 'OR' diferent device types
249 udev_enumerate_scan_devices(uenum); 243 * together for eeze_udev_find_by_type
250 244 *
251 udev_list_entry_foreach(uentry, udev_enumerate_get_list_entry(uenum)) 245 * For now, just find by 'NONE" and we'll filter for input devices by
246 * running tests */
247 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NONE, NULL);
248 EINA_LIST_FREE(devices, device)
252 { 249 {
253 path = udev_list_entry_get_name(uentry); 250 if ((eeze_udev_syspath_is_mouse(device)) ||
254 udevice = udev_device_new_from_syspath(udev, path); 251 (eeze_udev_syspath_is_kbd(device)) ||
255 name = udev_device_get_sysname(udevice); 252 (eeze_udev_syspath_is_touchpad(device)) ||
256 253 (eeze_udev_syspath_is_joystick(device)))
257 if (strncmp("event", name, 5) != 0)
258 {
259 udev_device_unref(udevice);
260 continue;
261 }
262
263 if (!_device_add(input, udevice))
264 { 254 {
265 udev_device_unref(udevice); 255 if (!_device_add(input, device))
266 continue; 256 ERR("\tFailed to add device");
257 else
258 found = EINA_TRUE;
267 } 259 }
268 260
269 found = EINA_TRUE; 261 eina_stringshare_del(device);
270
271 udev_device_unref(udevice);
272 } 262 }
273 263
274 udev_enumerate_unref(uenum);
275
276 if (!found) 264 if (!found)
277 { 265 {
278 ERR("No Input Devices Found"); 266 ERR("No Input Devices Found");
@@ -289,7 +277,7 @@ ecore_drm_inputs_create(Ecore_Drm_Device *dev)
289 Ecore_Drm_Input *input; 277 Ecore_Drm_Input *input;
290 278
291 /* check for valid device */ 279 /* check for valid device */
292 if ((!dev) || (!udev)) return EINA_FALSE; 280 if (!dev) return EINA_FALSE;
293 281
294 /* try to allocate space for input structure */ 282 /* try to allocate space for input structure */
295 if (!(input = calloc(1, sizeof(Ecore_Drm_Input)))) 283 if (!(input = calloc(1, sizeof(Ecore_Drm_Input))))
@@ -340,55 +328,31 @@ ecore_drm_inputs_enable(Ecore_Drm_Input *input)
340 /* check for valid input */ 328 /* check for valid input */
341 if (!input) return EINA_FALSE; 329 if (!input) return EINA_FALSE;
342 330
343 if (!input->monitor) 331 if (!input->watch)
344 input->monitor = udev_monitor_new_from_netlink(udev, "udev");
345
346 if (!input->monitor)
347 {
348 ERR("Could not create udev monitor: %m");
349 return EINA_FALSE;
350 }
351
352 /* setup input filter */
353 udev_monitor_filter_add_match_subsystem_devtype(input->monitor,
354 "input", NULL);
355
356 /* try to enable receiving udev events */
357 if (udev_monitor_enable_receiving(input->monitor))
358 {
359 ERR("Could not bind udev monitor: %m");
360 udev_monitor_unref(input->monitor);
361 return EINA_FALSE;
362 }
363
364 /* save the fd */
365 if ((input->fd = udev_monitor_get_fd(input->monitor)) < 0)
366 { 332 {
367 ERR("Input monitor has no fd: %m"); 333 int events = 0;
368 udev_monitor_unref(input->monitor); 334
369 return EINA_FALSE; 335 events = (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE);
370 } 336 /* NB: This really sucks !! We cannot 'OR' diferent device types
371 337 * together for eeze_udev_watch_add :(
372 /* create fd handler */ 338 *
373 if (!input->hdlr) 339 * For now, just put a 'watch' on mouse type as this (in effect) does
374 { 340 * what we need by internally by adding a subsystem match for 'input' */
375 input->hdlr = 341 if (!(input->watch =
376 ecore_main_fd_handler_add(input->fd, ECORE_FD_READ, 342 eeze_udev_watch_add(EEZE_UDEV_TYPE_MOUSE, events,
377 _cb_input_event, input, NULL, NULL); 343 _cb_input_event, input)))
378 } 344 {
379 345 ERR("Could not create Eeze_Udev_Watch for input");
380 if (!input->hdlr) 346 return EINA_FALSE;
381 { 347 }
382 ERR("Failed to setup input fd handler: %m");
383 udev_monitor_unref(input->monitor);
384 return EINA_FALSE;
385 } 348 }
386 349
387 /* try to add devices */ 350 /* try to add devices */
388 if (!_devices_add(input)) 351 if (!_devices_add(input))
389 { 352 {
390 ERR("Could not add input devices"); 353 ERR("Could not add input devices");
391 udev_monitor_unref(input->monitor); 354 eeze_udev_watch_del(input->watch);
355 input->watch = NULL;
392 return EINA_FALSE; 356 return EINA_FALSE;
393 } 357 }
394 358
@@ -403,13 +367,11 @@ ecore_drm_inputs_disable(Ecore_Drm_Input *input)
403{ 367{
404 if (!input) return; 368 if (!input) return;
405 369
406 if (input->monitor) udev_monitor_unref(input->monitor); 370 if (input->watch) eeze_udev_watch_del(input->watch);
407 input->monitor = NULL; 371 input->watch = NULL;
408
409 if (input->hdlr) ecore_main_fd_handler_del(input->hdlr);
410 input->hdlr = NULL;
411 372
412 input->enabled = EINA_FALSE; 373 input->enabled = EINA_FALSE;
413 input->suspended = EINA_TRUE; 374 input->suspended = EINA_TRUE;
375
414 ecore_drm_inputs_destroy(input->dev); 376 ecore_drm_inputs_destroy(input->dev);
415} 377}