Mercurial > MadButterfly
changeset 1018:7ccc094bdbe5 refine_backend_if
Move the timer manager based on mb_tman_t to timer.c
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 22 Nov 2010 13:15:33 +0800 |
parents | 9b5d4839c5bb |
children | 1a3cc22ee1bd |
files | include/mb_animate.h include/mb_backend_utils.h include/mb_redraw_man.h src/X_supp.c src/timer.c |
diffstat | 5 files changed, 116 insertions(+), 96 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_animate.h Mon Nov 22 12:38:36 2010 +0800 +++ b/include/mb_animate.h Mon Nov 22 13:15:33 2010 +0800 @@ -4,8 +4,8 @@ #define __ANIMATE_H_ #include "mb_types.h" -#include "mb_timer.h" #include "mb_paint.h" +#include "mb_backend.h" /*! \page def_action How to Define An Action? *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/mb_backend_utils.h Mon Nov 22 13:15:33 2010 +0800 @@ -0,0 +1,12 @@ +#ifndef __MB_BACKEND_UTILS_H_ +#define __MB_BACKEND_UTILS_H_ + +#include "mb_backend.h" +#include "mb_timer.h" + +/*! \brief A facotry of timer manager implemented with mb_tman_t. + */ +extern mb_timer_factory_t tman_timer_factory; +extern mb_tman_t * tman_timer_man_get_tman(mb_timer_man_t *tm_man); + +#endif /* __MB_BACKEND_UTILS_H_ */
--- a/include/mb_redraw_man.h Mon Nov 22 12:38:36 2010 +0800 +++ b/include/mb_redraw_man.h Mon Nov 22 13:15:33 2010 +0800 @@ -8,7 +8,6 @@ #include "mb_types.h" #include "mb_observer.h" #include "mb_img_ldr.h" -#include "mb_timer.h" typedef struct _redraw_man redraw_man_t;
--- a/src/X_supp.c Mon Nov 22 12:38:36 2010 +0800 +++ b/src/X_supp.c Mon Nov 22 13:15:33 2010 +0800 @@ -11,6 +11,7 @@ #include "mb_timer.h" #include "mb_X_supp.h" #include "mb_backend.h" +#include "mb_backend_utils.h" #include "config.h" #ifdef XSHM @@ -27,6 +28,8 @@ #define ONLY_MOUSE_MOVE_RAW 1 +static mb_timer_factory_t *_timer_factory = &tman_timer_factory; + /*! \ingroup xkb * @{ */ @@ -79,99 +82,6 @@ int mbut_state; /* Button state of last motion event */ }; -/*! \defgroup x_supp_timer Timer manager for X. - * - * This implmentation of timer manager is based on mb_tman_t. - * @{ - */ -struct _X_supp_timer_man { - mb_timer_man_t timer_man; - mb_tman_t *tman; -}; - -static int _x_supp_timer_man_timeout(struct _mb_timer_man *tm_man, - mb_timeval_t *tmout, - mb_timer_cb_t cb, void *data); -static void _x_supp_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl); -static mb_timer_man_t *_x_supp_timer_fact_new(void); -static void _x_supp_timer_fact_free(mb_timer_man_t *timer_man); - -static struct _X_supp_timer_man _x_supp_default_timer_man = { - {_x_supp_timer_man_timeout, _x_supp_timer_man_remove}, - NULL -}; - -static mb_timer_factory_t _x_supp_default_timer_factory = { - _x_supp_timer_fact_new, - _x_supp_timer_fact_free -}; - -static mb_timer_factory_t *_timer_factory = &_x_supp_default_timer_factory; - -/*! \brief Content of a timeout request. - * - * This is only used by internal of X support. This data structure - * carry information to adopt mb_tman_t to mb_timer_man_t. - */ -struct _X_supp_timeout_data { - mb_timer_t *timer; /*!< Handle returned by mb_tman_timeout() */ - mb_timer_cb_t cb; /*!< Real callback function */ - void *data; /*!< data for real callback */ -}; - -static void -_x_supp_tmo_hdlr(const mb_timeval_t *tmo, - const mb_timeval_t *now, - void *arg) { - struct _X_supp_timeout_data *data = (struct _X_supp_timeout_data *)arg; - - data->cb((int)data, tmo, now, data->data); -} - -static int -_x_supp_timer_man_timeout(struct _mb_timer_man *tm_man, - mb_timeval_t *tmout, /* timeout (wall time) */ - mb_timer_cb_t cb, void *data) { - struct _X_supp_timer_man *timer_man = (struct _X_supp_timer_man *)tm_man; - mb_timer_t *timer; - struct _X_supp_timeout_data *tmout_data; - - tmout_data = O_ALLOC(struct _X_supp_timeout_data); - tmout_data->cb = cb; - tmout_data->data = data; - timer = mb_tman_timeout(timer_man->tman, tmout, - _x_supp_tmo_hdlr, tmout_data); - if(timer == NULL) - return ERR; - tmout_data->timer = timer; - - return (int)tmout_data; -} - -static void -_x_supp_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl) { - struct _X_supp_timer_man *timer_man = (struct _X_supp_timer_man *)tm_man; - struct _X_supp_timeout_data *tmout_data = - (struct _X_supp_timeout_data *)tm_hdl; - - mb_tman_remove(timer_man->tman, tmout_data->timer); - free(tmout_data); -} - -static mb_timer_man_t * -_x_supp_timer_fact_new(void) { - if(_x_supp_default_timer_man.tman == NULL) - _x_supp_default_timer_man.tman = mb_tman_new(); - return (mb_timer_man_t *)&_x_supp_default_timer_man; -} - -static void -_x_supp_timer_fact_free(mb_timer_man_t *timer_man) { -} - - -/* @} */ - static void _x_supp_handle_x_event(X_supp_runtime_t *rt); /*! \defgroup x_supp_io IO manager for X. @@ -266,7 +176,7 @@ 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_tman_t *tman = timer_man->tman; + mb_tman_t *tman = tman_timer_man_get_tman(timer_man); int fd; mb_timeval_t now, tmo; struct timeval tv;
--- a/src/timer.c Mon Nov 22 12:38:36 2010 +0800 +++ b/src/timer.c Mon Nov 22 13:15:33 2010 +0800 @@ -6,6 +6,7 @@ #include <string.h> #include "mb_timer.h" #include "mb_tools.h" +#include "mb_backend.h" #define OK 0 @@ -122,3 +123,101 @@ return OK; } + +/*! \defgroup tman_timer_man Timer manager based on mb_tman_t. + * + * This implmentation of timer manager is based on mb_tman_t. + * @{ + */ +struct _tman_timer_man { + mb_timer_man_t timer_man; + mb_tman_t *tman; +}; + +static int _tman_timer_man_timeout(struct _mb_timer_man *tm_man, + mb_timeval_t *tmout, + mb_timer_cb_t cb, void *data); +static void _tman_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl); +static mb_timer_man_t *_tman_timer_fact_new(void); +static void _tman_timer_fact_free(mb_timer_man_t *timer_man); + +static struct _tman_timer_man _tman_default_timer_man = { + {_tman_timer_man_timeout, _tman_timer_man_remove}, + NULL +}; + +mb_timer_factory_t tman_timer_factory = { + _tman_timer_fact_new, + _tman_timer_fact_free +}; + +/*! \brief Content of a timeout request. + * + * This is only used by internal of X support. This data structure + * carry information to adopt mb_tman_t to mb_timer_man_t. + */ +struct _tman_timeout_data { + mb_timer_t *timer; /*!< Handle returned by mb_tman_timeout() */ + mb_timer_cb_t cb; /*!< Real callback function */ + void *data; /*!< data for real callback */ +}; + +static void +_tman_tmo_hdlr(const mb_timeval_t *tmo, + const mb_timeval_t *now, + void *arg) { + struct _tman_timeout_data *data = (struct _tman_timeout_data *)arg; + + data->cb((int)data, tmo, now, data->data); +} + +static int +_tman_timer_man_timeout(struct _mb_timer_man *tm_man, + mb_timeval_t *tmout, /* timeout (wall time) */ + mb_timer_cb_t cb, void *data) { + struct _tman_timer_man *timer_man = (struct _tman_timer_man *)tm_man; + mb_timer_t *timer; + struct _tman_timeout_data *tmout_data; + + tmout_data = O_ALLOC(struct _tman_timeout_data); + tmout_data->cb = cb; + tmout_data->data = data; + timer = mb_tman_timeout(timer_man->tman, tmout, + _tman_tmo_hdlr, tmout_data); + if(timer == NULL) + return ERR; + tmout_data->timer = timer; + + return (int)tmout_data; +} + +static void +_tman_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl) { + struct _tman_timer_man *timer_man = (struct _tman_timer_man *)tm_man; + struct _tman_timeout_data *tmout_data = + (struct _tman_timeout_data *)tm_hdl; + + mb_tman_remove(timer_man->tman, tmout_data->timer); + free(tmout_data); +} + +static mb_timer_man_t * +_tman_timer_fact_new(void) { + if(_tman_default_timer_man.tman == NULL) + _tman_default_timer_man.tman = mb_tman_new(); + return (mb_timer_man_t *)&_tman_default_timer_man; +} + +static void +_tman_timer_fact_free(mb_timer_man_t *timer_man) { +} + +mb_tman_t * +tman_timer_man_get_tman(mb_timer_man_t *tm_man) { + struct _tman_timer_man *timer_man = (struct _tman_timer_man *)tm_man; + + return timer_man->tman; +} + + +/* @} */