summaryrefslogtreecommitdiff
path: root/src
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-06-02 18:23:42 -0400
commit4c7c613e768febdec27324527ccd320c4aa090db (patch)
treecd33c8589ccd4ae19fe664e4d6f47eac97d04468 /src
parent539c2169b57518fa361c87961c98014dfeba40ff (diff)
elput: add refcounting for seats/devices
ensure lifetimes persist through events @fix
Diffstat (limited to 'src')
-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 be7c5800fd..33c4772ec7 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
@@ -1558,6 +1566,7 @@ _evdev_device_create(Elput_Seat *seat, struct libinput_device *device)
1558 edev = calloc(1, sizeof(Elput_Device)); 1566 edev = calloc(1, sizeof(Elput_Device));
1559 if (!edev) return NULL; 1567 if (!edev) return NULL;
1560 1568
1569 edev->refs = 1;
1561 edev->seat = seat; 1570 edev->seat = seat;
1562 edev->device = device; 1571 edev->device = device;
1563 edev->caps = 0; 1572 edev->caps = 0;
@@ -1621,6 +1630,8 @@ void
1621_evdev_device_destroy(Elput_Device *edev) 1630_evdev_device_destroy(Elput_Device *edev)
1622{ 1631{
1623 if (!edev) return; 1632 if (!edev) return;
1633 edev->refs--;
1634 if (edev->refs) return;
1624 1635
1625 if (edev->caps & ELPUT_DEVICE_CAPS_POINTER) 1636 if (edev->caps & ELPUT_DEVICE_CAPS_POINTER)
1626 _pointer_release(edev->seat); 1637 _pointer_release(edev->seat);
diff --git a/src/lib/elput/elput_input.c b/src/lib/elput/elput_input.c
index 9366ff9b51..52a00f5fa2 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
@@ -170,6 +174,7 @@ _device_event_cb_free(void *data EINA_UNUSED, void *event)
170 if (seat) 174 if (seat)
171 seat->devices = eina_list_remove(seat->devices, ev->device); 175 seat->devices = eina_list_remove(seat->devices, ev->device);
172 176
177 ev->device->refs--;
173 _evdev_device_destroy(ev->device); 178 _evdev_device_destroy(ev->device);
174 } 179 }
175 180
@@ -186,6 +191,7 @@ _device_event_send(Elput_Device *edev, Elput_Device_Change_Type type)
186 191
187 ev->device = edev; 192 ev->device = edev;
188 ev->type = type; 193 ev->type = type;
194 edev->refs++;
189 195
190 ecore_event_add(ELPUT_EVENT_DEVICE_CHANGE, ev, _device_event_cb_free, NULL); 196 ecore_event_add(ELPUT_EVENT_DEVICE_CHANGE, ev, _device_event_cb_free, NULL);
191} 197}
diff --git a/src/lib/elput/elput_private.h b/src/lib/elput/elput_private.h
index 202c52bbef..a5263f7720 100644
--- a/src/lib/elput/elput_private.h
+++ b/src/lib/elput/elput_private.h
@@ -189,6 +189,7 @@ struct _Elput_Touch
189 189
190struct _Elput_Seat 190struct _Elput_Seat
191{ 191{
192 int refs; //for events
192 const char *name; 193 const char *name;
193 194
194 struct 195 struct
@@ -209,6 +210,7 @@ struct _Elput_Seat
209struct _Elput_Device 210struct _Elput_Device
210{ 211{
211 Elput_Seat *seat; 212 Elput_Seat *seat;
213 int refs; //for events
212 214
213 uint32_t ow, oh; 215 uint32_t ow, oh;
214 216
@@ -289,4 +291,6 @@ extern Elput_Interface _logind_interface;
289void _keyboard_keymap_update(Elput_Seat *seat); 291void _keyboard_keymap_update(Elput_Seat *seat);
290void _keyboard_group_update(Elput_Seat *seat); 292void _keyboard_group_update(Elput_Seat *seat);
291 293
294
295void _udev_seat_destroy(Elput_Seat *eseat);
292#endif 296#endif