summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2014-09-22 15:54:37 -0400
committerChris Michael <cp.michael@samsung.com>2014-09-22 15:54:37 -0400
commit500491069fa3bfb05b73de3b424b31b1d1441f8c (patch)
tree28cd7fc77f4da1834f5ee39dfbaf3f5cc50446a5
parent21fe5e6eab29fdef7d25debe8bbbdea4a2856b1f (diff)
ecore-drm: Rework input code to function with Eldbus
Summary: Eldbus runs async so we needed to rework the internal input code to function with it. This commit changes the iternal code to issue a device open, and then wait for Eldbus to return us a callback from the proxy that the device open is finished. This Does add a delay during startup (which means devices will not always be immediately ready for use) but thus is the nature of Eldbus. @fix Signed-off-by: Chris Michael <cp.michael@samsung.com>
-rw-r--r--src/lib/ecore_drm/ecore_drm_inputs.c147
1 files changed, 121 insertions, 26 deletions
diff --git a/src/lib/ecore_drm/ecore_drm_inputs.c b/src/lib/ecore_drm/ecore_drm_inputs.c
index 0320fdc..0774b8f 100644
--- a/src/lib/ecore_drm/ecore_drm_inputs.c
+++ b/src/lib/ecore_drm/ecore_drm_inputs.c
@@ -4,7 +4,121 @@
4 4
5#include "ecore_drm_private.h" 5#include "ecore_drm_private.h"
6 6
7typedef struct _Ecore_Drm_Device_Open_Data Ecore_Drm_Device_Open_Data;
8struct _Ecore_Drm_Device_Open_Data
9{
10 Ecore_Drm_Seat *seat;
11 const char *node;
12};
13
7/* local functions */ 14/* local functions */
15static int
16_device_flags_set(int fd)
17{
18 int ret, fl;
19 /* char name[256] = "unknown"; */
20
21 if (fd < 0)
22 {
23 ERR("Failed to take device");
24 return -1;
25 }
26
27 if ((fl = fcntl(fd, F_GETFL)) < 0)
28 {
29 ERR("Failed to get file flags: %m");
30 goto flag_err;
31 }
32
33 fl = (O_RDWR | O_NONBLOCK);
34
35 if ((ret = fcntl(fd, F_SETFL, fl)) < 0)
36 {
37 ERR("Failed to set file flags: %m");
38 goto flag_err;
39 }
40
41 if ((fl = fcntl(fd, F_GETFD)) < 0)
42 {
43 ERR("Failed to get file fd: %m");
44 goto flag_err;
45 }
46
47 fl &= ~FD_CLOEXEC;
48
49 if ((ret = fcntl(fd, F_SETFD, fl)) < 0)
50 {
51 ERR("Failed to set file fds: %m");
52 goto flag_err;
53 }
54
55 /* if (ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0) */
56 /* { */
57 /* ERR("Could not get device name: %m"); */
58 /* goto flag_err; */
59 /* } */
60 /* else */
61 /* { */
62 /* name[sizeof(name) - 1] = '\0'; */
63 /* DBG("%s Opened", name); */
64 /* } */
65
66 return fd;
67
68flag_err:
69 close(fd);
70 return -1;
71}
72
73static void
74_cb_device_opened(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
75{
76 Ecore_Drm_Device_Open_Data *d;
77 Ecore_Drm_Evdev *edev;
78 Eina_Bool b = EINA_FALSE;
79 const char *errname, *errmsg;
80 int fd = -1;
81
82 if (eldbus_message_error_get(msg, &errname, &errmsg))
83 {
84 ERR("Eldbus Message Error: %s %s", errname, errmsg);
85 return;
86 }
87
88 if (!(d = data)) return;
89
90 DBG("Device Opened: %s", d->node);
91
92 /* DBUS_TYPE_UNIX_FD == 'h' */
93 if (!eldbus_message_arguments_get(msg, "hb", &fd, &b))
94 {
95 ERR("\tCould not get UNIX_FD from eldbus message: %d %d", fd, b);
96 goto cleanup;
97 }
98
99 if (!(fd = _device_flags_set(fd)))
100 {
101 ERR("\tCould not set fd flags");
102 goto release;
103 }
104
105 if (!(edev = _ecore_drm_evdev_device_create(d->seat, d->node, fd)))
106 {
107 ERR("\tCould not create evdev device: %s", d->node);
108 goto release;
109 }
110
111 d->seat->devices = eina_list_append(d->seat->devices, edev);
112
113 goto cleanup;
114
115release:
116 _ecore_drm_dbus_device_close(d->node);
117cleanup:
118 eina_stringshare_del(d->node);
119 free(d);
120}
121
8static Ecore_Drm_Seat * 122static Ecore_Drm_Seat *
9_seat_get(Ecore_Drm_Input *input, const char *seat) 123_seat_get(Ecore_Drm_Input *input, const char *seat)
10{ 124{
@@ -30,12 +144,11 @@ _seat_get(Ecore_Drm_Input *input, const char *seat)
30static Eina_Bool 144static Eina_Bool
31_device_add(Ecore_Drm_Input *input, struct udev_device *device) 145_device_add(Ecore_Drm_Input *input, struct udev_device *device)
32{ 146{
33 Ecore_Drm_Evdev *edev; 147 Ecore_Drm_Device_Open_Data *data;
34 Ecore_Drm_Seat *seat; 148 Ecore_Drm_Seat *seat;
35 const char *dev_seat, *wl_seat; 149 const char *dev_seat, *wl_seat;
36 const char *node; 150 const char *node;
37 char n[PATH_MAX]; 151 char n[PATH_MAX];
38 int fd = -1;
39 152
40 if (!(dev_seat = udev_device_get_property_value(device, "ID_SEAT"))) 153 if (!(dev_seat = udev_device_get_property_value(device, "ID_SEAT")))
41 dev_seat = "seat0"; 154 dev_seat = "seat0";
@@ -51,25 +164,13 @@ _device_add(Ecore_Drm_Input *input, struct udev_device *device)
51 node = udev_device_get_devnode(device); 164 node = udev_device_get_devnode(device);
52 strcpy(n, node); 165 strcpy(n, node);
53 166
54 fd = _ecore_drm_dbus_device_open(n); 167 if (!(data = calloc(1, sizeof(Ecore_Drm_Device_Open_Data))))
55 if (fd < 0) 168 return EINA_FALSE;
56 {
57 ERR("FAILED TO OPEN %s: %m", n);
58 return EINA_FALSE;
59 }
60
61 /* DBG("Opened Restricted Input: %s %d", node, fd); */
62
63 if (!(edev = _ecore_drm_evdev_device_create(seat, node, fd)))
64 {
65 ERR("Could not create evdev device: %s", node);
66 close(fd);
67 return EINA_FALSE;
68 }
69 169
70 seat->devices = eina_list_append(seat->devices, edev); 170 data->seat = seat;
171 data->node = eina_stringshare_add(n);
71 172
72 /* TODO: finish */ 173 _ecore_drm_dbus_device_open(n, _cb_device_opened, data);
73 174
74 return EINA_TRUE; 175 return EINA_TRUE;
75} 176}
@@ -106,8 +207,6 @@ _cb_input_event(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
106 struct udev_device *udevice; 207 struct udev_device *udevice;
107 const char *act; 208 const char *act;
108 209
109 DBG("Input Event");
110
111 if (!(input = data)) return EINA_FALSE; 210 if (!(input = data)) return EINA_FALSE;
112 211
113 if (!(udevice = udev_monitor_receive_device(input->monitor))) 212 if (!(udevice = udev_monitor_receive_device(input->monitor)))
@@ -119,17 +218,13 @@ _cb_input_event(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
119 goto err; 218 goto err;
120 219
121 if (!strcmp(act, "add")) 220 if (!strcmp(act, "add"))
122 { 221 _device_add(input, udevice);
123 DBG("\tDevice Added");
124 _device_add(input, udevice);
125 }
126 else if (!strcmp(act, "remove")) 222 else if (!strcmp(act, "remove"))
127 { 223 {
128 const char *node; 224 const char *node;
129 225
130 node = udev_device_get_devnode(udevice); 226 node = udev_device_get_devnode(udevice);
131 227
132 DBG("\tDevice Removed: %s", node);
133 _device_remove(input, node); 228 _device_remove(input, node);
134 } 229 }
135 230