Mercurial > MadButterfly
changeset 1034:e9a134d75c99 refine_backend_if
To make backend compatible with C++
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 23 Nov 2010 00:29:55 +0800 |
parents | a79118734d20 |
children | 2275aef63b21 |
files | include/mb_backend.h src/X_supp.c |
diffstat | 2 files changed, 47 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_backend.h Mon Nov 22 22:26:03 2010 +0800 +++ b/include/mb_backend.h Tue Nov 23 00:29:55 2010 +0800 @@ -16,7 +16,17 @@ #inclde "mb_dfb_supp.h" #endif -typedef void mb_rt_t; +struct _mb_rt; +typedef struct _mb_rt mb_rt_t; + +struct _mb_timer_man; +struct _mb_timer_factory; +struct _mb_IO_man; +struct _mb_IO_factory; + +/*! \brief Type of IO that registered with an IO manager. + */ +enum _MB_IO_TYPE {MB_IO_DUMMY, MB_IO_R, MB_IO_W, MB_IO_RW}; typedef struct _mb_timer_man mb_timer_man_t; typedef struct _mb_timer_factory mb_timer_factory_t; @@ -42,11 +52,11 @@ * - render manager(?) */ typedef struct { - mb_rt_t *(*new)(const char *display, int w,int h); - mb_rt_t *(*new_with_win)(MB_DISPLAY display, MB_WINDOW win); + mb_rt_t *(*rt_new)(const char *display, int w,int h); + mb_rt_t *(*rt_new_with_win)(MB_DISPLAY display, MB_WINDOW win); - void (*free)(mb_rt_t *rt); - void (*free_keep_win)(mb_rt_t *rt); + void (*rt_free)(mb_rt_t *rt); + void (*rt_free_keep_win)(mb_rt_t *rt); /*! \brief Request the backend to start monitoring a file descriptor. * * This is used only when the backend is responsible for event loop. @@ -84,9 +94,9 @@ } mb_backend_t; #define mb_runtime_new(disp, w, h) \ - mb_dfl_backend.new((disp), (w), (h)) + mb_dfl_backend.rt_new((disp), (w), (h)) #define mb_runtime_new_with_win(disp, win) \ - mb_dfl_backend.new_with_win((disp), (win)) + mb_dfl_backend.rt_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) \ @@ -99,9 +109,9 @@ extern mb_backend_t mb_dfl_backend; #define mb_runtime_free(rt) \ - mb_dfl_backend.free(rt) + mb_dfl_backend.rt_free(rt) #define mb_runtime_free_with_win(rt) \ - mb_dfl_backend.free_with_win(rt) + mb_dfl_backend.rt_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) \ @@ -122,10 +132,6 @@ mb_dfl_backend.loader(rt) -/*! \brief Type of IO that registered with an IO manager. - */ -enum _MB_IO_TYPE {MB_IO_DUMMY, MB_IO_R, MB_IO_W, MB_IO_RW}; - /*! \brief IO Manager */ struct _mb_IO_man { @@ -138,10 +144,17 @@ /*! \brief Factory of IO managers. */ struct _mb_IO_factory { - mb_IO_man_t *(*new)(void); - void (*free)(mb_IO_man_t *io_man); + mb_IO_man_t *(*io_man_new)(void); + void (*io_man_free)(mb_IO_man_t *io_man); }; +#define mb_io_man_reg(io_man, fd, type, cb, data) \ + (io_man)->reg(io_man, fd, type, cb, data) +#define mb_io_man_unreg(io_man, io_hdl) \ + (io_man)->unreg(io_man, io_hdl) +#define mb_io_man_new(io_fact) (io_fact)->io_man_new() +#define mb_io_man_free(io_fact, io_man) (io_fact)->io_man_free(io_man) + /*! \brief Function signature of callback functions for timers. */ typedef void (*mb_timer_cb_t)(int hdl, @@ -169,15 +182,15 @@ /*! \brief Factory of timer manager. */ struct _mb_timer_factory { - mb_timer_man_t *(*new)(void); - void (*free)(mb_timer_man_t *timer_man); + mb_timer_man_t *(*timer_man_new)(void); + void (*timer_man_free)(mb_timer_man_t *timer_man); }; #define mb_timer_man_timeout(tm_man, tmout, cb, data) \ (tm_man)->timeout((tm_man), (tmout), (cb), (data)) #define mb_timer_man_remove(tm_man, tm_hdl) \ (tm_man)->remove((tm_man), (tm_hdl)) -#define mb_timer_man_new(tm_fact) (tm_fact)->new() -#define mb_timer_man_free(tm_fact, tm_man) (tm_fact)->free(tm_man) +#define mb_timer_man_new(tm_fact) (tm_fact)->timer_man_new() +#define mb_timer_man_free(tm_fact, tm_man) (tm_fact)->timer_man_free(tm_man) #endif /* __MB_BACKEND_H_ */
--- a/src/X_supp.c Mon Nov 22 22:26:03 2010 +0800 +++ b/src/X_supp.c Tue Nov 23 00:29:55 2010 +0800 @@ -174,11 +174,9 @@ _x_supp_event_loop(mb_rt_t *rt) { struct _X_supp_runtime *xmb_rt = (struct _X_supp_runtime *)rt; struct _X_supp_IO_man *io_man = (struct _X_supp_IO_man *)xmb_rt->io_man; - struct _X_supp_timer_man *timer_man = - (struct _X_supp_timer_man *)xmb_rt->timer_man; + mb_timer_man_t *timer_man = (mb_timer_man_t *)xmb_rt->timer_man; redraw_man_t *rdman; mb_tman_t *tman = tman_timer_man_get_tman(timer_man); - int fd; mb_timeval_t now, tmo; struct timeval tv; fd_set rfds, wfds; @@ -187,7 +185,7 @@ rdman = mb_runtime_rdman(rt); - _x_supp_handle_x_event(rt); + _x_supp_handle_x_event(xmb_rt); while(1) { FD_ZERO(&rfds); @@ -808,8 +806,8 @@ // to the redraw_man_t instead. xmb_rt->rdman->rt = xmb_rt; - xmb_rt->io_man = _io_factory->new(); - xmb_rt->timer_man = _timer_factory->new(); + xmb_rt->io_man = mb_io_man_new(_io_factory); + xmb_rt->timer_man = mb_timer_man_new(_timer_factory); img_ldr = simple_mb_img_ldr_new(""); xmb_rt->img_ldr = img_ldr; @@ -823,10 +821,10 @@ X_kb_init(&xmb_rt->kbinfo, xmb_rt->display, xmb_rt->rdman); disp_fd = XConnectionNumber(xmb_rt->display); - xmb_rt->io_hdl = xmb_rt->io_man->reg(xmb_rt->io_man, disp_fd, - MB_IO_R, - _x_supp_handle_connection, - xmb_rt); + xmb_rt->io_hdl = mb_io_man_reg(xmb_rt->io_man, disp_fd, + MB_IO_R, + _x_supp_handle_connection, + xmb_rt); return OK; } @@ -889,12 +887,12 @@ } if(xmb_rt->io_hdl) - xmb_rt->io_man->unreg(xmb_rt->io_man, xmb_rt->io_hdl); + mb_io_man_unreg(xmb_rt->io_man, xmb_rt->io_hdl); if(xmb_rt->io_man) - _io_factory->free(xmb_rt->io_man); + mb_io_man_free(_io_factory, xmb_rt->io_man); if(xmb_rt->timer_man) - _timer_factory->free(xmb_rt->timer_man); + mb_timer_man_free(_timer_factory, xmb_rt->timer_man); if(xmb_rt->img_ldr) MB_IMG_LDR_FREE(xmb_rt->img_ldr); @@ -954,7 +952,7 @@ return NULL; } - return rt; + return (mb_rt_t *)rt; } /*! \brief Create a new runtime for existed window for X. @@ -977,7 +975,7 @@ return NULL; } - return rt; + return (mb_rt_t *)rt; } static void @@ -1039,7 +1037,7 @@ mb_IO_man_t *io_man = xmb_rt->io_man; int hdl; - hdl = io_man->reg(io_man, fd, type, cb, data); + hdl = mb_io_man_reg(io_man, fd, type, cb, data); return hdl; } @@ -1049,7 +1047,7 @@ X_supp_runtime_t *xmb_rt = (X_supp_runtime_t *) rt; mb_IO_man_t *io_man = xmb_rt->io_man; - io_man->unreg(io_man, hdl); + mb_io_man_unreg(io_man, hdl); } static int