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-06-02 18:23:42 -0400
commit4c7c613e768febdec27324527ccd320c4aa090db (patch)
treecd33c8589ccd4ae19fe664e4d6f47eac97d04468
parent539c2169b57518fa361c87961c98014dfeba40ff (diff)
downloadefl-4c7c613e768febdec27324527ccd320c4aa090db.tar.gz
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 be7c5800fd..33c4772ec7 100644
--- a/src/lib/elput/elput_evdev.c
+++ b/src/lib/elput/elput_evdev.c
@@ -1,6 +1,12 @@
#include "elput_private.h"
static void
+_seat_event_free(void *d, void *ev EINA_UNUSED)
+{
+ _udev_seat_destroy(d);
+}
+
+static void
_seat_caps_update(Elput_Seat *seat)
{
Elput_Event_Seat_Caps *ev;
@@ -12,8 +18,9 @@ _seat_caps_update(Elput_Seat *seat)
ev->keyboard_count = seat->count.kbd;
ev->touch_count = seat->count.touch;
ev->seat = seat;
+ seat->refs++;
- ecore_event_add(ELPUT_EVENT_SEAT_CAPS, ev, NULL, NULL);
+ ecore_event_add(ELPUT_EVENT_SEAT_CAPS, ev, _seat_event_free, seat);
}
static void
@@ -25,7 +32,8 @@ _seat_frame_send(Elput_Seat *seat)
if (!ev) return;
ev->seat = seat;
- ecore_event_add(ELPUT_EVENT_SEAT_FRAME, ev, NULL, NULL);
+ seat->refs++;
+ ecore_event_add(ELPUT_EVENT_SEAT_FRAME, ev, _seat_event_free, seat);
}
static void
@@ -1558,6 +1566,7 @@ _evdev_device_create(Elput_Seat *seat, struct libinput_device *device)
edev = calloc(1, sizeof(Elput_Device));
if (!edev) return NULL;
+ edev->refs = 1;
edev->seat = seat;
edev->device = device;
edev->caps = 0;
@@ -1621,6 +1630,8 @@ void
_evdev_device_destroy(Elput_Device *edev)
{
if (!edev) return;
+ edev->refs--;
+ if (edev->refs) return;
if (edev->caps & ELPUT_DEVICE_CAPS_POINTER)
_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)
if (!eseat) return NULL;
eseat->manager = em;
+ eseat->refs = 1;
eseat->name = eina_stringshare_add(name);
em->input.seats = eina_list_append(em->input.seats, eseat);
@@ -110,11 +111,14 @@ _udev_seat_create(Elput_Manager *em, const char *name)
return eseat;
}
-static void
+void
_udev_seat_destroy(Elput_Seat *eseat)
{
Elput_Device *edev;
+ eseat->refs--;
+ if (eseat->refs) return;
+
EINA_LIST_FREE(eseat->devices, edev)
_evdev_device_destroy(edev);
@@ -170,6 +174,7 @@ _device_event_cb_free(void *data EINA_UNUSED, void *event)
if (seat)
seat->devices = eina_list_remove(seat->devices, ev->device);
+ ev->device->refs--;
_evdev_device_destroy(ev->device);
}
@@ -186,6 +191,7 @@ _device_event_send(Elput_Device *edev, Elput_Device_Change_Type type)
ev->device = edev;
ev->type = type;
+ edev->refs++;
ecore_event_add(ELPUT_EVENT_DEVICE_CHANGE, ev, _device_event_cb_free, NULL);
}
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
struct _Elput_Seat
{
+ int refs; //for events
const char *name;
struct
@@ -209,6 +210,7 @@ struct _Elput_Seat
struct _Elput_Device
{
Elput_Seat *seat;
+ int refs; //for events
uint32_t ow, oh;
@@ -289,4 +291,6 @@ extern Elput_Interface _logind_interface;
void _keyboard_keymap_update(Elput_Seat *seat);
void _keyboard_group_update(Elput_Seat *seat);
+
+void _udev_seat_destroy(Elput_Seat *eseat);
#endif