summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVinícius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br>2015-06-04 21:43:38 -0300
committerVinícius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br>2015-06-04 21:54:13 -0300
commitebe77260c5e75ffdfa1dd98ce6759b102bb8a7d6 (patch)
treebca9a49bed794996a29da903745ff9ae09afb63e
parentb299a3489e221d8b134c2e3711e4141a4875c9da (diff)
Initial bindings for Ecore_Poller
-rw-r--r--src/Makefile_Ecore_Js.am6
-rw-r--r--src/bindings/ecore_js/ecore_js_poller.cc168
-rw-r--r--src/bindings/ecore_js/ecore_js_poller.hh35
-rw-r--r--src/tests/ecore_js/ecore_js_suite.cc17
-rwxr-xr-xsrc/tests/ecore_js/ecore_js_suite.js7
5 files changed, 231 insertions, 2 deletions
diff --git a/src/Makefile_Ecore_Js.am b/src/Makefile_Ecore_Js.am
index 96d6afa..bf4d594 100644
--- a/src/Makefile_Ecore_Js.am
+++ b/src/Makefile_Ecore_Js.am
@@ -27,7 +27,8 @@ bindings/ecore_js/ecore_js_timer.cc \
27bindings/ecore_js/ecore_js_event.cc \ 27bindings/ecore_js/ecore_js_event.cc \
28bindings/ecore_js/ecore_js_job.cc \ 28bindings/ecore_js/ecore_js_job.cc \
29bindings/ecore_js/ecore_js_idle.cc \ 29bindings/ecore_js/ecore_js_idle.cc \
30bindings/ecore_js/ecore_js_animator.cc 30bindings/ecore_js/ecore_js_animator.cc \
31bindings/ecore_js/ecore_js_poller.cc
31 32
32ECORE_JS_TEST_CXXFLAGS = -I$(top_builddir)/src/lib/efl \ 33ECORE_JS_TEST_CXXFLAGS = -I$(top_builddir)/src/lib/efl \
33-DTESTS_WD=\"`pwd`\" \ 34-DTESTS_WD=\"`pwd`\" \
@@ -50,7 +51,8 @@ bindings/ecore_js/ecore_js_timer.hh \
50bindings/ecore_js/ecore_js_event.hh \ 51bindings/ecore_js/ecore_js_event.hh \
51bindings/ecore_js/ecore_js_job.hh \ 52bindings/ecore_js/ecore_js_job.hh \
52bindings/ecore_js/ecore_js_idle.hh \ 53bindings/ecore_js/ecore_js_idle.hh \
53bindings/ecore_js/ecore_js_animator.hh 54bindings/ecore_js/ecore_js_animator.hh \
55bindings/ecore_js/ecore_js_poller.hh
54 56
55### Unit tests 57### Unit tests
56 58
diff --git a/src/bindings/ecore_js/ecore_js_poller.cc b/src/bindings/ecore_js/ecore_js_poller.cc
new file mode 100644
index 0000000..092b994
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_poller.cc
@@ -0,0 +1,168 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <ecore_js_poller.hh>
6#include <Ecore.h>
7
8namespace efl { namespace ecore { namespace js {
9
10static Ecore_Poller* extract_poller(v8::Local<v8::Object> object)
11{
12 auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
13 return reinterpret_cast<Ecore_Poller*>(ptr);
14}
15
16static v8::Local<v8::Object> wrap_poller(Ecore_Poller *poller,
17 v8::Isolate *isolate)
18{
19 using v8::Boolean;
20 using v8::String;
21 using v8::ObjectTemplate;
22 using v8::FunctionTemplate;
23
24 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
25 obj_tpl->SetInternalFieldCount(1);
26 auto ret = obj_tpl->NewInstance();
27
28 auto del = [](compatibility_callback_info_type info)
29 -> compatibility_return_type {
30 if (info.Length() != 0)
31 return compatibility_return();
32
33 ecore_poller_del(extract_poller(info.This()));
34 };
35
36 ret->Set(compatibility_new<String>(isolate, "del"),
37 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
38
39 ret->SetInternalField(0, compatibility_new<v8::External>(isolate, poller));
40
41 return ret;
42}
43
44EAPI
45void register_poller_core(v8::Isolate *isolate, v8::Handle<v8::Object> global,
46 v8::Handle<v8::String> name)
47{
48 using v8::Integer;
49
50 global->Set(name, compatibility_new<Integer>(isolate, ECORE_POLLER_CORE));
51}
52
53EAPI
54void register_poller_poll_interval_set(v8::Isolate *isolate,
55 v8::Handle<v8::Object> global,
56 v8::Handle<v8::String> name)
57{
58 using v8::Integer;
59 using v8::FunctionTemplate;
60
61 auto f = [](compatibility_callback_info_type args)
62 -> compatibility_return_type {
63 if (args.Length() != 2 || !args[0]->IsNumber() || !args[1]->IsNumber())
64 return compatibility_return();
65
66 Ecore_Poller_Type type;
67
68 switch ((int)(args[0]->NumberValue())) {
69 case ECORE_POLLER_CORE:
70 type = ECORE_POLLER_CORE;
71 break;
72 default:
73 return compatibility_return();
74 }
75
76 ecore_poller_poll_interval_set(type, args[1]->NumberValue());
77 };
78
79 global->Set(name,
80 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
81}
82
83EAPI
84void register_poller_poll_interval_get(v8::Isolate *isolate,
85 v8::Handle<v8::Object> global,
86 v8::Handle<v8::String> name)
87{
88 using v8::Integer;
89 using v8::FunctionTemplate;
90
91 auto f = [](compatibility_callback_info_type args)
92 -> compatibility_return_type {
93 if (args.Length() != 1 || !args[0]->IsNumber())
94 return compatibility_return();
95
96 Ecore_Poller_Type type;
97
98 switch ((int)(args[0]->NumberValue())) {
99 case ECORE_POLLER_CORE:
100 type = ECORE_POLLER_CORE;
101 break;
102 default:
103 return compatibility_return();
104 }
105
106 auto isolate = args.GetIsolate();
107 auto ret = ecore_poller_poll_interval_get(type);
108 return compatibility_return(compatibility_new<Integer>(isolate, ret),
109 args);
110 };
111
112 global->Set(name,
113 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
114}
115
116EAPI
117void register_poller_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
118 v8::Handle<v8::String> name)
119{
120 using v8::Integer;
121 using v8::Value;
122 using v8::FunctionTemplate;
123 using v8::Isolate;
124 using v8::Function;
125
126 auto f = [](compatibility_callback_info_type args)
127 -> compatibility_return_type {
128 if (args.Length() != 3 || !args[0]->IsNumber() || !args[1]->IsNumber()
129 || !args[2]->IsFunction()) {
130 return compatibility_return();
131 }
132
133 Ecore_Poller_Type type;
134
135 switch ((int)(args[0]->NumberValue())) {
136 case ECORE_POLLER_CORE:
137 type = ECORE_POLLER_CORE;
138 break;
139 default:
140 return compatibility_return();
141 }
142
143 auto isolate = args.GetIsolate();
144 auto f = new compatibility_persistent<Value>(isolate, args[2]);
145
146 auto cb = [](void *data) -> Eina_Bool {
147 auto persistent
148 = reinterpret_cast<compatibility_persistent<Value>*>(data);
149 auto closure = Function::Cast(*persistent->handle());
150
151 auto ret = closure->Call(Undefined(Isolate::GetCurrent()), 0, NULL);
152 auto bret = ret->IsBoolean() && ret->BooleanValue();
153
154 if (!bret)
155 delete persistent;
156
157 return bret ? EINA_TRUE : EINA_FALSE;
158 };
159
160 auto ret = ecore_poller_add(type, args[1]->NumberValue(), cb, f);
161 return compatibility_return(wrap_poller(ret, isolate), args);
162 };
163
164 global->Set(name,
165 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
166}
167
168} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_poller.hh b/src/bindings/ecore_js/ecore_js_poller.hh
new file mode 100644
index 0000000..3e217be
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_poller.hh
@@ -0,0 +1,35 @@
1#ifndef ECORE_JS_POLLER_HH
2#define ECORE_JS_POLLER_HH
3
4#include <Eina.hh>
5#include EINA_STRINGIZE(V8_INCLUDE_HEADER)
6
7#include <eina_js_compatibility.hh>
8
9namespace efl { namespace ecore { namespace js {
10
11using ::efl::eina::js::compatibility_new;
12using ::efl::eina::js::compatibility_return_type;
13using ::efl::eina::js::compatibility_callback_info_type;
14using ::efl::eina::js::compatibility_return;
15using ::efl::eina::js::compatibility_get_pointer_internal_field;
16using ::efl::eina::js::compatibility_set_pointer_internal_field;
17using ::efl::eina::js::compatibility_persistent;
18
19void register_poller_core(v8::Isolate *isolate, v8::Handle<v8::Object> global,
20 v8::Handle<v8::String> name);
21
22void register_poller_poll_interval_set(v8::Isolate *isolate,
23 v8::Handle<v8::Object> global,
24 v8::Handle<v8::String> name);
25
26void register_poller_poll_interval_get(v8::Isolate *isolate,
27 v8::Handle<v8::Object> global,
28 v8::Handle<v8::String> name);
29
30void register_poller_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
31 v8::Handle<v8::String> name);
32
33} } } // namespace efl { namespace ecore { namespace js {
34
35#endif /* ECORE_JS_POLLER_HH */
diff --git a/src/tests/ecore_js/ecore_js_suite.cc b/src/tests/ecore_js/ecore_js_suite.cc
index ba143e7..bb37413 100644
--- a/src/tests/ecore_js/ecore_js_suite.cc
+++ b/src/tests/ecore_js/ecore_js_suite.cc
@@ -20,6 +20,7 @@
20#include <ecore_js_job.hh> 20#include <ecore_js_job.hh>
21#include <ecore_js_idle.hh> 21#include <ecore_js_idle.hh>
22#include <ecore_js_animator.hh> 22#include <ecore_js_animator.hh>
23#include <ecore_js_poller.hh>
23 24
24const char* ToCString(const v8::String::Utf8Value& value) { 25const char* ToCString(const v8::String::Utf8Value& value) {
25 return *value ? *value : "<string conversion failed>"; 26 return *value ? *value : "<string conversion failed>";
@@ -368,6 +369,22 @@ void test_setup(v8::Handle<v8::Object> exports)
368 "ecore_animator" 369 "ecore_animator"
369 "_timeline_add")); 370 "_timeline_add"));
370 371
372 // poller
373 register_poller_core(isolate, exports,
374 compatibility_new<String>(isolate, "ECORE_POLLER_CORE"));
375 register_poller_poll_interval_set(isolate, exports,
376 compatibility_new<String>(isolate,
377 "ecore_poller"
378 "_poll_interval"
379 "_set"));
380 register_poller_poll_interval_get(isolate, exports,
381 compatibility_new<String>(isolate,
382 "ecore_poller"
383 "_poll_interval"
384 "_get"));
385 register_poller_add(isolate, exports,
386 compatibility_new<String>(isolate, "ecore_poller_add"));
387
371 std::cerr << __LINE__ << std::endl; 388 std::cerr << __LINE__ << std::endl;
372} 389}
373 390
diff --git a/src/tests/ecore_js/ecore_js_suite.js b/src/tests/ecore_js/ecore_js_suite.js
index e471bf4..5ab2b5e 100755
--- a/src/tests/ecore_js/ecore_js_suite.js
+++ b/src/tests/ecore_js/ecore_js_suite.js
@@ -272,6 +272,13 @@ assert(suite.ecore_animator_source_get()
272suite.ecore_animator_source_set(suite.ECORE_ANIMATOR_SOURCE_TIMER); 272suite.ecore_animator_source_set(suite.ECORE_ANIMATOR_SOURCE_TIMER);
273assert(suite.ecore_animator_source_get() === suite.ECORE_ANIMATOR_SOURCE_TIMER); 273assert(suite.ecore_animator_source_get() === suite.ECORE_ANIMATOR_SOURCE_TIMER);
274 274
275// Ecore poller
276
277suite.ecore_poller_poll_interval_set(suite.ECORE_POLLER_CORE, 42);
278assert(suite.ecore_poller_poll_interval_get(suite.ECORE_POLLER_CORE) === 42);
279suite.ecore_poller_poll_interval_set(suite.ECORE_POLLER_CORE, 2);
280assert(suite.ecore_poller_poll_interval_get(suite.ECORE_POLLER_CORE) === 2);
281
275// Ecore shutdown 282// Ecore shutdown
276 283
277suite.ecore_shutdown(); 284suite.ecore_shutdown();