changeset 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 2cbe3721dc9a
files include/mb_backend.h src/X_supp.c
diffstat 2 files changed, 49 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/include/mb_backend.h	Mon Nov 22 00:42:29 2010 +0800
+++ b/include/mb_backend.h	Mon Nov 22 00:42:29 2010 +0800
@@ -1,6 +1,11 @@
 #ifndef __MB_BACKEND_H_
 #define __MB_BACKEND_H_
 
+#include "mb_redraw_man.h"
+#include "mb_timer.h"
+#include "mb_observer.h"
+#include "mb_img_ldr.h"
+
 #include "mb_config.h"
 
 #ifdef X_BACKEND
@@ -94,13 +99,15 @@
 
 /*! \brief Function signature of callback functions for timers.
  */
-typedef void (*mb_timer_cb_t)(int hdl, mbsec_t sec, mbusec_t usec, void *data);
+typedef void (*mb_timer_cb_t)(int hdl, mb_timeval_t *tmo, mb_timeval_t *now,
+			      void *data);
 
 /*! \brief Timer manager
  */
 struct _mb_timer_man {
     int (*timeout)(struct _mb_timer_man *tm_man,
-		   mbsec_t sec, mbusec_t usec, mb_timer_cb_t cb, void *data);
+		   mb_timeval_t *tmout, /* tiemout (wall time) */
+		   mb_timer_cb_t cb, void *data);
     /*! \brief Remove a timeout request.
      *
      * \param tm_hdl is the handle returned by _mb_timer_man::timeout.
--- a/src/X_supp.c	Mon Nov 22 00:42:29 2010 +0800
+++ b/src/X_supp.c	Mon Nov 22 00:42:29 2010 +0800
@@ -75,6 +75,8 @@
 };
 
 /*! \defgroup x_mb_timer Timer manager for X.
+ *
+ * This implmentation of timer manager is based on mb_tman_t.
  * @{
  */
 struct _X_supp_timer_man {
@@ -101,19 +103,54 @@
 
 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,
-			  mbsec_t sec, mbusec_t usec,
+			  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;
-    mb_timeval_t tmo;
+    struct _X_supp_timeout_data *tmout_data;
 
-    timer = mb_tman_timeout(timer_man->tman, &tmo, cb, 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 *