comparison nodejs/X_supp_njs.c @ 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 249bcbf07eb0
children 9e69c4a0f565
comparison
equal deleted inserted replaced
549:6ec4d7e90480 550:127499ab2412
49 49
50 static void 50 static void
51 x_conn_cb(EV_P_ ev_io *iowatcher, int revent) { 51 x_conn_cb(EV_P_ ev_io *iowatcher, int revent) {
52 njs_ev_data_t *ev_data = MEM2OBJ(iowatcher, njs_ev_data_t, iowatcher); 52 njs_ev_data_t *ev_data = MEM2OBJ(iowatcher, njs_ev_data_t, iowatcher);
53 redraw_man_t *rdman; 53 redraw_man_t *rdman;
54 extern void _X_MB_handle_x_event_for_nodejs(X_MB_runtime_t *rt); 54 extern void _X_MB_handle_x_event_for_nodejs(void *rt);
55 55
56 rdman = X_MB_rdman(ev_data->rt); 56 rdman = X_MB_rdman(ev_data->rt);
57 _X_MB_handle_x_event_for_nodejs(ev_data->rt); 57 _X_MB_handle_x_event_for_nodejs(ev_data->rt);
58 rdman_redraw_changed(rdman); 58 rdman_redraw_changed(rdman);
59 59
65 timer_cb(EV_P_ ev_timer *tmwatcher, int revent) { 65 timer_cb(EV_P_ ev_timer *tmwatcher, int revent) {
66 njs_ev_data_t *ev_data = MEM2OBJ(tmwatcher, njs_ev_data_t, tmwatcher); 66 njs_ev_data_t *ev_data = MEM2OBJ(tmwatcher, njs_ev_data_t, tmwatcher);
67 mb_tman_t *tman; 67 mb_tman_t *tman;
68 redraw_man_t *rdman; 68 redraw_man_t *rdman;
69 mb_timeval_t now; 69 mb_timeval_t now;
70 extern int _X_MB_flush_x_conn_nodejs(X_MB_runtime_t *rt); 70 extern int _X_MB_flush_x_conn_nodejs(void *rt);
71 71
72 tman = X_MB_tman(ev_data->rt); 72 tman = X_MB_tman(ev_data->rt);
73 get_now(&now); 73 get_now(&now);
74 mb_tman_handle_timeout(tman, &now); 74 mb_tman_handle_timeout(tman, &now);
75 75
82 82
83 /*! \brief Handle connection coming data and timeout of timers. 83 /*! \brief Handle connection coming data and timeout of timers.
84 * 84 *
85 * \param rt is a runtime object for X. 85 * \param rt is a runtime object for X.
86 */ 86 */
87 void X_MB_handle_connection_njs(void *rt) { 87 void
88 X_MB_runtime_t *_rt = (X_MB_runtime_t *)rt; 88 X_njs_MB_handle_connection(njs_ev_data_t *ev_data) {
89 njs_ev_data_t *ev_data; 89 void *rt = ev_data->rt;
90 mb_tman_t *tman; 90 mb_tman_t *tman;
91 mb_timeval_t now, tmo; 91 mb_timeval_t now, tmo;
92 ev_tstamp tout; 92 ev_tstamp tout;
93 int fd; 93 int fd;
94 int r; 94 int r;
95 extern int _X_MB_get_x_conn_for_nodejs(X_MB_runtime_t *rt); 95 extern int _X_MB_get_x_conn_for_nodejs(void *rt);
96 96
97 ev_data = (njs_ev_data_t *)malloc(sizeof(njs_ev_data_t));
98 ASSERT(ev_data != NULL);
99
100 _X_MB_set_data_nodejs(_rt, ev_data);
101 ev_data->rt = _rt;
102 ev_default_loop(0);
103
104 /* 97 /*
105 * Setup watcher for X connection. 98 * Setup watcher for X connection.
106 */ 99 */
107 fd = _X_MB_get_x_conn_for_nodejs(_rt); 100 fd = _X_MB_get_x_conn_for_nodejs(rt);
108 ev_io_init(&ev_data->iowatcher, x_conn_cb, fd, EV_READ); 101 ev_io_init(&ev_data->iowatcher, x_conn_cb, fd, EV_READ);
109 ev_io_start(&ev_data->iowatcher); 102 ev_io_start(&ev_data->iowatcher);
110 103
111 set_next_timeout(ev_data); 104 set_next_timeout(ev_data);
112 } 105 }
113 106
114 void X_MB_stop_njs(void *rt) { 107 /*! \brief Free njs_ev_data_t.
115 X_MB_runtime_t *_rt = (X_MB_runtime_t *)rt; 108 */
116 njs_ev_data_t *ev_data; 109 void
117 110 X_njs_MB_free(njs_ev_data_t *ev_data) {
118 ev_data = (njs_ev_data_t *)_X_MB_get_x_conn_for_nodejs(_rt);
119
120 /* 111 /*
121 * stop IO and timer watcher 112 * stop IO and timer watcher
122 */ 113 */
123 ev_io_stop(&ev_data->iowatcher); 114 ev_io_stop(&ev_data->iowatcher);
124 if(ev_data->enable_timer) 115 if(ev_data->enable_timer)
125 ev_timer_stop(&ev_data->tmwatcher); 116 ev_timer_stop(&ev_data->tmwatcher);
126 } 117 }
118
119 njs_ev_data_t *
120 X_njs_MB_new(char *display_name, int w, int h) {
121 njs_ev_data_t *ev_data;
122 void *rt;
123
124 ev_data = (njs_ev_data_t *)malloc(sizeof(njs_ev_data_t));
125 ASSERT(ev_data != NULL);
126
127 rt = X_MB_new(display_name, w, h);
128
129 ev_data->rt = rt;
130 ev_data->enable_timer = 0; /* no timer, now */
131
132 return ev_data;
133 }
134
135 void *
136 _X_njs_MB_get_runtime(nsj_ev_data_t *ev_data) {
137 return ev_data->rt;
138 }