Mercurial > MadButterfly
changeset 1042:18256f404193 refine_backend_if
nodejs binding passes compiling
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 23 Nov 2010 11:44:27 +0800 |
parents | eb3d2e3381cb |
children | 769921baf111 |
files | nodejs/X_supp_njs.c nodejs/X_supp_njs.h nodejs/mbfly_njs.cc |
diffstat | 3 files changed, 35 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/X_supp_njs.c Tue Nov 23 11:42:01 2010 +0800 +++ b/nodejs/X_supp_njs.c Tue Nov 23 11:44:27 2010 +0800 @@ -7,11 +7,13 @@ * The part is about */ #include <stdio.h> +#include <string.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <ev.h> #include "mb_X_supp.h" #include "mb_tools.h" +#include <mb_backend.h> #include "X_supp_njs.h" #ifndef ASSERT @@ -25,21 +27,21 @@ /*! \defgroup njs_timer_man Timer manager for nodejs. * @{ */ -struct _njs_timer_tiemout { +struct _njs_timer_timeout { ev_timer tmwatcher; mb_timer_cb_t cb; mb_timeval_t *timeout; void *data; }; -static int njs_timer_man_timeout(struct _mb_timer_man *tm_man, +static int njs_timer_man_timeout(mb_timer_man_t *tm_man, mb_timeval_t *tm_out, mb_timer_cb_t cb, void *data); -static void njs_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl); +static void njs_timer_man_remove(mb_timer_man_t *tm_man, int tm_hdl); static mb_timer_man_t *njs_timer_man_new(void); static void njs_timer_man_free(mb_timer_man_t *timer_man); -static mb_timer_man_t *njs_timer_man = { +static mb_timer_man_t njs_timer_man = { njs_timer_man_timeout, njs_timer_man_remove }; @@ -61,7 +63,7 @@ } static int -njs_timer_man_timeout(struct _mb_timer_man *tm_man, +njs_timer_man_timeout(mb_timer_man_t *tm_man, mb_timeval_t *timeout, mb_timer_cb_t cb, void *data) { struct _njs_timer_timeout *timer_timeout; @@ -91,7 +93,7 @@ static void njs_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl) { struct _njs_timer_timeout *timer_timeout = - MEM2OBJ(tmwatcher, struct _njs_timer_timeout, tmwatcher); + (struct _njs_timer_timeout *)tm_hdl; ev_timer_stop(&timer_timeout->tmwatcher); free(timer_timeout); @@ -99,7 +101,7 @@ static mb_timer_man_t * njs_timer_man_new(void) { - return &njs_timr_man; + return &njs_timer_man; } static void @@ -113,6 +115,7 @@ /* @} */ +#ifdef USE_MB_TMAN static void timer_cb(EV_P_ ev_timer *tmwatcher, int revent); /*! \brief Register next timeout with libev. @@ -171,6 +174,8 @@ set_next_timeout(rt); } +#endif /* USE_MB_TMAN */ + /*! \defgroup njs_io_man IO manager for nodejs. * @{ */ @@ -231,9 +236,9 @@ if(type == MB_IO_R) _type = EV_READ; else if(type == MB_IO_W) - _type == EV_WRITE; + _type = EV_WRITE; else if(type == MB_IO_RW) - _type == EV_READ | EV_WRITE; + _type = EV_READ | EV_WRITE; else return ERR; @@ -272,11 +277,12 @@ */ void X_njs_MB_reg_IO_man(void) { - mb_reg_IO_facotry(&njs_io_factory); + mb_reg_IO_factory(&njs_io_factory); } /* @} */ +#if 0 /*! \brief Handle connection coming data and timeout of timers. * * \param rt is a runtime object for X. @@ -297,20 +303,16 @@ set_next_timeout(rt); } +#endif /*! \brief Free njs_runtime_t. */ void X_njs_MB_free(njs_runtime_t *rt) { - /* - * stop IO and timer watcher + /*! + * TODO: Release all IO and timer request. */ - if(rt->enable_io) - ev_io_stop(&rt->iowatcher); - if(rt->enable_timer) - ev_timer_stop(&rt->tmwatcher); - - X_MB_free(rt->xrt); + mb_runtime_free(rt->xrt); free(rt); } @@ -319,41 +321,32 @@ void X_njs_MB_free_keep_win(njs_runtime_t *rt) { /* - * stop IO and timer watcher + * TODO: Release all IO and timer request. */ - if(rt->enable_io) - ev_io_stop(&rt->iowatcher); - if(rt->enable_timer) - ev_timer_stop(&rt->tmwatcher); - - X_MB_free_keep_win(rt->xrt); + mb_runtime_free_keep_win(rt->xrt); free(rt); } int X_njs_MB_flush(njs_runtime_t *rt) { - void *xrt = rt->xrt; + mb_rt_t *mb_rt = rt->xrt; int r; - extern int _X_MB_flush_x_conn_for_nodejs(void *rt); - _X_MB_flush_x_conn_for_nodejs(xrt); - + r = mb_runtime_flush(mb_rt); return r; } njs_runtime_t * X_njs_MB_new(char *display_name, int w, int h) { njs_runtime_t *rt; - void *xrt; + mb_rt_t *mb_rt; rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t)); ASSERT(rt != NULL); - xrt = X_MB_new(display_name, w, h); + mb_rt = mb_runtime_new(display_name, w, h); - rt->xrt = xrt; - rt->enable_io = 0; - rt->enable_timer = 0; /* no timer, now */ + rt->xrt = mb_rt; return rt; } @@ -366,16 +359,14 @@ njs_runtime_t * X_njs_MB_new_with_win(void *display, long win) { njs_runtime_t *rt; - void *xrt; + mb_rt_t *mb_rt; rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t)); ASSERT(rt != NULL); - xrt = X_MB_new_with_win((Display *)display, win); + mb_rt = mb_runtime_new_with_win((Display *)display, win); - rt->xrt = xrt; - rt->enable_io = 0; - rt->enable_timer = 0; /* no timer, now */ + rt->xrt = mb_rt; return rt; } @@ -384,20 +375,24 @@ */ void X_njs_MB_handle_single_event(njs_runtime_t *rt, void *evt) { +#if 0 void *xrt = rt->xrt; extern void _X_MB_handle_single_event(void *rt, void *evt); _X_MB_handle_single_event(xrt, evt); +#endif } /*! \brief Called at end of an iteration of event loop. */ void X_njs_MB_no_more_event(njs_runtime_t *rt) { +#if 0 mb_rt_t *xrt = rt->xrt; extern void _X_MB_no_more_event(mb_rt_t *rt); _X_MB_no_more_event(xrt); +#endif } /*! \brief Get X runtime that is backend of this njs runtime.
--- a/nodejs/X_supp_njs.h Tue Nov 23 11:42:01 2010 +0800 +++ b/nodejs/X_supp_njs.h Tue Nov 23 11:44:27 2010 +0800 @@ -7,14 +7,12 @@ #include <mb_backend.h> typedef struct _njs_runtime { - int enable_io; - int enable_timer; mb_rt_t *xrt; } njs_runtime_t; extern void X_njs_MB_reg_timer_man(void); extern void X_njs_MB_reg_IO_man(void); -extern void X_njs_MB_init_handle_connection(njs_runtime_t *rt); +/* extern void X_njs_MB_init_handle_connection(njs_runtime_t *rt); */ extern void X_njs_MB_free(njs_runtime_t *rt); extern njs_runtime_t *X_njs_MB_new(char *display_name, int w, int h); extern void X_njs_MB_free_keep_win(njs_runtime_t *rt);
--- a/nodejs/mbfly_njs.cc Tue Nov 23 11:42:01 2010 +0800 +++ b/nodejs/mbfly_njs.cc Tue Nov 23 11:44:27 2010 +0800 @@ -80,7 +80,6 @@ * it is wrapped after returning of * this function. So, we wrap it * here. */ - X_njs_MB_init_handle_connection(obj); xnjsmb_coord_mkroot(self); subject = X_njs_MB_kbevents(obj);