Mercurial > MadButterfly
annotate nodejs/X_supp_njs.c @ 1041:eb3d2e3381cb refine_backend_if
Fix typo for mb_runtime_free_keep_win()
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 23 Nov 2010 11:42:01 +0800 |
parents | 22e5cf38d8e8 |
children | 18256f404193 |
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> |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 #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
|
11 #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
|
12 #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
|
13 #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
|
14 #include "mb_tools.h" |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
15 #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
|
16 |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 #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
|
18 #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
|
19 #endif |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 |
1039 | 21 #define OK 0 |
22 #define ERR -1 | |
23 | |
1040
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
24 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
25 /*! \defgroup njs_timer_man Timer manager for nodejs. |
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 */ |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
28 struct _njs_timer_tiemout { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
29 ev_timer tmwatcher; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
30 mb_timer_cb_t cb; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
31 mb_timeval_t *timeout; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
32 void *data; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
33 }; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
34 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
35 static int njs_timer_man_timeout(struct _mb_timer_man *tm_man, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
36 mb_timeval_t *tm_out, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
37 mb_timer_cb_t cb, void *data); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
38 static void 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
|
39 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
|
40 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
|
41 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
42 static mb_timer_man_t *njs_timer_man = { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
43 njs_timer_man_timeout, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
44 njs_timer_man_remove |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
45 }; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
46 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
47 static mb_timer_factory_t njs_timer_factory = { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
48 njs_timer_man_new, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
49 njs_timer_man_free |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
50 }; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
51 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
52 static void |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
53 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
|
54 struct _njs_timer_timeout *timer_timeout = |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
55 MEM2OBJ(tmwatcher, struct _njs_timer_timeout, tmwatcher); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
56 mb_timeval_t now; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
57 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
58 get_now(&now); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
59 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
|
60 timer_timeout->data); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
61 } |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
62 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
63 static int |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
64 njs_timer_man_timeout(struct _mb_timer_man *tm_man, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
65 mb_timeval_t *timeout, |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
66 mb_timer_cb_t cb, void *data) { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
67 struct _njs_timer_timeout *timer_timeout; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
68 mb_timeval_t now, timeout_diff; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
69 ev_tstamp timeout_stamp; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
70 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
71 timer_timeout = O_ALLOC(struct _njs_timer_timeout); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
72 if(timer_timeout == NULL) |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
73 return ERR; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
74 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
75 timer_timeout->cb = cb; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
76 timer_timeout->timeout = timeout; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
77 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
78 get_now(&now); |
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 memcpy(&timeout_diff, timeout, sizeof(mb_timeval_t)); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
81 MB_TIMEVAL_DIFF(&timeout_diff, &now); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
82 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
|
83 (ev_tstamp)MB_TIMEVAL_USEC(&timeout_diff) / 1000000; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
84 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
|
85 timeout_stamp, 0); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
86 ev_timer_start(&timer_timeout->tmwatcher); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
87 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
88 return (int)timer_timeout; |
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 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
91 static void |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
92 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
|
93 struct _njs_timer_timeout *timer_timeout = |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
94 MEM2OBJ(tmwatcher, struct _njs_timer_timeout, tmwatcher); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
95 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
96 ev_timer_stop(&timer_timeout->tmwatcher); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
97 free(timer_timeout); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
98 } |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
99 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
100 static mb_timer_man_t * |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
101 njs_timer_man_new(void) { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
102 return &njs_timr_man; |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
103 } |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
104 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
105 static void |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
106 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
|
107 } |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
108 |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
109 void |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
110 X_njs_MB_reg_timer_man(void) { |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
111 mb_reg_timer_factory(&njs_timer_factory); |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
112 } |
22e5cf38d8e8
Timer manager for njs
Thinker K.F. Li <thinker@codemud.net>
parents:
1039
diff
changeset
|
113 |
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 |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
116 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
|
117 |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
118 /*! \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
|
119 */ |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
120 static void |
552 | 121 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
|
122 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
|
123 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
|
124 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
|
125 int r; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
126 |
552 | 127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 (ev_tstamp)MB_TIMEVAL_USEC(&tmo) / 1000000; |
552 | 134 ev_timer_init(&rt->tmwatcher, timer_cb, tout, 0); |
135 ev_timer_start(&rt->tmwatcher); | |
136 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
|
137 } else |
552 | 138 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
|
139 } |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
140 |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
141 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
|
142 x_conn_cb(EV_P_ ev_io *iowatcher, int revent) { |
552 | 143 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
|
144 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
|
145 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
|
146 |
552 | 147 rdman = X_MB_rdman(rt->xrt); |
148 _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
|
149 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
|
150 |
552 | 151 if(rt->enable_timer == 0) /* no installed timeout */ |
152 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
|
153 } |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
154 |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
155 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
|
156 timer_cb(EV_P_ ev_timer *tmwatcher, int revent) { |
552 | 157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 |
552 | 163 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
|
164 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
|
165 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
|
166 |
552 | 167 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
|
168 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
|
169 _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
|
170 |
552 | 171 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
|
172 } |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
173 |
1039 | 174 /*! \defgroup njs_io_man IO manager for nodejs. |
175 * @{ | |
176 */ | |
177 struct _njs_io_reg { | |
178 ev_io iowatcher; | |
179 int fd; | |
180 mb_IO_cb_t cb; | |
181 void *data; | |
182 }; | |
183 | |
184 static int njs_io_man_reg(struct _mb_IO_man *io_man, | |
185 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data); | |
186 static void njs_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl); | |
187 static mb_IO_man_t *njs_io_man_new(void); | |
188 static void njs_io_man_free(mb_IO_man_t *io_man); | |
189 | |
190 static mb_IO_man_t njs_io_man = { | |
191 njs_io_man_reg, | |
192 njs_io_man_unreg | |
193 }; | |
194 | |
195 /*! \brief IO factory to integrate MadButterfly to event loop of nodejs. | |
196 */ | |
197 static mb_IO_factory_t njs_io_factory = { | |
198 njs_io_man_new, | |
199 njs_io_man_free | |
200 }; | |
201 | |
202 /*! \brief Bridge libev callback to IO manager callback. | |
203 */ | |
204 static void | |
205 njs_io_man_cb(EV_P_ ev_io *iowatcher, int revent) { | |
206 struct _njs_io_reg *io_reg = | |
207 MEM2OBJ(iowatcher, struct _njs_io_reg, iowatcher); | |
208 MB_IO_TYPE type; | |
209 | |
210 switch(revent & (EV_READ | EV_WRITE)) { | |
211 case EV_READ: | |
212 type = MB_IO_R; | |
213 break; | |
214 case EV_WRITE: | |
215 type = MB_IO_W; | |
216 break; | |
217 case EV_READ | EV_WRITE: | |
218 type = MB_IO_RW; | |
219 break; | |
220 } | |
221 | |
222 io_reg->cb((int)io_reg, io_reg->fd, type, io_reg->data); | |
223 } | |
224 | |
225 static int | |
226 njs_io_man_reg(struct _mb_IO_man *io_man, | |
227 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data) { | |
228 int _type; | |
229 struct _njs_io_reg *io_reg; | |
230 | |
231 if(type == MB_IO_R) | |
232 _type = EV_READ; | |
233 else if(type == MB_IO_W) | |
234 _type == EV_WRITE; | |
235 else if(type == MB_IO_RW) | |
236 _type == EV_READ | EV_WRITE; | |
237 else | |
238 return ERR; | |
239 | |
240 io_reg = O_ALLOC(struct _njs_io_reg); | |
241 if(io_reg == NULL) | |
242 return ERR; | |
243 | |
244 io_reg->fd = fd; | |
245 io_reg->cb = cb; | |
246 io_reg->data = data; | |
247 | |
248 ev_io_init(&io_reg->iowatcher, njs_io_man_cb, fd, _type); | |
249 ev_io_start(&io_reg->iowatcher); | |
250 | |
251 return (int)io_reg; | |
252 } | |
253 | |
254 static void | |
255 njs_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl) { | |
256 struct _njs_io_reg *io_reg = (struct _njs_io_reg *)io_hdl; | |
257 | |
258 ev_io_stop(&io_reg->iowatcher); | |
259 free(io_reg); | |
260 } | |
261 | |
262 static mb_IO_man_t * | |
263 njs_io_man_new(void) { | |
264 return &njs_io_man; | |
265 } | |
266 | |
267 static void | |
268 njs_io_man_free(mb_IO_man_t *io_man) { | |
269 } | |
270 | |
271 /*! \brief Register an IO factory with MadButterfly backend. | |
272 */ | |
273 void | |
274 X_njs_MB_reg_IO_man(void) { | |
275 mb_reg_IO_facotry(&njs_io_factory); | |
276 } | |
277 | |
278 /* @} */ | |
279 | |
546
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
280 /*! \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
|
281 * |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
282 * \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
|
283 */ |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
284 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
|
285 X_njs_MB_init_handle_connection(njs_runtime_t *rt) { |
552 | 286 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
|
287 int fd; |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
288 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
|
289 |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
290 /* |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
291 * 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
|
292 */ |
551
9e69c4a0f565
rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents:
550
diff
changeset
|
293 fd = _X_MB_get_x_conn_for_nodejs(xrt); |
552 | 294 ev_io_init(&rt->iowatcher, x_conn_cb, fd, EV_READ); |
295 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
|
296 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
|
297 |
552 | 298 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
|
299 } |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
300 |
551
9e69c4a0f565
rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents:
550
diff
changeset
|
301 /*! \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
|
302 */ |
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
303 void |
552 | 304 X_njs_MB_free(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
|
305 /* |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
306 * stop IO and timer watcher |
249bcbf07eb0
Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
307 */ |
554
4caf6090825f
Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents:
553
diff
changeset
|
308 if(rt->enable_io) |
4caf6090825f
Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents:
553
diff
changeset
|
309 ev_io_stop(&rt->iowatcher); |
552 | 310 if(rt->enable_timer) |
311 ev_timer_stop(&rt->tmwatcher); | |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
312 |
554
4caf6090825f
Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents:
553
diff
changeset
|
313 X_MB_free(rt->xrt); |
4caf6090825f
Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents:
553
diff
changeset
|
314 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
|
315 } |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
316 |
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
|
317 /*! \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
|
318 */ |
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 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
|
320 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
|
321 /* |
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 * stop IO and timer watcher |
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 */ |
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
|
324 if(rt->enable_io) |
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 ev_io_stop(&rt->iowatcher); |
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
|
326 if(rt->enable_timer) |
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 ev_timer_stop(&rt->tmwatcher); |
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 X_MB_free_keep_win(rt->xrt); |
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
|
330 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
|
331 } |
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
|
332 |
571
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
333 int |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
334 X_njs_MB_flush(njs_runtime_t *rt) { |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
335 void *xrt = rt->xrt; |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
336 int r; |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
337 extern int _X_MB_flush_x_conn_for_nodejs(void *rt); |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
338 |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
339 _X_MB_flush_x_conn_for_nodejs(xrt); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
340 |
571
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
341 return r; |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
342 } |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
343 |
551
9e69c4a0f565
rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents:
550
diff
changeset
|
344 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
|
345 X_njs_MB_new(char *display_name, int w, int h) { |
552 | 346 njs_runtime_t *rt; |
551
9e69c4a0f565
rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents:
550
diff
changeset
|
347 void *xrt; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
348 |
552 | 349 rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t)); |
350 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
|
351 |
551
9e69c4a0f565
rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents:
550
diff
changeset
|
352 xrt = X_MB_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
|
353 |
552 | 354 rt->xrt = xrt; |
554
4caf6090825f
Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents:
553
diff
changeset
|
355 rt->enable_io = 0; |
552 | 356 rt->enable_timer = 0; /* no timer, now */ |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
753
diff
changeset
|
357 |
552 | 358 return rt; |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
359 } |
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
546
diff
changeset
|
360 |
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
|
361 /*! \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
|
362 * |
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 * 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
|
364 * 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
|
365 */ |
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 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
|
367 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
|
368 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
|
369 void *xrt; |
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 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
|
372 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
|
373 |
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
|
374 xrt = X_MB_new_with_win((Display *)display, 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
|
375 |
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
|
376 rt->xrt = xrt; |
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
|
377 rt->enable_io = 0; |
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
|
378 rt->enable_timer = 0; /* no timer, now */ |
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
|
379 |
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
|
380 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
|
381 } |
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
|
382 |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
383 /*! \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
|
384 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
385 void |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
386 X_njs_MB_handle_single_event(njs_runtime_t *rt, void *evt) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
387 void *xrt = rt->xrt; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
388 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
|
389 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
390 _X_MB_handle_single_event(xrt, evt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
391 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
392 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
393 /*! \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
|
394 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
395 void |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
396 X_njs_MB_no_more_event(njs_runtime_t *rt) { |
1039 | 397 mb_rt_t *xrt = rt->xrt; |
398 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
|
399 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
400 _X_MB_no_more_event(xrt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
401 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
402 |
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
|
403 /*! \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
|
404 */ |
1039 | 405 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
|
406 _X_njs_MB_get_X_runtime(njs_runtime_t *rt) { |
552 | 407 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
|
408 } |