forked from enlightenment/efl
Initial bindings for Ecore_Job
This commit is contained in:
parent
fe5508a40d
commit
8d2fc96d1e
|
@ -24,7 +24,8 @@ lib_ecore_js_libecore_js_la_SOURCES = \
|
||||||
bindings/ecore_js/ecore_js_init.cc \
|
bindings/ecore_js/ecore_js_init.cc \
|
||||||
bindings/ecore_js/ecore_js_mainloop.cc \
|
bindings/ecore_js/ecore_js_mainloop.cc \
|
||||||
bindings/ecore_js/ecore_js_timer.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 \
|
ECORE_JS_TEST_CXXFLAGS = -I$(top_builddir)/src/lib/efl \
|
||||||
-DTESTS_WD=\"`pwd`\" \
|
-DTESTS_WD=\"`pwd`\" \
|
||||||
|
@ -44,7 +45,8 @@ dist_installed_ecorejsheaders_DATA = \
|
||||||
bindings/ecore_js/ecore_js_init.hh \
|
bindings/ecore_js/ecore_js_init.hh \
|
||||||
bindings/ecore_js/ecore_js_mainloop.hh \
|
bindings/ecore_js/ecore_js_mainloop.hh \
|
||||||
bindings/ecore_js/ecore_js_timer.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
|
### Unit tests
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
|
@ -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 */
|
|
@ -17,6 +17,7 @@
|
||||||
#include <ecore_js_mainloop.hh>
|
#include <ecore_js_mainloop.hh>
|
||||||
#include <ecore_js_timer.hh>
|
#include <ecore_js_timer.hh>
|
||||||
#include <ecore_js_event.hh>
|
#include <ecore_js_event.hh>
|
||||||
|
#include <ecore_js_job.hh>
|
||||||
|
|
||||||
const char* ToCString(const v8::String::Utf8Value& value) {
|
const char* ToCString(const v8::String::Utf8Value& value) {
|
||||||
return *value ? *value : "<string conversion failed>";
|
return *value ? *value : "<string conversion failed>";
|
||||||
|
@ -246,6 +247,10 @@ void test_setup(v8::Handle<v8::Object> exports)
|
||||||
"ecore_event_signal_realtime"
|
"ecore_event_signal_realtime"
|
||||||
"_handler_add"));
|
"_handler_add"));
|
||||||
|
|
||||||
|
// job
|
||||||
|
register_job_add(isolate, exports,
|
||||||
|
compatibility_new<String>(isolate, "ecore_job_add"));
|
||||||
|
|
||||||
std::cerr << __LINE__ << std::endl;
|
std::cerr << __LINE__ << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ suite.ecore_timer_add(1, function() {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
captured = true;
|
captured = true;
|
||||||
suite.ecore_mainloop_thread_safe_call_async(suite.ecore_mainloop_quit);
|
suite.ecore_job_add(suite.ecore_mainloop_quit);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ suite.ecore_timer_loop_add(1, function() {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
captured = true;
|
captured = true;
|
||||||
suite.ecore_mainloop_thread_safe_call_async(suite.ecore_mainloop_quit);
|
suite.ecore_job_add(suite.ecore_mainloop_quit);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ assert(timer.freeze_get() === false);
|
||||||
timer.del();
|
timer.del();
|
||||||
|
|
||||||
suite.ecore_timer_add(2, function() {
|
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;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -191,6 +191,28 @@ suite.ecore_timer_add(1, suite.ecore_mainloop_quit);
|
||||||
suite.ecore_mainloop_begin();
|
suite.ecore_mainloop_begin();
|
||||||
assert(captured[1] === 8);
|
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
|
// Ecore shutdown
|
||||||
|
|
||||||
suite.ecore_shutdown();
|
suite.ecore_shutdown();
|
||||||
|
|
Loading…
Reference in New Issue