Mercurial > MadButterfly
comparison src/X_supp.c @ 991:1882700bb4b9 refine_backend_if
Adapt mb_tman_t to mb_timer_man_t
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 22 Nov 2010 00:42:29 +0800 |
parents | 8dd42310dd79 |
children | cfed7fb28d24 |
comparison
equal
deleted
inserted
replaced
990:8dd42310dd79 | 991:1882700bb4b9 |
---|---|
73 int mx, my; /* Position of last motion event */ | 73 int mx, my; /* Position of last motion event */ |
74 int mbut_state; /* Button state of last motion event */ | 74 int mbut_state; /* Button state of last motion event */ |
75 }; | 75 }; |
76 | 76 |
77 /*! \defgroup x_mb_timer Timer manager for X. | 77 /*! \defgroup x_mb_timer Timer manager for X. |
78 * | |
79 * This implmentation of timer manager is based on mb_tman_t. | |
78 * @{ | 80 * @{ |
79 */ | 81 */ |
80 struct _X_supp_timer_man { | 82 struct _X_supp_timer_man { |
81 mb_timer_man_t timer_man; | 83 mb_timer_man_t timer_man; |
82 mb_tman_t *tman; | 84 mb_tman_t *tman; |
99 _x_supp_timer_fact_free | 101 _x_supp_timer_fact_free |
100 }; | 102 }; |
101 | 103 |
102 static mb_timer_factory_t *_timer_factory = &_x_supp_default_timer_factory; | 104 static mb_timer_factory_t *_timer_factory = &_x_supp_default_timer_factory; |
103 | 105 |
106 /*! \brief Content of a timeout request. | |
107 * | |
108 * This is only used by internal of X support. This data structure | |
109 * carry information to adopt mb_tman_t to mb_timer_man_t. | |
110 */ | |
111 struct _X_supp_timeout_data { | |
112 mb_timer_t *timer; /*!< Handle returned by mb_tman_timeout() */ | |
113 mb_timer_cb_t cb; /*!< Real callback function */ | |
114 void *data; /*!< data for real callback */ | |
115 }; | |
116 | |
117 static void * | |
118 _x_supp_tmo_hdlr(const mb_timeval_t *tmo, | |
119 const mb_timeval_t *now, | |
120 void *arg) { | |
121 struct _X_supp_timeout_data *data = (struct _X_supp_timeout_data *)arg; | |
122 | |
123 data->cb((int)data, tmo, now, data->data); | |
124 } | |
125 | |
104 static int | 126 static int |
105 _x_supp_timer_man_timeout(struct _mb_timer_man *tm_man, | 127 _x_supp_timer_man_timeout(struct _mb_timer_man *tm_man, |
106 mbsec_t sec, mbusec_t usec, | 128 mb_timeval_t *tmout, /* timeout (wall time) */ |
107 mb_timer_cb_t cb, void *data) { | 129 mb_timer_cb_t cb, void *data) { |
108 struct _X_supp_timer_man *timer_man = (struct _X_supp_timer_man *)tm_man; | 130 struct _X_supp_timer_man *timer_man = (struct _X_supp_timer_man *)tm_man; |
109 mb_timer_t *timer; | 131 mb_timer_t *timer; |
110 mb_timeval_t tmo; | 132 struct _X_supp_timeout_data *tmout_data; |
111 | 133 |
112 timer = mb_tman_timeout(timer_man->tman, &tmo, cb, data); | 134 tmout_data = O_ALLOC(struct _X_supp_timeout_data); |
135 tmout_data->cb = cb; | |
136 tmout_data->data = data; | |
137 timer = mb_tman_timeout(timer_man->tman, tmout, | |
138 _x_supp_tmo_hdlr, tmout_data); | |
139 if(timer == NULL) | |
140 return ERR; | |
141 tmout_data->timer = timer; | |
142 | |
143 return (int)tmout_data; | |
113 } | 144 } |
114 | 145 |
115 static void | 146 static void |
116 _x_supp_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl) { | 147 _x_supp_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl) { |
148 struct _X_supp_timer_man *timer_man = (struct _X_supp_timer_man *)tm_man; | |
149 struct _X_supp_timeout_data *tmout_data = | |
150 (struct _X_supp_timeout_data *)tm_hdl; | |
151 | |
152 mb_tman_remove(timer_man->tman, tmout_data->timer); | |
153 free(tmout_data); | |
117 } | 154 } |
118 | 155 |
119 static mb_timer_man_t * | 156 static mb_timer_man_t * |
120 _x_supp_timer_fact_new(void) { | 157 _x_supp_timer_fact_new(void) { |
121 if(_x_supp_default_timer_man.tman == NULL) | 158 if(_x_supp_default_timer_man.tman == NULL) |