Mercurial > MadButterfly
changeset 1022:84006acab6af refine_backend_if
Use macros to hide the default backend
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 22 Nov 2010 15:20:11 +0800 |
parents | 4f4abce1b5df |
children | dffecd62817c |
files | include/mb_backend.h src/X_supp.c src/mbaf/mbapp.c |
diffstat | 3 files changed, 63 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_backend.h Mon Nov 22 14:02:01 2010 +0800 +++ b/include/mb_backend.h Mon Nov 22 15:20:11 2010 +0800 @@ -79,11 +79,48 @@ * Following two methods are used to integrate a backend to * event loop of main application. */ - void (*reg_IO_factory)(mb_IO_factory_t *evman); - void (*reg_timer_factory)(mb_timer_factory_t *evman); + void (*reg_IO_factory)(mb_IO_factory_t *io_man); + void (*reg_timer_factory)(mb_timer_factory_t *tm_man); } mb_backend_t; -extern mb_backend_t backend; +#define mb_runtime_new(disp, w, h) \ + mb_dfl_backend.new((disp), (w), (h)) +#define mb_runtime_new_with_win(disp, win) \ + mb_dfl_backend.new_with_win((disp), (win)) +#define mb_reg_IO_factory(io_man) \ + mb_dfl_backend.reg_IO_factory(io_man) +#define mb_reg_timer_factory(tm_man) \ + mb_dfl_backend.reg_timer_factory(tm_man) + +/* + * This is defined by backend implementations. For example, X_supp.c + * or dfb_supp.c should defined a backend. + */ +extern mb_backend_t mb_dfl_backend; + +#define mb_runtime_free(rt) \ + mb_dfl_backend.free(rt) +#define mb_runtime_free_with_win(rt) \ + mb_dfl_backend.free_with_win(rt) +#define mb_runtime_add_event(rt, fd, type, cb, arg) \ + mb_dfl_backend.add_event((rt), (fd), (type), (cb), (arg)) +#define mb_runtime_remove_event(hdl) \ + mb_dfl_backend.remove_event((rt), (hdl)) +#define mb_runtime_event_loop(rt) \ + mb_dfl_backend.event_loop(rt) +#define mb_runtime_flush(rt) \ + mb_dfl_backend.flush(rt) +#define mb_runtime_kbevents(rt) \ + mb_dfl_backend.kbevents(rt) +#define mb_runtime_rdman(rt) \ + mb_dfl_backend.rdman(rt) +#define mb_runtime_timer_man(rt) \ + mb_dfl_backend.timer_man(rt) +#define mb_runtime_ob_factory(rt) \ + mb_dfl_backend.ob_factory(rt) +#define mb_runtime_loader(rt) \ + mb_dfl_backend.loader(rt) + /*! \brief Type of IO that registered with an IO manager. */
--- a/src/X_supp.c Mon Nov 22 14:02:01 2010 +0800 +++ b/src/X_supp.c Mon Nov 22 15:20:11 2010 +0800 @@ -1056,22 +1056,22 @@ return r == 0? ERR: OK; } -mb_backend_t backend = { _x_supp_new, - _x_supp_new_with_win, - - _x_supp_free, - _x_supp_free_keep_win, - _x_supp_add_event, - _x_supp_remove_event, - _x_supp_event_loop, - _x_supp_flush, - - _x_supp_kbevents, - _x_supp_rdman, - _x_supp_timer_man, - _x_supp_ob_factory, - _x_supp_img_ldr - }; +mb_backend_t mb_dfl_backend = { _x_supp_new, + _x_supp_new_with_win, + + _x_supp_free, + _x_supp_free_keep_win, + _x_supp_add_event, + _x_supp_remove_event, + _x_supp_event_loop, + _x_supp_flush, + + _x_supp_kbevents, + _x_supp_rdman, + _x_supp_timer_man, + _x_supp_ob_factory, + _x_supp_img_ldr +}; #if 0 /*! \defgroup x_supp_nodejs_sup Export functions for supporting nodejs plugin.
--- a/src/mbaf/mbapp.c Mon Nov 22 14:02:01 2010 +0800 +++ b/src/mbaf/mbapp.c Mon Nov 22 15:20:11 2010 +0800 @@ -9,19 +9,19 @@ mbaf_t *app = (mbaf_t *) malloc(sizeof(mbaf_t)); mb_rt_t *rt; - rt = backend.new(":0.0", 800, 600); + rt = mb_runtime_new(":0.0", 800, 600); if(rt == NULL) return NULL; sprite_set_search_path(module_dir); app->rt = rt; - app->rdman = backend.rdman(rt); - app->kbevents = backend.kbevents(rt); + app->rdman = mb_runtime_rdman(rt); + app->kbevents = mb_runtime_kbevents(rt); app->rootsprite= sprite_load(module,app->rdman, app->rdman->root_coord); if(app->rootsprite == NULL) { - backend.free(rt); + mb_runtime_free(rt); free(app); return NULL; } @@ -39,7 +39,7 @@ mb_timer_man_t *mbaf_get_timer(mbaf_t *app) { - return backend.timer_man(app->rt); + return mb_runtime_timer_man(app->rt); } void mbaf_loop(mbaf_t *app) @@ -48,11 +48,11 @@ * Start handle connections, includes one to X server. * User start to interact with the application. */ - backend.event_loop(app->rt); + mb_runtime_event_loop(app->rt); /* * Clean */ - backend.free(app->rt); + mb_runtime_free(app->rt); free(app); }