Initial bindings for Ecore_Poller

This commit is contained in:
Vinícius dos Santos Oliveira 2015-06-04 21:43:38 -03:00
parent b299a3489e
commit ebe77260c5
5 changed files with 231 additions and 2 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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 */

View File

@ -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;
}

View File

@ -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();