changeset 1009:595a06fc0157 refine_backend_if

Change X_MB_add/remove_event() to match new mb_backend_t
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 22 Nov 2010 00:42:30 +0800
parents 789f67288e1c
children feea3784b7ff
files include/mb_backend.h src/X_supp.c
diffstat 2 files changed, 15 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/include/mb_backend.h	Mon Nov 22 00:42:30 2010 +0800
+++ b/include/mb_backend.h	Mon Nov 22 00:42:30 2010 +0800
@@ -22,6 +22,7 @@
 typedef struct _mb_timer_factory mb_timer_factory_t;
 typedef struct _mb_IO_man mb_IO_man_t;
 typedef struct _mb_IO_factory mb_IO_factory_t;
+typedef enum _MB_IO_TYPE MB_IO_TYPE;
 
 /*! \brief The backend engine mb_backend_t is used to define the
  *         interface to realize the MB.
@@ -45,12 +46,13 @@
      *
      * This is used only when the backend is responsible for event loop.
      */
-    void (*add_event)(mb_rt_t *rt,int type, int fd, mb_eventcb_t f,void *arg);
+    int (*add_event)(mb_rt_t *rt, int fd, MB_IO_TYPE type,
+		     mb_eventcb_t f,void *arg);
     /*! \brief Request the backend to stop monitoring a file descriptor.
      *
      * This is used only when the backend is responsible for event loop.
      */
-    void (*remove_event)(mb_rt_t *rt,int type, int fd);
+    void (*remove_event)(mb_rt_t *rt, int hdl);
     /*! \brief Event Loop
      *
      * This is called when main application does not handle event
@@ -78,7 +80,6 @@
 /*! \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 enum _MB_IO_TYPE MB_IO_TYPE;
 
 /*! \brief Function signature of callback functions for IO requests.
  */
--- a/src/X_supp.c	Mon Nov 22 00:42:30 2010 +0800
+++ b/src/X_supp.c	Mon Nov 22 00:42:30 2010 +0800
@@ -1159,47 +1159,25 @@
     return img_ldr;
 }
 
-void X_MB_add_event(void *rt, int type, int fd, mb_eventcb_t f,void *arg)
+int X_MB_add_event(void *rt, int fd, MB_IO_TYPE type,
+		   mb_IO_cb_t cb, void *data)
 {
     X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt;
-    int i;
+    mb_IO_man_t *io_man = xmb_rt->io_man;
+    int hdl;
 
-    for(i=0;i<xmb_rt->n_monitor;i++) {
-        if (xmb_rt->monitors[i].type == type && xmb_rt->monitors[i].fd == fd) {
-	    xmb_rt->monitors[i].f = f;
-	    xmb_rt->monitors[i].arg = arg;
-	    return;
-	}
-    }
-    for(i=0;i<xmb_rt->n_monitor;i++) {
-        if (xmb_rt->monitors[i].type == 0) {
-	    xmb_rt->monitors[i].type = type;
-	    xmb_rt->monitors[i].fd = fd;
-	    xmb_rt->monitors[i].f = f;
-	    xmb_rt->monitors[i].arg = arg;
-	    return;
-	}
-    }
-    if (i == MAX_MONITORS) return;
-    xmb_rt->monitors[i].type = type;
-    xmb_rt->monitors[i].fd = fd;
-    xmb_rt->monitors[i].f = f;
-    xmb_rt->monitors[i].arg = arg;
-    i++;
-    xmb_rt->n_monitor=i;
+    hdl = io_man->reg(io_man, fd, type, cb, data);
+    return hdl;
 }
 
-void X_MB_remove_event(void *rt, int type, int fd)
+void X_MB_remove_event(void *rt, int hdl)
 {
     X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt;
-    int i;
-    for(i=0;i<xmb_rt->n_monitor;i++) {
-        if (xmb_rt->monitors[i].type == type && xmb_rt->monitors[i].fd == fd) {
-	    xmb_rt->monitors[i].type = 0;
-	    return;
-	}
-    }
+    mb_IO_man_t *io_man = xmb_rt->io_man;
+
+    io_man->unreg(io_man, hdl);
 }
+
 mb_backend_t backend = { X_MB_new,
 			 X_MB_new_with_window,