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)
{
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;
{
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);
}
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;
{
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);
}
{
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);
}
}
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;
{
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);
}
{
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;
}
}