aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinícius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br>2015-06-02 14:14:10 -0300
committerVinícius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br>2015-06-02 14:14:10 -0300
commit8d2fc96d1e1e1586b07067ea7863294e3082b1d4 (patch)
tree99a40a84d0c7a48ef14406834ca48965062336fe
parentInitial bindings for Ecore_Event (diff)
downloadefl-8d2fc96d1e1e1586b07067ea7863294e3082b1d4.tar.gz
Initial bindings for Ecore_Job
-rw-r--r--src/Makefile_Ecore_Js.am6
-rw-r--r--src/bindings/ecore_js/ecore_js_job.cc91
-rw-r--r--src/bindings/ecore_js/ecore_js_job.hh23
-rw-r--r--src/tests/ecore_js/ecore_js_suite.cc5
-rwxr-xr-xsrc/tests/ecore_js/ecore_js_suite.js28
5 files changed, 148 insertions, 5 deletions
diff --git a/src/Makefile_Ecore_Js.am b/src/Makefile_Ecore_Js.am
index 6cd8777379..b2195699cb 100644
--- a/src/Makefile_Ecore_Js.am
+++ b/src/Makefile_Ecore_Js.am
@@ -24,7 +24,8 @@ lib_ecore_js_libecore_js_la_SOURCES = \
bindings/ecore_js/ecore_js_init.cc \
bindings/ecore_js/ecore_js_mainloop.cc \
bindings/ecore_js/ecore_js_timer.cc \
-bindings/ecore_js/ecore_js_event.cc
+bindings/ecore_js/ecore_js_event.cc \
+bindings/ecore_js/ecore_js_job.cc
ECORE_JS_TEST_CXXFLAGS = -I$(top_builddir)/src/lib/efl \
-DTESTS_WD=\"`pwd`\" \
@@ -44,7 +45,8 @@ dist_installed_ecorejsheaders_DATA = \
bindings/ecore_js/ecore_js_init.hh \
bindings/ecore_js/ecore_js_mainloop.hh \
bindings/ecore_js/ecore_js_timer.hh \
-bindings/ecore_js/ecore_js_event.hh
+bindings/ecore_js/ecore_js_event.hh \
+bindings/ecore_js/ecore_js_job.hh
### Unit tests
diff --git a/src/bindings/ecore_js/ecore_js_job.cc b/src/bindings/ecore_js/ecore_js_job.cc
new file mode 100644
index 0000000000..456561ad20
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_job.cc
@@ -0,0 +1,91 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ecore_js_job.hh>
+#include <Ecore.h>
+
+namespace efl { namespace ecore { namespace js {
+
+struct persistent_with_isolate_t
+{
+ template<class S>
+ persistent_with_isolate_t(v8::Isolate *isolate, v8::Handle<S> that)
+ : isolate(isolate)
+ , persistent(isolate, that)
+ {}
+
+ v8::Isolate *isolate;
+ v8::Persistent<v8::Value> persistent;
+};
+
+static Ecore_Job* extract_job(v8::Local<v8::Object> object)
+{
+ auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
+ return reinterpret_cast<Ecore_Job*>(ptr);
+}
+
+static v8::Local<v8::Object> wrap_job(Ecore_Job *job, 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_job_del(extract_job(info.This()));
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ ret->SetInternalField(0, compatibility_new<v8::External>(isolate, job));
+
+ return ret;
+}
+
+EAPI
+void register_job_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Local;
+ using v8::Value;
+ using v8::Undefined;
+ using v8::Function;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ persistent_with_isolate_t *f
+ = new persistent_with_isolate_t(args.GetIsolate(), args[0]);
+ auto ret = ecore_job_add([](void *data) {
+ persistent_with_isolate_t *persistent
+ = reinterpret_cast<persistent_with_isolate_t *>(data);
+ auto value = Local<Value>::New(persistent->isolate,
+ persistent->persistent);
+ auto closure = Function::Cast(*value);
+
+ closure->Call(Undefined(persistent->isolate), 0, NULL);
+
+ delete persistent;
+ }, f);
+
+ return compatibility_return(wrap_job(ret, args.GetIsolate()), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_job.hh b/src/bindings/ecore_js/ecore_js_job.hh
new file mode 100644
index 0000000000..f950062b29
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_job.hh
@@ -0,0 +1,23 @@
+#ifndef ECORE_JS_JOB_HH
+#define ECORE_JS_JOB_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;
+
+void register_job_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+} } } // namespace efl { namespace ecore { namespace js {
+
+#endif /* ECORE_JS_JOB_HH */
diff --git a/src/tests/ecore_js/ecore_js_suite.cc b/src/tests/ecore_js/ecore_js_suite.cc
index 391ac9ac94..c40d7f0094 100644
--- a/src/tests/ecore_js/ecore_js_suite.cc
+++ b/src/tests/ecore_js/ecore_js_suite.cc
@@ -17,6 +17,7 @@
#include <ecore_js_mainloop.hh>
#include <ecore_js_timer.hh>
#include <ecore_js_event.hh>
+#include <ecore_js_job.hh>
const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>";
@@ -246,6 +247,10 @@ void test_setup(v8::Handle<v8::Object> exports)
"ecore_event_signal_realtime"
"_handler_add"));
+ // job
+ register_job_add(isolate, exports,
+ compatibility_new<String>(isolate, "ecore_job_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 5f0eea2d0a..2c52276807 100755
--- a/src/tests/ecore_js/ecore_js_suite.js
+++ b/src/tests/ecore_js/ecore_js_suite.js
@@ -71,7 +71,7 @@ suite.ecore_timer_add(1, function() {
return true;
captured = true;
- suite.ecore_mainloop_thread_safe_call_async(suite.ecore_mainloop_quit);
+ suite.ecore_job_add(suite.ecore_mainloop_quit);
return false;
});
@@ -87,7 +87,7 @@ suite.ecore_timer_loop_add(1, function() {
return true;
captured = true;
- suite.ecore_mainloop_thread_safe_call_async(suite.ecore_mainloop_quit);
+ suite.ecore_job_add(suite.ecore_mainloop_quit);
return false;
});
@@ -114,7 +114,7 @@ assert(timer.freeze_get() === false);
timer.del();
suite.ecore_timer_add(2, function() {
- suite.ecore_mainloop_thread_safe_call_async(suite.ecore_mainloop_quit);
+ suite.ecore_job_add(suite.ecore_mainloop_quit);
return false;
});
@@ -191,6 +191,28 @@ suite.ecore_timer_add(1, suite.ecore_mainloop_quit);
suite.ecore_mainloop_begin();
assert(captured[1] === 8);
+// Ecore job
+
+captured = false;
+
+suite.ecore_job_add(function() {
+ captured = true;
+ suite.ecore_mainloop_quit();
+});
+
+assert(captured === false);
+suite.ecore_mainloop_begin();
+assert(captured === true);
+
+captured = false;
+var job = suite.ecore_job_add(function() {
+ captured = true;
+});
+suite.ecore_job_add(suite.ecore_mainloop_quit);
+job.del();
+suite.ecore_mainloop_begin();
+assert(captured === false);
+
// Ecore shutdown
suite.ecore_shutdown();