source: select.c @ aa69c1e

release-1.10release-1.8release-1.9
Last change on this file since aa69c1e was aa69c1e, checked in by David Benjamin <davidben@mit.edu>, 13 years ago
And finally, remove owl_io_dispatch All uses have been replaced with a GIOChannel watch.
  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[9c7a701]1#include "owl.h"
2
[2c79eae]3static GMainLoop *loop = NULL;
[44976fe]4static GMainContext *main_context;
[2c79eae]5
6void owl_select_init(void)
[4f2166b]7{
8}
9
[3ecd78b]10void owl_select_run_loop(void)
[4f2166b]11{
[44976fe]12  main_context = g_main_context_default();
13  loop = g_main_loop_new(main_context, FALSE);
[2c79eae]14  g_main_loop_run(loop);
[4f2166b]15}
16
[3ecd78b]17void owl_select_quit_loop(void)
[4f2166b]18{
[2c79eae]19  if (loop) {
20    g_main_loop_quit(loop);
[f0781ba]21    g_main_loop_unref(loop);
[2c79eae]22    loop = NULL;
[4f2166b]23  }
24}
25
[ba12b44]26typedef struct _owl_task { /*noproto*/
27  void (*cb)(void *);
28  void *cbdata;
29  void (*destroy_cbdata)(void *);
30} owl_task;
[3a84694]31
[ba12b44]32static gboolean _run_task(gpointer data)
33{
34  owl_task *t = data;
35  if (t->cb)
36    t->cb(t->cbdata);
37  return FALSE;
[9c7a701]38}
[3ecd78b]39
[ba12b44]40static void _destroy_task(void *data)
[3ecd78b]41{
[ba12b44]42  owl_task *t = data;
43  if (t->destroy_cbdata)
44    t->destroy_cbdata(t->cbdata);
45  g_free(t);
[3ecd78b]46}
47
[44976fe]48void owl_select_post_task(void (*cb)(void*), void *cbdata, void (*destroy_cbdata)(void*), GMainContext *context)
[3ecd78b]49{
[ba12b44]50  GSource *source = g_idle_source_new();
51  owl_task *t = g_new0(owl_task, 1);
52  t->cb = cb;
53  t->cbdata = cbdata;
54  t->destroy_cbdata = destroy_cbdata;
55  g_source_set_priority(source, G_PRIORITY_DEFAULT);
56  g_source_set_callback(source, _run_task, t, _destroy_task);
57  g_source_attach(source, context);
58  g_source_unref(source);
[3ecd78b]59}
Note: See TracBrowser for help on using the repository browser.