Mercurial > MadButterfly
annotate nodejs/X_supp_njs.c @ 1051:8679b03f72e8
Move declaration about sprite to a separated header file.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 24 Nov 2010 14:19:00 +0800 |
parents | 18256f404193 |
children | df6ee4568ca2 |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 /*! \brief Implement X11 backend for nodejs plugin. |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 * |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 * Since nodejs use libev to handle event loops, part of X11 backend |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 * code can not be used directly. The part of code should be rewrote. |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 * The part is about |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 */ |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 #include <stdio.h> |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
10 #include <string.h> |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 #include <X11/Xlib.h> |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 #include <X11/Xutil.h> |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 #include <ev.h> |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 #include "mb_X_supp.h" |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 #include "mb_tools.h" |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
16 #include <mb_backend.h> |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
17 #include "X_supp_njs.h" |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 #ifndef ASSERT |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 #define ASSERT(x) |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 #endif |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 |
1039 | 23 #define OK 0 |
24 #define ERR -1 | |
25 | |
1040
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
26 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
27 /*! \defgroup njs_timer_man Timer manager for nodejs. |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
28 * @{ |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
29 */ |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
30 struct _njs_timer_timeout { |
1040
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
31 ev_timer tmwatcher; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
32 mb_timer_cb_t cb; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
33 mb_timeval_t *timeout; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
34 void *data; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
35 }; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
36 |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
37 static int njs_timer_man_timeout(mb_timer_man_t *tm_man, |
1040
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
38 mb_timeval_t *tm_out, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
39 mb_timer_cb_t cb, void *data); |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
40 static void njs_timer_man_remove(mb_timer_man_t *tm_man, int tm_hdl); |
1040
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
41 static mb_timer_man_t *njs_timer_man_new(void); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
42 static void njs_timer_man_free(mb_timer_man_t *timer_man); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
43 |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
44 static mb_timer_man_t njs_timer_man = { |
1040
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
45 njs_timer_man_timeout, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
46 njs_timer_man_remove |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
47 }; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
48 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
49 static mb_timer_factory_t njs_timer_factory = { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
50 njs_timer_man_new, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
51 njs_timer_man_free |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
52 }; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
53 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
54 static void |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
55 njs_timer_man_cb(EV_P_ ev_timer *tmwatcher, int revent) { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
56 struct _njs_timer_timeout *timer_timeout = |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
57 MEM2OBJ(tmwatcher, struct _njs_timer_timeout, tmwatcher); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
58 mb_timeval_t now; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
59 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
60 get_now(&now); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
61 timer_timeout->cb((int)timer_timeout, timer_timeout->timeout, &now, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
62 timer_timeout->data); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
63 } |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
64 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
65 static int |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
66 njs_timer_man_timeout(mb_timer_man_t *tm_man, |
1040
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
67 mb_timeval_t *timeout, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
68 mb_timer_cb_t cb, void *data) { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
69 struct _njs_timer_timeout *timer_timeout; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
70 mb_timeval_t now, timeout_diff; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
71 ev_tstamp timeout_stamp; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
72 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
73 timer_timeout = O_ALLOC(struct _njs_timer_timeout); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
74 if(timer_timeout == NULL) |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
75 return ERR; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
76 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
77 timer_timeout->cb = cb; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
78 timer_timeout->timeout = timeout; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
79 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
80 get_now(&now); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
81 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
82 memcpy(&timeout_diff, timeout, sizeof(mb_timeval_t)); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
83 MB_TIMEVAL_DIFF(&timeout_diff, &now); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
84 timeout_stamp = (ev_tstamp)MB_TIMEVAL_SEC(&timeout_diff) + |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
85 (ev_tstamp)MB_TIMEVAL_USEC(&timeout_diff) / 1000000; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
86 ev_timer_init(&timer_timeout->tmwatcher, njs_timer_man_cb, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
87 timeout_stamp, 0); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
88 ev_timer_start(&timer_timeout->tmwatcher); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
89 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
90 return (int)timer_timeout; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
91 } |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
92 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
93 static void |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
94 njs_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl) { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
95 struct _njs_timer_timeout *timer_timeout = |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
96 (struct _njs_timer_timeout *)tm_hdl; |
1040
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
97 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
98 ev_timer_stop(&timer_timeout->tmwatcher); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
99 free(timer_timeout); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
100 } |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
101 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
102 static mb_timer_man_t * |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
103 njs_timer_man_new(void) { |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
104 return &njs_timer_man; |
1040
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
105 } |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
106 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
107 static void |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
108 njs_timer_man_free(mb_timer_man_t *timer_man) { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
109 } |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
110 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
111 void |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
112 X_njs_MB_reg_timer_man(void) { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
113 mb_reg_timer_factory(&njs_timer_factory); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
114 } |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
115 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
116 /* @} */ |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
117 |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
118 #ifdef USE_MB_TMAN |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
119 static void timer_cb(EV_P_ ev_timer *tmwatcher, int revent); |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
120 |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
121 /*! \brief Register next timeout with libev. |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
122 */ |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
123 static void |
552 | 124 set_next_timeout(njs_runtime_t *rt) { |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
125 mb_tman_t *tman; |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
126 mb_timeval_t now, tmo; |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
127 ev_tstamp tout; |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
128 int r; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
129 |
552 | 130 tman = X_MB_tman(rt->xrt); |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
131 get_now(&now); |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
132 r = mb_tman_next_timeout(tman, &now, &tmo); |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
133 if(r == 0) { |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
134 MB_TIMEVAL_DIFF(&tmo, &now); |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
135 tout = (ev_tstamp)MB_TIMEVAL_SEC(&tmo) + |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
136 (ev_tstamp)MB_TIMEVAL_USEC(&tmo) / 1000000; |
552 | 137 ev_timer_init(&rt->tmwatcher, timer_cb, tout, 0); |
138 ev_timer_start(&rt->tmwatcher); | |
139 rt->enable_timer = 1; | |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
140 } else |
552 | 141 rt->enable_timer = 0; |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
142 } |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
143 |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
144 static void |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
145 x_conn_cb(EV_P_ ev_io *iowatcher, int revent) { |
552 | 146 njs_runtime_t *rt = MEM2OBJ(iowatcher, njs_runtime_t, iowatcher); |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
147 redraw_man_t *rdman; |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
148 extern void _X_MB_handle_x_event_for_nodejs(void *rt); |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
149 |
552 | 150 rdman = X_MB_rdman(rt->xrt); |
151 _X_MB_handle_x_event_for_nodejs(rt->xrt); | |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
152 rdman_redraw_changed(rdman); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
153 |
552 | 154 if(rt->enable_timer == 0) /* no installed timeout */ |
155 set_next_timeout(rt); | |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
156 } |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
157 |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
158 static void |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
159 timer_cb(EV_P_ ev_timer *tmwatcher, int revent) { |
552 | 160 njs_runtime_t *rt = MEM2OBJ(tmwatcher, njs_runtime_t, tmwatcher); |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
161 mb_tman_t *tman; |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
162 redraw_man_t *rdman; |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
163 mb_timeval_t now; |
556
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
554
diff
changeset
|
164 extern int _X_MB_flush_x_conn_for_nodejs(void *rt); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
165 |
552 | 166 tman = X_MB_tman(rt->xrt); |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
167 get_now(&now); |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
168 mb_tman_handle_timeout(tman, &now); |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
169 |
552 | 170 rdman = X_MB_rdman(rt->xrt); |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
171 rdman_redraw_changed(rdman); |
556
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
554
diff
changeset
|
172 _X_MB_flush_x_conn_for_nodejs(rt->xrt); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
173 |
552 | 174 set_next_timeout(rt); |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
175 } |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
176 |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
177 #endif /* USE_MB_TMAN */ |
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
178 |
1039 | 179 /*! \defgroup njs_io_man IO manager for nodejs. |
180 * @{ | |
181 */ | |
182 struct _njs_io_reg { | |
183 ev_io iowatcher; | |
184 int fd; | |
185 mb_IO_cb_t cb; | |
186 void *data; | |
187 }; | |
188 | |
189 static int njs_io_man_reg(struct _mb_IO_man *io_man, | |
190 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data); | |
191 static void njs_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl); | |
192 static mb_IO_man_t *njs_io_man_new(void); | |
193 static void njs_io_man_free(mb_IO_man_t *io_man); | |
194 | |
195 static mb_IO_man_t njs_io_man = { | |
196 njs_io_man_reg, | |
197 njs_io_man_unreg | |
198 }; | |
199 | |
200 /*! \brief IO factory to integrate MadButterfly to event loop of nodejs. | |
201 */ | |
202 static mb_IO_factory_t njs_io_factory = { | |
203 njs_io_man_new, | |
204 njs_io_man_free | |
205 }; | |
206 | |
207 /*! \brief Bridge libev callback to IO manager callback. | |
208 */ | |
209 static void | |
210 njs_io_man_cb(EV_P_ ev_io *iowatcher, int revent) { | |
211 struct _njs_io_reg *io_reg = | |
212 MEM2OBJ(iowatcher, struct _njs_io_reg, iowatcher); | |
213 MB_IO_TYPE type; | |
214 | |
215 switch(revent & (EV_READ | EV_WRITE)) { | |
216 case EV_READ: | |
217 type = MB_IO_R; | |
218 break; | |
219 case EV_WRITE: | |
220 type = MB_IO_W; | |
221 break; | |
222 case EV_READ | EV_WRITE: | |
223 type = MB_IO_RW; | |
224 break; | |
225 } | |
226 | |
227 io_reg->cb((int)io_reg, io_reg->fd, type, io_reg->data); | |
228 } | |
229 | |
230 static int | |
231 njs_io_man_reg(struct _mb_IO_man *io_man, | |
232 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data) { | |
233 int _type; | |
234 struct _njs_io_reg *io_reg; | |
235 | |
236 if(type == MB_IO_R) | |
237 _type = EV_READ; | |
238 else if(type == MB_IO_W) | |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
239 _type = EV_WRITE; |
1039 | 240 else if(type == MB_IO_RW) |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
241 _type = EV_READ | EV_WRITE; |
1039 | 242 else |
243 return ERR; | |
244 | |
245 io_reg = O_ALLOC(struct _njs_io_reg); | |
246 if(io_reg == NULL) | |
247 return ERR; | |
248 | |
249 io_reg->fd = fd; | |
250 io_reg->cb = cb; | |
251 io_reg->data = data; | |
252 | |
253 ev_io_init(&io_reg->iowatcher, njs_io_man_cb, fd, _type); | |
254 ev_io_start(&io_reg->iowatcher); | |
255 | |
256 return (int)io_reg; | |
257 } | |
258 | |
259 static void | |
260 njs_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl) { | |
261 struct _njs_io_reg *io_reg = (struct _njs_io_reg *)io_hdl; | |
262 | |
263 ev_io_stop(&io_reg->iowatcher); | |
264 free(io_reg); | |
265 } | |
266 | |
267 static mb_IO_man_t * | |
268 njs_io_man_new(void) { | |
269 return &njs_io_man; | |
270 } | |
271 | |
272 static void | |
273 njs_io_man_free(mb_IO_man_t *io_man) { | |
274 } | |
275 | |
276 /*! \brief Register an IO factory with MadButterfly backend. | |
277 */ | |
278 void | |
279 X_njs_MB_reg_IO_man(void) { | |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
280 mb_reg_IO_factory(&njs_io_factory); |
1039 | 281 } |
282 | |
283 /* @} */ | |
284 | |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
285 #if 0 |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
286 /*! \brief Handle connection coming data and timeout of timers. |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
287 * |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
288 * \param rt is a runtime object for X. |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
289 */ |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
290 void |
556
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
554
diff
changeset
|
291 X_njs_MB_init_handle_connection(njs_runtime_t *rt) { |
552 | 292 void *xrt = rt->xrt; |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
293 int fd; |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
294 extern int _X_MB_get_x_conn_for_nodejs(void *rt); |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
295 |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
296 /* |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
297 * Setup watcher for X connection. |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
298 */ |
551
9e69c4a0f565
rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents:
550
diff
changeset
|
299 fd = _X_MB_get_x_conn_for_nodejs(xrt); |
552 | 300 ev_io_init(&rt->iowatcher, x_conn_cb, fd, EV_READ); |
301 ev_io_start(&rt->iowatcher); | |
554
4caf6090825f
Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents:
553
diff
changeset
|
302 rt->enable_io = 1; |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
303 |
552 | 304 set_next_timeout(rt); |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
305 } |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
306 #endif |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
307 |
551
9e69c4a0f565
rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents:
550
diff
changeset
|
308 /*! \brief Free njs_runtime_t. |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
309 */ |
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
310 void |
552 | 311 X_njs_MB_free(njs_runtime_t *rt) { |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
312 /*! |
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
313 * TODO: Release all IO and timer request. |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
314 */ |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
315 mb_runtime_free(rt->xrt); |
554
4caf6090825f
Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents:
553
diff
changeset
|
316 free(rt); |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
317 } |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
318 |
871
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
319 /*! \brief Free njs_runtime_t. |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
320 */ |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
321 void |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
322 X_njs_MB_free_keep_win(njs_runtime_t *rt) { |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
323 /* |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
324 * TODO: Release all IO and timer request. |
871
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
325 */ |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
326 mb_runtime_free_keep_win(rt->xrt); |
871
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
327 free(rt); |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
328 } |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
329 |
571
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
330 int |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
331 X_njs_MB_flush(njs_runtime_t *rt) { |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
332 mb_rt_t *mb_rt = rt->xrt; |
571
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
333 int r; |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
334 |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
335 r = mb_runtime_flush(mb_rt); |
571
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
336 return r; |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
337 } |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
338 |
551
9e69c4a0f565
rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents:
550
diff
changeset
|
339 njs_runtime_t * |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
340 X_njs_MB_new(char *display_name, int w, int h) { |
552 | 341 njs_runtime_t *rt; |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
342 mb_rt_t *mb_rt; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
343 |
552 | 344 rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t)); |
345 ASSERT(rt != NULL); | |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
346 |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
347 mb_rt = mb_runtime_new(display_name, w, h); |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
348 |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
349 rt->xrt = mb_rt; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
350 |
552 | 351 return rt; |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
352 } |
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
353 |
871
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
354 /*! \brief Create a njs_runtime_t for an existed window. |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
355 * |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
356 * The njs_runtime_t created by this function must be free by |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
357 * X_njs_MB_free_keep_win(). |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
358 */ |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
359 njs_runtime_t * |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
360 X_njs_MB_new_with_win(void *display, long win) { |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
361 njs_runtime_t *rt; |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
362 mb_rt_t *mb_rt; |
871
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
363 |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
364 rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t)); |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
365 ASSERT(rt != NULL); |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
366 |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
367 mb_rt = mb_runtime_new_with_win((Display *)display, win); |
871
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
368 |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
369 rt->xrt = mb_rt; |
871
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
370 |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
371 return rt; |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
372 } |
67d0fed24120
Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
373 |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
374 /*! \brief Pass a X event to X runtime. |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
375 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
376 void |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
377 X_njs_MB_handle_single_event(njs_runtime_t *rt, void *evt) { |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
378 #if 0 |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
379 void *xrt = rt->xrt; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
380 extern void _X_MB_handle_single_event(void *rt, void *evt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
381 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
382 _X_MB_handle_single_event(xrt, evt); |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
383 #endif |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
384 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
385 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
386 /*! \brief Called at end of an iteration of event loop. |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
387 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
388 void |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
389 X_njs_MB_no_more_event(njs_runtime_t *rt) { |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
390 #if 0 |
1039 | 391 mb_rt_t *xrt = rt->xrt; |
392 extern void _X_MB_no_more_event(mb_rt_t *rt); | |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
393 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
394 _X_MB_no_more_event(xrt); |
1042
18256f404193
nodejs binding passes compiling
Thinker K.F. Li <thinker@codemud.net>
parents:
1040
diff
changeset
|
395 #endif |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
396 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
397 |
553
0a77b88500bf
rename _X_njs_MB_get_runtime to _X_njs_MB_get_X_runtime
Thinker K.F. Li <thinker@branda.to>
parents:
552
diff
changeset
|
398 /*! \brief Get X runtime that is backend of this njs runtime. |
0a77b88500bf
rename _X_njs_MB_get_runtime to _X_njs_MB_get_X_runtime
Thinker K.F. Li <thinker@branda.to>
parents:
552
diff
changeset
|
399 */ |
1039 | 400 mb_rt_t * |
553
0a77b88500bf
rename _X_njs_MB_get_runtime to _X_njs_MB_get_X_runtime
Thinker K.F. Li <thinker@branda.to>
parents:
552
diff
changeset
|
401 _X_njs_MB_get_X_runtime(njs_runtime_t *rt) { |
552 | 402 return rt->xrt; |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
403 } |