release-1.10release-1.8release-1.9
|
Last change
on this file since e146cd7 was
aa69c1e,
checked in by David Benjamin <davidben@mit.edu>, 15 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
|
| Line | |
|---|
| 1 | #include "owl.h" |
|---|
| 2 | |
|---|
| 3 | static GMainLoop *loop = NULL; |
|---|
| 4 | static GMainContext *main_context; |
|---|
| 5 | |
|---|
| 6 | void owl_select_init(void) |
|---|
| 7 | { |
|---|
| 8 | } |
|---|
| 9 | |
|---|
| 10 | void owl_select_run_loop(void) |
|---|
| 11 | { |
|---|
| 12 | main_context = g_main_context_default(); |
|---|
| 13 | loop = g_main_loop_new(main_context, FALSE); |
|---|
| 14 | g_main_loop_run(loop); |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | void owl_select_quit_loop(void) |
|---|
| 18 | { |
|---|
| 19 | if (loop) { |
|---|
| 20 | g_main_loop_quit(loop); |
|---|
| 21 | g_main_loop_unref(loop); |
|---|
| 22 | loop = NULL; |
|---|
| 23 | } |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | typedef struct _owl_task { /*noproto*/ |
|---|
| 27 | void (*cb)(void *); |
|---|
| 28 | void *cbdata; |
|---|
| 29 | void (*destroy_cbdata)(void *); |
|---|
| 30 | } owl_task; |
|---|
| 31 | |
|---|
| 32 | static gboolean _run_task(gpointer data) |
|---|
| 33 | { |
|---|
| 34 | owl_task *t = data; |
|---|
| 35 | if (t->cb) |
|---|
| 36 | t->cb(t->cbdata); |
|---|
| 37 | return FALSE; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | static void _destroy_task(void *data) |
|---|
| 41 | { |
|---|
| 42 | owl_task *t = data; |
|---|
| 43 | if (t->destroy_cbdata) |
|---|
| 44 | t->destroy_cbdata(t->cbdata); |
|---|
| 45 | g_free(t); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | void owl_select_post_task(void (*cb)(void*), void *cbdata, void (*destroy_cbdata)(void*), GMainContext *context) |
|---|
| 49 | { |
|---|
| 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); |
|---|
| 59 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.