annotate nodejs/observer.cc @ 651:aa52883534fc

Code generated by generator can be built
author Thinker K.F. Li <thinker@branda.to>
date Sat, 31 Jul 2010 13:28:48 +0800
parents
children d58251f1bf0b
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
aa52883534fc Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 #include "observer-inc.h"
aa52883534fc Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49
aa52883534fc Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 static void
aa52883534fc Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 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
52 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
53 Handle<Value> evt_obj;
aa52883534fc Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 Handle<Value> func_args[1];
aa52883534fc Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55
aa52883534fc Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 evt_obj = xnjsmb_event_new(evt);
aa52883534fc Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 ASSERT(!evt_obj.IsEmpty());
aa52883534fc Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 func_args[0] = evt_obj;
aa52883534fc Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 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
60 }
aa52883534fc Code generated by generator can be built
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61