diff options
author | Volodymyr Brynza <v.brynza@samsung.com> | 2016-11-09 16:46:43 +0200 |
---|---|---|
committer | Eunhae Choi <eunhae1.choi@samsung.com> | 2016-11-10 18:17:15 +0900 |
commit | 9fae47dc621fd31a81c41894962576d31c3b06ea (patch) | |
tree | 80fb0208b0c152a8aff89e3c9476176984a8a5b5 | |
parent | 0ab33a96b8ff21700f6d3a5725640fa95d4f1987 (diff) | |
download | murphy-9fae47dc621fd31a81c41894962576d31c3b06ea.tar.gz murphy-9fae47dc621fd31a81c41894962576d31c3b06ea.tar.bz2 murphy-9fae47dc621fd31a81c41894962576d31c3b06ea.zip |
Update glib-glue for suporting non default contextsubmit/tizen_3.0_common/20161114.081136submit/tizen_3.0/20161110.095131accepted/tizen/3.0/wearable/20161111.003332accepted/tizen/3.0/tv/20161111.003313accepted/tizen/3.0/mobile/20161111.003304accepted/tizen/3.0/ivi/20161111.003352accepted/tizen/3.0/common/20161114.143140
Change-Id: Ia3163c7822627d64acfe1d49a3c3e3a5c9f93716
Signed-off-by: Volodymyr Brynza <v.brynza@samsung.com>
-rw-r--r-- | src/common/glib-glue.c | 75 |
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; } } |