summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2017-06-02 18:23:45 -0400
committerMike Blumenkrantz <zmike@osg.samsung.com>2017-07-28 16:03:02 -0400
commitd9b0fded6ebc4c3a1fbf19621926a42b22fd544d (patch)
treed634b7953c17d0d54dcca14fb2675e9d0350a0fa
parentff7151d2f0bb616c327013712b02490f7f1f4d69 (diff)
elput: add refcounting for seats/devices
ensure lifetimes persist through events @fix
-rw-r--r--src/lib/elput/elput_evdev.c15
-rw-r--r--src/lib/elput/elput_input.c8
-rw-r--r--src/lib/elput/elput_private.h4
3 files changed, 24 insertions, 3 deletions
diff --git a/src/lib/elput/elput_evdev.c b/src/lib/elput/elput_evdev.c
index 9c20758..0c005d2 100644
--- a/src/lib/elput/elput_evdev.c
+++ b/src/lib/elput/elput_evdev.c
@@ -1,6 +1,12 @@
1#include "elput_private.h" 1#include "elput_private.h"
2 2
3static void 3static void
4_seat_event_free(void *d, void *ev EINA_UNUSED)
5{
6 _udev_seat_destroy(d);
7}
8
9static void
4_seat_caps_update(Elput_Seat *seat) 10_seat_caps_update(Elput_Seat *seat)
5{ 11{
6 Elput_Event_Seat_Caps *ev; 12 Elput_Event_Seat_Caps *ev;
@@ -12,8 +18,9 @@ _seat_caps_update(Elput_Seat *seat)
12 ev->keyboard_count = seat->count.kbd; 18 ev->keyboard_count = seat->count.kbd;
13 ev->touch_count = seat->count.touch; 19 ev->touch_count = seat->count.touch;
14 ev->seat = seat; 20 ev->seat = seat;
21 seat->refs++;
15 22
16 ecore_event_add(ELPUT_EVENT_SEAT_CAPS, ev, NULL, NULL); 23 ecore_event_add(ELPUT_EVENT_SEAT_CAPS, ev, _seat_event_free, seat);
17} 24}
18 25
19static void 26static void
@@ -25,7 +32,8 @@ _seat_frame_send(Elput_Seat *seat)
25 if (!ev) return; 32 if (!ev) return;
26 33
27 ev->seat = seat; 34 ev->seat = seat;
28 ecore_event_add(ELPUT_EVENT_SEAT_FRAME, ev, NULL, NULL); 35 seat->refs++;
36 ecore_event_add(ELPUT_EVENT_SEAT_FRAME, ev, _seat_event_free, seat);
29} 37}
30 38
31static void 39static void
@@ -1330,6 +1338,7 @@ _evdev_device_create(Elput_Seat *seat, struct libinput_device *device)
1330 edev = calloc(1, sizeof(Elput_Device)); 1338 edev = calloc(1, sizeof(Elput_Device));
1331 if (!edev) return NULL; 1339 if (!edev) return NULL;
1332 1340
1341 edev->refs = 1;
1333 edev->seat = seat; 1342 edev->seat = seat;
1334 edev->device = device; 1343 edev->device = device;
1335 edev->caps = 0; 1344 edev->caps = 0;
@@ -1389,6 +1398,8 @@ void
1389_evdev_device_destroy(Elput_Device *edev) 1398_evdev_device_destroy(Elput_Device *edev)
1390{ 1399{
1391 if (!edev) return; 1400 if (!edev) return;
1401 edev->refs--;
1402 if (edev->refs) return;
1392 1403
1393 if (edev->caps & EVDEV_SEAT_POINTER) 1404 if (edev->caps & EVDEV_SEAT_POINTER)
1394 _pointer_release(edev->seat); 1405 _pointer_release(edev->seat);
diff --git a/src/lib/elput/elput_input.c b/src/lib/elput/elput_input.c
index db0e980..4186ad9 100644
--- a/src/lib/elput/elput_input.c
+++ b/src/lib/elput/elput_input.c
@@ -103,6 +103,7 @@ _udev_seat_create(Elput_Manager *em, const char *name)
103 if (!eseat) return NULL; 103 if (!eseat) return NULL;
104 104
105 eseat->manager = em; 105 eseat->manager = em;
106 eseat->refs = 1;
106 107
107 eseat->name = eina_stringshare_add(name); 108 eseat->name = eina_stringshare_add(name);
108 em->input.seats = eina_list_append(em->input.seats, eseat); 109 em->input.seats = eina_list_append(em->input.seats, eseat);
@@ -110,11 +111,14 @@ _udev_seat_create(Elput_Manager *em, const char *name)
110 return eseat; 111 return eseat;
111} 112}
112 113
113static void 114void
114_udev_seat_destroy(Elput_Seat *eseat) 115_udev_seat_destroy(Elput_Seat *eseat)
115{ 116{
116 Elput_Device *edev; 117 Elput_Device *edev;
117 118
119 eseat->refs--;
120 if (eseat->refs) return;
121
118 EINA_LIST_FREE(eseat->devices, edev) 122 EINA_LIST_FREE(eseat->devices, edev)
119 _evdev_device_destroy(edev); 123 _evdev_device_destroy(edev);
120 124
@@ -177,6 +181,7 @@ _device_event_cb_free(void *data EINA_UNUSED, void *event)
177 if (seat) 181 if (seat)
178 seat->devices = eina_list_remove(seat->devices, ev->device); 182 seat->devices = eina_list_remove(seat->devices, ev->device);
179 183
184 ev->device->refs--;
180 _evdev_device_destroy(ev->device); 185 _evdev_device_destroy(ev->device);
181 } 186 }
182 187
@@ -193,6 +198,7 @@ _device_event_send(Elput_Device *edev, Elput_Device_Change_Type type)
193 198
194 ev->device = edev; 199 ev->device = edev;
195 ev->type = type; 200 ev->type = type;
201 edev->refs++;
196 202
197 ecore_event_add(ELPUT_EVENT_DEVICE_CHANGE, ev, _device_event_cb_free, NULL); 203 ecore_event_add(ELPUT_EVENT_DEVICE_CHANGE, ev, _device_event_cb_free, NULL);
198} 204}
diff --git a/src/lib/elput/elput_private.h b/src/lib/elput/elput_private.h
index 250c849..43bef7a 100644
--- a/src/lib/elput/elput_private.h
+++ b/src/lib/elput/elput_private.h
@@ -190,6 +190,7 @@ struct _Elput_Touch
190 190
191struct _Elput_Seat 191struct _Elput_Seat
192{ 192{
193 int refs; //for events
193 const char *name; 194 const char *name;
194 195
195 struct 196 struct
@@ -210,6 +211,7 @@ struct _Elput_Seat
210struct _Elput_Device 211struct _Elput_Device
211{ 212{
212 Elput_Seat *seat; 213 Elput_Seat *seat;
214 int refs; //for events
213 215
214 uint32_t ow, oh; 216 uint32_t ow, oh;
215 217
@@ -285,4 +287,6 @@ Elput_Touch *_evdev_touch_get(Elput_Seat *seat);
285 287
286extern Elput_Interface _logind_interface; 288extern Elput_Interface _logind_interface;
287 289
290
291void _udev_seat_destroy(Elput_Seat *eseat);
288#endif 292#endif