aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 96d6afa196..bf4d59497f 100644
--- a/src/Makefile_Ecore_Js.am
+++ b/src/Makefile_Ecore_Js.am
@@ -27,7 +27,8 @@ bindings/ecore_js/ecore_js_timer.cc \
bindings/ecore_js/ecore_js_event.cc \
bindings/ecore_js/ecore_js_job.cc \
bindings/ecore_js/ecore_js_idle.cc \
-bindings/ecore_js/ecore_js_animator.cc
+bindings/ecore_js/ecore_js_animator.cc \
+bindings/ecore_js/ecore_js_poller.cc
ECORE_JS_TEST_CXXFLAGS = -I$(top_builddir)/src/lib/efl \
-DTESTS_WD=\"`pwd`\" \
@@ -50,7 +51,8 @@ bindings/ecore_js/ecore_js_timer.hh \
bindings/ecore_js/ecore_js_event.hh \
bindings/ecore_js/ecore_js_job.hh \
bindings/ecore_js/ecore_js_idle.hh \
-bindings/ecore_js/ecore_js_animator.hh
+bindings/ecore_js/ecore_js_animator.hh \
+bindings/ecore_js/ecore_js_poller.hh
### Unit tests
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 0000000000..092b9947a6
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_poller.cc
@@ -0,0 +1,168 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ecore_js_poller.hh>
+#include <Ecore.h>
+
+namespace efl { namespace ecore { namespace js {
+
+static Ecore_Poller* extract_poller(v8::Local<v8::Object> object)
+{
+ auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
+ return reinterpret_cast<Ecore_Poller*>(ptr);
+}
+
+static v8::Local<v8::Object> wrap_poller(Ecore_Poller *poller,
+ v8::Isolate *isolate)
+{
+ using v8::Boolean;
+ using v8::String;
+ using v8::ObjectTemplate;
+ using v8::FunctionTemplate;
+
+ auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
+ obj_tpl->SetInternalFieldCount(1);
+ auto ret = obj_tpl->NewInstance();
+
+ auto del = [](compatibility_callback_info_type info)
+ -> compatibility_return_type {
+ if (info.Length() != 0)
+ return compatibility_return();
+
+ ecore_poller_del(extract_poller(info.This()));
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ ret->SetInternalField(0, compatibility_new<v8::External>(isolate, poller));
+
+ return ret;
+}
+
+EAPI
+void register_poller_core(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+
+ global->Set(name, compatibility_new<Integer>(isolate, ECORE_POLLER_CORE));
+}
+
+EAPI
+void register_poller_poll_interval_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsNumber() || !args[1]->IsNumber())
+ return compatibility_return();
+
+ Ecore_Poller_Type type;
+
+ switch ((int)(args[0]->NumberValue())) {
+ case ECORE_POLLER_CORE:
+ type = ECORE_POLLER_CORE;
+ break;
+ default:
+ return compatibility_return();
+ }
+
+ ecore_poller_poll_interval_set(type, args[1]->NumberValue());
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_poller_poll_interval_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsNumber())
+ return compatibility_return();
+
+ Ecore_Poller_Type type;
+
+ switch ((int)(args[0]->NumberValue())) {
+ case ECORE_POLLER_CORE:
+ type = ECORE_POLLER_CORE;
+ break;
+ default:
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_poller_poll_interval_get(type);
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_poller_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::Value;
+ using v8::FunctionTemplate;
+ using v8::Isolate;
+ using v8::Function;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 3 || !args[0]->IsNumber() || !args[1]->IsNumber()
+ || !args[2]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ Ecore_Poller_Type type;
+
+ switch ((int)(args[0]->NumberValue())) {
+ case ECORE_POLLER_CORE:
+ type = ECORE_POLLER_CORE;
+ break;
+ default:
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+ auto f = new compatibility_persistent<Value>(isolate, args[2]);
+
+ auto cb = [](void *data) -> Eina_Bool {
+ auto persistent
+ = reinterpret_cast<compatibility_persistent<Value>*>(data);
+ auto closure = Function::Cast(*persistent->handle());
+
+ auto ret = closure->Call(Undefined(Isolate::GetCurrent()), 0, NULL);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ if (!bret)
+ delete persistent;
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_poller_add(type, args[1]->NumberValue(), cb, f);
+ return compatibility_return(wrap_poller(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+} } } // 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 0000000000..3e217bec3f
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_poller.hh
@@ -0,0 +1,35 @@
+#ifndef ECORE_JS_POLLER_HH
+#define ECORE_JS_POLLER_HH
+
+#include <Eina.hh>
+#include EINA_STRINGIZE(V8_INCLUDE_HEADER)
+
+#include <eina_js_compatibility.hh>
+
+namespace efl { namespace ecore { namespace js {
+
+using ::efl::eina::js::compatibility_new;
+using ::efl::eina::js::compatibility_return_type;
+using ::efl::eina::js::compatibility_callback_info_type;
+using ::efl::eina::js::compatibility_return;
+using ::efl::eina::js::compatibility_get_pointer_internal_field;
+using ::efl::eina::js::compatibility_set_pointer_internal_field;
+using ::efl::eina::js::compatibility_persistent;
+
+void register_poller_core(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_poller_poll_interval_set(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_poller_poll_interval_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_poller_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+} } } // namespace efl { namespace ecore { namespace js {
+
+#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 ba143e7166..bb37413b29 100644
--- a/src/tests/ecore_js/ecore_js_suite.cc
+++ b/src/tests/ecore_js/ecore_js_suite.cc
@@ -20,6 +20,7 @@
#include <ecore_js_job.hh>
#include <ecore_js_idle.hh>
#include <ecore_js_animator.hh>
+#include <ecore_js_poller.hh>
const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>";
@@ -368,6 +369,22 @@ void test_setup(v8::Handle<v8::Object> exports)
"ecore_animator"
"_timeline_add"));
+ // poller
+ register_poller_core(isolate, exports,
+ compatibility_new<String>(isolate, "ECORE_POLLER_CORE"));
+ register_poller_poll_interval_set(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ecore_poller"
+ "_poll_interval"
+ "_set"));
+ register_poller_poll_interval_get(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ecore_poller"
+ "_poll_interval"
+ "_get"));
+ register_poller_add(isolate, exports,
+ compatibility_new<String>(isolate, "ecore_poller_add"));
+
std::cerr << __LINE__ << std::endl;
}
diff --git a/src/tests/ecore_js/ecore_js_suite.js b/src/tests/ecore_js/ecore_js_suite.js
index e471bf4854..5ab2b5ecb5 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()
suite.ecore_animator_source_set(suite.ECORE_ANIMATOR_SOURCE_TIMER);
assert(suite.ecore_animator_source_get() === suite.ECORE_ANIMATOR_SOURCE_TIMER);
+// Ecore poller
+
+suite.ecore_poller_poll_interval_set(suite.ECORE_POLLER_CORE, 42);
+assert(suite.ecore_poller_poll_interval_get(suite.ECORE_POLLER_CORE) === 42);
+suite.ecore_poller_poll_interval_set(suite.ECORE_POLLER_CORE, 2);
+assert(suite.ecore_poller_poll_interval_get(suite.ECORE_POLLER_CORE) === 2);
+
// Ecore shutdown
suite.ecore_shutdown();