changeset 984:3fe8054457a8 refine_backend_if

Change interface of mb_backend_t for more concise
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 22 Nov 2010 00:42:29 +0800
parents a1ebbe11354d
children bab9c0f836b9
files include/mb_X_supp.h include/mb_backend.h include/mb_redraw_man.h src/X_supp.c
diffstat 4 files changed, 106 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/include/mb_X_supp.h	Thu Nov 18 12:10:51 2010 +0800
+++ b/include/mb_X_supp.h	Mon Nov 22 00:42:29 2010 +0800
@@ -37,4 +37,6 @@
 extern ob_factory_t *X_MB_ob_factory(void *xmb_rt);
 extern mb_img_ldr_t *X_MB_img_ldr(void *xmb_rt);
 
+#define MBB_WINDOW Window
+
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/mb_backend.h	Mon Nov 22 00:42:29 2010 +0800
@@ -0,0 +1,103 @@
+#ifndef __MB_BACKEND_H_
+#define __MB_BACKEND_H_
+
+#ifdef X_BACKEND
+#include "mb_X_supp.h"
+#endif
+
+#ifdef DFB_BACKEND
+#inclde "mb_dfb_supp.h"
+#endif
+
+typedef void *MBB_WINDOW;
+typedef void mb_rt_t;
+
+/*! \brief The backend engine mb_backend_t is used to define the
+ *         interface to realize the MB.
+ *
+ * A backend is used to receive events from the system. The MB does
+ * not define the backend by itself.  Instead, it define an interface
+ * which allow the lower layer to implement the event system. Each
+ * backend need to provides the following events.
+ *
+ * - keyboard event
+ * - timer event
+ * - image loader(?)
+ * - render manager(?)
+ */
+typedef struct {
+    mb_rt_t *(*new)(const char *display, int w,int h);
+    mb_rt_t *(*new_with_win)(const char *display, MBB_WINDOW win, int w,int h);
+    
+    void (*free)(mb_rt_t *rt);
+    void (*add_event)(mb_rt_t *rt,int type, int fd, mb_eventcb_t f,void *arg);
+    void (*remove_event)(mb_rt_t *rt,int type, int fd);
+    void (*loop)(mb_rt_t *rt);
+    
+    subject_t *(*kbevents)(mb_rt_t *rt);
+    redraw_man_t *(*rdman)(mb_rt_t *rt);
+    mb_timer_man_t *(*tman)(mb_rt_t *rt);
+    ob_factory_t *(*ob_factory)(mb_rt_t *rt);
+    mb_img_ldr_t *(*loader)(mb_rt_t *rt);
+    
+    /*
+     * 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);
+} mb_backend_t;
+
+extern mb_backend_t backend;
+
+/*! \brief Type of IO that registered with an IO manager.
+ */
+enum MB_IO_TYPE {MB_IO_R, MB_IO_W, MB_IO_RW};
+
+/*! \brief Function signature of callback functions for IO requests.
+ */
+typedef void (*mb_IO_cb_t)(int fd, MB_IO_TYPE type, void *data);
+
+/*! \brief IO Manager
+ */
+struct _mb_IO_man {
+    int (*reg)(struct _mb_IO_man *io_man,
+	       int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data);
+    void (*unreg)(struct _mb_IO_Man *io_man,
+		  int io_hdl);
+};
+typedef struct _mb_IO_man mb_IO_man_t;
+
+/*! \brief Factory of IO managers.
+ */
+struct _mb_IO_factory {
+    mb_IO_man_t *(*new)(void);
+    void (*free)(mb_IO_man_t *io_man);
+};
+typedef struct _mb_IO_factory mb_IO_factory_t;
+
+/*! \brief Function signature of callback functions for timers.
+ */
+typedef void (*mb_timer_cb_t)(mbsec_t sec, mbusec_t usec, 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);
+    /*! \brief Remove a timeout request.
+     *
+     * \param tm_hdl is the handle returned by _mb_timer_man::timeout.
+     */
+    void (*remove)(struct _mb_timer_man *tm_man, int tm_hdl);
+} mb_timer_man_t;
+
+/*! \brief Factory of timer manager.
+ */
+struct _mb_timer_factory {
+    mb_timer_man_t *(*new)(void);
+    void (*free)(mb_timer_man_t *timer_man);
+};
+typedef struct _mb_timer_factory mb_timer_factory_t;
+
+#endif /* __MB_BACKEND_H_ */
--- a/include/mb_redraw_man.h	Thu Nov 18 12:10:51 2010 +0800
+++ b/include/mb_redraw_man.h	Mon Nov 22 00:42:29 2010 +0800
@@ -243,31 +243,5 @@
 #define MONITOR_READ   1
 #define MONITOR_WRITE  2
 
-/*! \brief The backend engine mb_backend_t is used to define the interface to realize the MB.
- *
- * A backend is used to receive events from the system. The MB does not define the backend by itself.
- * Instead, it define an interface which allow the lower layer to implement the event system. Each
- * backend need to provides the following events.
- *
- * - keyboard event
- * - timer event
- * - image loader(?)
- * - render manager(?)
- */
-typedef struct {
-
-    void *(*init)(const char *display,int w,int h);
-    void (*free)(void *be);
-    void (*add_event)(void *be,int type, int fd, mb_eventcb_t f,void *arg);
-    void (*remove_event)(void *be,int type, int fd);
-    void (*loop)(void *be);
-    subject_t *(*kbevents)(void *be);
-    redraw_man_t *(*rdman)(void *be);
-    mb_tman_t *(*tman)(void *be);
-    ob_factory_t *(*factory)(void *be);
-    mb_img_ldr_t *(*loader)(void *be);
-} mb_backend_t;
-
-extern mb_backend_t backend;
 
 #endif /* __REDRAW_MAN_H_ */
--- a/src/X_supp.c	Thu Nov 18 12:10:51 2010 +0800
+++ b/src/X_supp.c	Mon Nov 22 00:42:29 2010 +0800
@@ -953,6 +953,7 @@
     }
 }
 mb_backend_t backend = { X_MB_new,
+			 X_MB_new_with_window,
 			 X_MB_free,
 			 X_MB_add_event,
 			 X_MB_remove_event,