changeset 550:127499ab2412 Android_Skia

Upgrade ndoejs plugin to level of a new runtime. Original, nodejs plugin is a variant of X runtime. But, now, I think it had better a new runtime that reuse code of X runtime. It would be easier to maintain.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 06 Jun 2010 13:58:01 +0800
parents 6ec4d7e90480
children 9e69c4a0f565
files nodejs/X_supp_njs.c nodejs/X_supp_njs.h src/X_supp.c
diffstat 3 files changed, 50 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/X_supp_njs.c	Sun Jun 06 13:48:13 2010 +0800
+++ b/nodejs/X_supp_njs.c	Sun Jun 06 13:58:01 2010 +0800
@@ -51,7 +51,7 @@
 x_conn_cb(EV_P_ ev_io *iowatcher, int revent) {
     njs_ev_data_t *ev_data = MEM2OBJ(iowatcher, njs_ev_data_t, iowatcher);
     redraw_man_t *rdman;
-    extern void _X_MB_handle_x_event_for_nodejs(X_MB_runtime_t *rt);
+    extern void _X_MB_handle_x_event_for_nodejs(void *rt);
 
     rdman = X_MB_rdman(ev_data->rt);
     _X_MB_handle_x_event_for_nodejs(ev_data->rt);
@@ -67,7 +67,7 @@
     mb_tman_t *tman;
     redraw_man_t *rdman;
     mb_timeval_t now;
-    extern int _X_MB_flush_x_conn_nodejs(X_MB_runtime_t *rt);
+    extern int _X_MB_flush_x_conn_nodejs(void *rt);
     
     tman = X_MB_tman(ev_data->rt);
     get_now(&now);
@@ -84,39 +84,30 @@
  *
  * \param rt is a runtime object for X.
  */
-void X_MB_handle_connection_njs(void *rt) {
-    X_MB_runtime_t *_rt = (X_MB_runtime_t *)rt;
-    njs_ev_data_t *ev_data;
+void
+X_njs_MB_handle_connection(njs_ev_data_t *ev_data) {
+    void *rt = ev_data->rt;
     mb_tman_t *tman;
     mb_timeval_t now, tmo;
     ev_tstamp tout;
     int fd;
     int r;
-    extern int _X_MB_get_x_conn_for_nodejs(X_MB_runtime_t *rt);
+    extern int _X_MB_get_x_conn_for_nodejs(void *rt);
 
-    ev_data = (njs_ev_data_t *)malloc(sizeof(njs_ev_data_t));
-    ASSERT(ev_data != NULL);
-    
-    _X_MB_set_data_nodejs(_rt, ev_data);
-    ev_data->rt = _rt;
-    ev_default_loop(0);
-    
     /*
      * Setup watcher for X connection.
      */
-    fd = _X_MB_get_x_conn_for_nodejs(_rt);
+    fd = _X_MB_get_x_conn_for_nodejs(rt);
     ev_io_init(&ev_data->iowatcher, x_conn_cb, fd, EV_READ);
     ev_io_start(&ev_data->iowatcher);
 
     set_next_timeout(ev_data);
 }
 
-void X_MB_stop_njs(void *rt) {
-    X_MB_runtime_t *_rt = (X_MB_runtime_t *)rt;
-    njs_ev_data_t *ev_data;
-
-    ev_data = (njs_ev_data_t *)_X_MB_get_x_conn_for_nodejs(_rt);
-    
+/*! \brief Free njs_ev_data_t.
+ */
+void
+X_njs_MB_free(njs_ev_data_t *ev_data) {
     /*
      * stop IO and timer watcher
      */
@@ -124,3 +115,24 @@
     if(ev_data->enable_timer)
 	ev_timer_stop(&ev_data->tmwatcher);
 }
+
+njs_ev_data_t *
+X_njs_MB_new(char *display_name, int w, int h) {
+    njs_ev_data_t *ev_data;
+    void *rt;
+    
+    ev_data = (njs_ev_data_t *)malloc(sizeof(njs_ev_data_t));
+    ASSERT(ev_data != NULL);
+
+    rt = X_MB_new(display_name, w, h);
+
+    ev_data->rt = rt;
+    ev_data->enable_timer = 0;	/* no timer, now */
+    
+    return ev_data;
+}
+
+void *
+_X_njs_MB_get_runtime(nsj_ev_data_t *ev_data) {
+    return ev_data->rt;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nodejs/X_supp_njs.h	Sun Jun 06 13:58:01 2010 +0800
@@ -0,0 +1,12 @@
+#ifndef __X_SUPP_NJS_H_
+#define __X_SUPP_NJS_H_
+
+struct _njs_ev_data;
+typedef struct _njs_ev_data njs_ev_data_t;
+
+extern void X_njs_MB_handle_connection(njs_ev_data_t *ev_data);
+extern void X_njs_MB_free(njs_ev_data_t *ev_data);
+extern njs_ev_data_t *X_njs_MB_new(char *display_name, int w, int h);
+extern void *_X_njs_MB_get_runtime(nsj_ev_data_t *ev_data);
+
+#endif /* __X_SUPP_NJS_H_ */
--- a/src/X_supp.c	Sun Jun 06 13:48:13 2010 +0800
+++ b/src/X_supp.c	Sun Jun 06 13:58:01 2010 +0800
@@ -48,8 +48,6 @@
     monitor_t monitors[MAX_MONITORS];
     int n_monitor;
 
-    void *nodejs_data;
-
 #ifndef ONLY_MOUSE_MOVE_RAW
     /* States */
     shape_t *last;
@@ -656,32 +654,20 @@
  */			 
 /*! \brief Exported for nodejs plugin to call handle_x_event.
  */
-void _X_MB_handle_x_event_for_nodejs(X_MB_runtime_t *rt) {
-    handle_x_event(rt);
+void _X_MB_handle_x_event_for_nodejs(void *rt) {
+    handle_x_event((X_MB_runtime_t *)rt);
 }
 
 /*! \brief Get X connect for nodejs plugin.
  */
-int _X_MB_get_x_conn_for_nodejs(X_MB_runtime_t *rt) {
-    return XConnectionNumber(rt->display);
+int _X_MB_get_x_conn_for_nodejs(void *rt) {
+    return XConnectionNumber(((X_MB_runtime_t *)rt)->display);
 }
 
 /*! \brief Flush buffer for the X connection of a runtime object.
  */
-int _X_MB_flush_x_conn_nodejs(X_MB_runtime_t *rt) {
-    return XFlush(rt->display);
-}
-
-/*! \brief Keep data for nodejs plugin.
- */
-void _X_MB_set_data_nodejs(X_MB_runtime_t *rt, void *data) {
-    rt->nodejs_data = data;
-}
-
-/*! \brief Get data for nodejs plugin.
- */
-void *_X_MB_get_data_nodejs(X_MB_runtime_t *rt) {
-    return rt->nodejs_data;
+int _X_MB_flush_x_conn_nodejs(void *rt) {
+    return XFlush(((X_MB_runtime_t *)rt)->display);
 }
 
 /* @} */