Initial binding for Ecore_Throttle

This commit is contained in:
Vinícius dos Santos Oliveira 2015-06-05 14:41:38 -03:00
parent ebe77260c5
commit 1f5fadd9d5
5 changed files with 98 additions and 2 deletions

View File

@ -28,7 +28,8 @@ 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_poller.cc
bindings/ecore_js/ecore_js_poller.cc \
bindings/ecore_js/ecore_js_throttle.cc
ECORE_JS_TEST_CXXFLAGS = -I$(top_builddir)/src/lib/efl \
-DTESTS_WD=\"`pwd`\" \
@ -52,7 +53,8 @@ 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_poller.hh
bindings/ecore_js/ecore_js_poller.hh \
bindings/ecore_js/ecore_js_throttle.hh
### Unit tests

View File

@ -0,0 +1,51 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <ecore_js_throttle.hh>
#include <Ecore.h>
namespace efl { namespace ecore { namespace js {
EAPI
void register_throttle_adjust(v8::Isolate *isolate,
v8::Handle<v8::Object> global,
v8::Handle<v8::String> name)
{
using v8::FunctionTemplate;
auto f = [](compatibility_callback_info_type args)
-> compatibility_return_type {
if (args.Length() != 1 || !args[0]->IsNumber())
return compatibility_return();
ecore_throttle_adjust(args[0]->NumberValue());
};
global->Set(name,
compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
}
EAPI
void register_throttle_get(v8::Isolate *isolate, v8::Handle<v8::Object> global,
v8::Handle<v8::String> name)
{
using v8::Number;
using v8::FunctionTemplate;
auto f = [](compatibility_callback_info_type args)
-> compatibility_return_type {
if (args.Length() != 0)
return compatibility_return();
auto isolate = args.GetIsolate();
auto ret = ecore_throttle_get();
return compatibility_return(compatibility_new<Number>(isolate, ret),
args);
};
global->Set(name,
compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
}
} } } // namespace efl { namespace js {

View File

@ -0,0 +1,27 @@
#ifndef ECORE_JS_THROTTLE_HH
#define ECORE_JS_THROTTLE_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_throttle_adjust(v8::Isolate *isolate,
v8::Handle<v8::Object> global,
v8::Handle<v8::String> name);
void register_throttle_get(v8::Isolate *isolate, v8::Handle<v8::Object> global,
v8::Handle<v8::String> name);
} } } // namespace efl { namespace ecore { namespace js {
#endif /* ECORE_JS_THROTTLE_HH */

View File

@ -21,6 +21,7 @@
#include <ecore_js_idle.hh>
#include <ecore_js_animator.hh>
#include <ecore_js_poller.hh>
#include <ecore_js_throttle.hh>
const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>";
@ -385,6 +386,14 @@ void test_setup(v8::Handle<v8::Object> exports)
register_poller_add(isolate, exports,
compatibility_new<String>(isolate, "ecore_poller_add"));
// throttle
register_throttle_adjust(isolate, exports,
compatibility_new<String>(isolate,
"ecore_throttle_adjust"));
register_throttle_get(isolate, exports,
compatibility_new<String>(isolate,
"ecore_throttle_get"));
std::cerr << __LINE__ << std::endl;
}

View File

@ -279,6 +279,13 @@ 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 throttle
suite.ecore_throttle_adjust(3);
assert(suite.ecore_throttle_get() === 3);
suite.ecore_throttle_adjust(-3);
assert(suite.ecore_throttle_get() === 0);
// Ecore shutdown
suite.ecore_shutdown();