Mercurial > MadButterfly
annotate nodejs/observer.cc @ 658:62c2de99b03a
Remove get_object() method for subject for js
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 31 Jul 2010 16:16:45 +0800 |
parents | 38c720272dd5 |
children | fc29a343ce7c |
rev | line source |
---|---|
651
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 #include <v8.h> |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 #include "mbfly_njs.h" |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 extern "C" { |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 #include <mb.h> |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 #include <string.h> |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 } |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 #ifndef ASSERT |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 #define ASSERT(x) |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 #endif |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 using namespace v8; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 struct xnjsmb_observer_data { |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
16 Persistent<Function> func; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 }; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 static void |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 event_handler(event_t *evt, void *arg); |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 static observer_t * |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 _subject_add_event_observer(subject_t *subject, int type, |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 Handle<Function> func) { |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 observer_t *observer; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 xnjsmb_observer_data *data; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 data = new xnjsmb_observer_data; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
29 if(data == NULL) |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 return NULL; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 data->func = Persistent<Function>::New(func); |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 observer = subject_add_event_observer(subject, type, |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 event_handler, |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 data); |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 return observer; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 } |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 static void |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 _subject_remove_observer(subject_t *subject, observer_t *observer) { |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 xnjsmb_observer_data *data; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 subject_remove_observer(subject, observer); |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 data = (xnjsmb_observer_data *)observer->arg; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 delete data; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 } |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 |
655 | 48 /* This is the part of the code generated by gen_v8_binding.m4 */ |
651
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 #include "observer-inc.h" |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
51 static void |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 event_handler(event_t *evt, void *arg) { |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
53 xnjsmb_observer_data *data = (xnjsmb_observer_data *)arg; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 Handle<Value> evt_obj; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
55 Handle<Value> func_args[1]; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 |
656
38c720272dd5
Change prefix for the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
655
diff
changeset
|
57 evt_obj = xnjsmb_auto_event_new(evt); |
651
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 ASSERT(!evt_obj.IsEmpty()); |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 func_args[0] = evt_obj; |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 data->func->Call(Context::GetCurrent()->Global(), 1, func_args); |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
61 } |
aa52883534fc
Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
62 |
658
62c2de99b03a
Remove get_object() method for subject for js
Thinker K.F. Li <thinker@branda.to>
parents:
656
diff
changeset
|
63 void |
62c2de99b03a
Remove get_object() method for subject for js
Thinker K.F. Li <thinker@branda.to>
parents:
656
diff
changeset
|
64 xnjsmb_observer_init(void) { |
62c2de99b03a
Remove get_object() method for subject for js
Thinker K.F. Li <thinker@branda.to>
parents:
656
diff
changeset
|
65 } |