summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolodymyr Brynza <v.brynza@samsung.com>2016-11-09 16:46:43 +0200
committerVolodymyr Brynza <v.brynza@samsung.com>2016-11-09 16:46:43 +0200
commita9290218c24ee95ac918ac85ea56bedd22c44c05 (patch)
tree80fb0208b0c152a8aff89e3c9476176984a8a5b5
parenta833f980ecebaeca2a45571d6fe74c862f11fb55 (diff)
downloadmurphy-a9290218c24ee95ac918ac85ea56bedd22c44c05.tar.gz
murphy-a9290218c24ee95ac918ac85ea56bedd22c44c05.tar.bz2
murphy-a9290218c24ee95ac918ac85ea56bedd22c44c05.zip
Change-Id: Ia3163c7822627d64acfe1d49a3c3e3a5c9f93716 Signed-off-by: Volodymyr Brynza <v.brynza@samsung.com>
-rw-r--r--src/common/glib-glue.c75
1 files changed, 54 insertions, 21 deletions
diff --git a/src/common/glib-glue.c b/src/common/glib-glue.c
index 1678b96..bea7f98 100644
--- a/src/common/glib-glue.c
+++ b/src/common/glib-glue.c
@@ -91,7 +91,48 @@ static void *add_defer(void *glue_data,
void *user_data);
static void del_defer(void *glue_data, void *id);
static void mod_defer(void *glue_data, void *id, int enabled);
+static guint add_timeout(void *glue_data, GSourceFunc cb, unsigned int msecs, void *user_data);
+static guint add_io_watch(void *glue_data, GSourceFunc cb, GIOCondition mask, GIOChannel *ioc, void *user_data);
+static void remove_source(void *glue_data, guint id);
+static guint add_timeout(void *glue_data, GSourceFunc cb, unsigned int msecs, void *user_data)
+{
+ guint id = 0;
+
+ glib_glue_t *glue = (glib_glue_t *)glue_data;
+ GMainContext *ctx = g_main_loop_get_context(glue->gml);
+ GSource *timesource = g_timeout_source_new(msecs);
+ g_source_set_callback(timesource, cb, user_data, NULL);
+ id = g_source_attach(timesource, ctx);
+ g_source_unref(timesource);
+
+ return id;
+}
+
+static guint add_io_watch(void *glue_data, GSourceFunc cb, GIOCondition mask, GIOChannel *ioc, void *user_data)
+{
+ guint id = 0;
+
+ glib_glue_t *glue = (glib_glue_t *)glue_data;
+ GMainContext *ctx = g_main_loop_get_context(glue->gml);
+ GSource *source = g_io_create_watch (ioc, mask);
+ g_source_set_callback (source, cb, user_data, NULL);
+ id = g_source_attach (source, ctx);
+ g_source_unref (source);
+
+ return id;
+}
+
+static void remove_source(void *glue_data, guint id)
+{
+ glib_glue_t *glue = (glib_glue_t *)glue_data;
+ GMainContext *ctx = g_main_loop_get_context(glue->gml);
+ GSource *source;
+
+ source = g_main_context_find_source_by_id (ctx, id);
+ if (source)
+ g_source_destroy (source);
+}
static gboolean io_cb(GIOChannel *ioc, GIOCondition cond, gpointer user_data)
{
@@ -138,7 +179,8 @@ static void *add_io(void *glue_data, int fd, mrp_io_event_t events,
io->mask = events;
io->gl_ioc = ioc;
- io->gl_iow = g_io_add_watch(ioc, mask, io_cb, io);
+
+ io->gl_iow = add_io_watch(glue_data, (GSourceFunc)io_cb, mask, ioc, io);
if (io->gl_iow != 0) {
io->cb = cb;
@@ -161,9 +203,7 @@ static void del_io(void *glue_data, void *id)
{
io_t *io = (io_t *)id;
- MRP_UNUSED(glue_data);
-
- g_source_remove(io->gl_iow);
+ remove_source(glue_data, io->gl_iow);
g_io_channel_unref(io->gl_ioc);
mrp_free(io);
}
@@ -194,7 +234,7 @@ static void *add_timer(void *glue_data, unsigned int msecs,
t = mrp_allocz(sizeof(*t));
if (t != NULL) {
- t->gl_t = g_timeout_add(msecs, timer_cb, t);
+ t->gl_t = add_timeout(glue_data, (GSourceFunc)timer_cb, msecs, t);
if (t->gl_t != 0) {
t->cb = cb;
@@ -215,9 +255,7 @@ static void del_timer(void *glue_data, void *id)
{
tmr_t *t = (tmr_t *)id;
- MRP_UNUSED(glue_data);
-
- g_source_remove(t->gl_t);
+ remove_source(glue_data, t->gl_t);
mrp_free(t);
}
@@ -226,11 +264,9 @@ static void mod_timer(void *glue_data, void *id, unsigned int msecs)
{
tmr_t *t = (tmr_t *)id;
- MRP_UNUSED(glue_data);
-
if (t != NULL) {
- g_source_remove(t->gl_t);
- t->gl_t = g_timeout_add(msecs, timer_cb, t);
+ remove_source(glue_data, t->gl_t);
+ t->gl_t = add_timeout(glue_data, (GSourceFunc)timer_cb, msecs, t);
}
}
@@ -260,7 +296,7 @@ static void *add_defer(void *glue_data,
d = mrp_allocz(sizeof(*d));
if (d != NULL) {
- d->gl_t = g_timeout_add(1, defer_cb, d);
+ d->gl_t = add_timeout(glue_data, (GSourceFunc)defer_cb, 1, d);
if (d->gl_t != 0) {
d->cb = cb;
@@ -281,10 +317,8 @@ static void del_defer(void *glue_data, void *id)
{
dfr_t *d = (dfr_t *)id;
- MRP_UNUSED(glue_data);
-
if (d->gl_t != 0)
- g_source_remove(d->gl_t);
+ remove_source(glue_data, d->gl_t);
mrp_free(d);
}
@@ -294,15 +328,14 @@ static void mod_defer(void *glue_data, void *id, int enabled)
{
dfr_t *d = (dfr_t *)id;
- MRP_UNUSED(glue_data);
-
if (d == NULL)
return;
- if (enabled && !d->gl_t)
- d->gl_t = g_timeout_add(0, defer_cb, d);
+ if (enabled && !d->gl_t) {
+ d->gl_t = add_timeout(glue_data, (GSourceFunc)defer_cb, 0, d);
+ }
else if (!enabled && d->gl_t) {
- g_source_remove(d->gl_t);
+ remove_source(glue_data, d->gl_t);
d->gl_t = 0;
}
}