aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinícius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br>2015-06-02 14:13:47 -0300
committerVinícius dos Santos Oliveira <vini.ipsmaker@expertisesolutions.com.br>2015-06-02 14:13:47 -0300
commitfe5508a40d0fd782c1480a71e732f43bdd566ef3 (patch)
treeca285411b0045c07b707d2e202888f0a829fa42d
parentInitial bindings for Ecore_Timer (diff)
downloadefl-fe5508a40d0fd782c1480a71e732f43bdd566ef3.tar.gz
Initial bindings for Ecore_Event
-rw-r--r--src/Makefile_Ecore_Js.am6
-rw-r--r--src/bindings/ecore_js/ecore_js_event.cc706
-rw-r--r--src/bindings/ecore_js/ecore_js_event.hh122
-rw-r--r--src/tests/ecore_js/ecore_js_suite.cc82
-rwxr-xr-xsrc/tests/ecore_js/ecore_js_suite.js70
5 files changed, 984 insertions, 2 deletions
diff --git a/src/Makefile_Ecore_Js.am b/src/Makefile_Ecore_Js.am
index 15afab9e2b..6cd8777379 100644
--- a/src/Makefile_Ecore_Js.am
+++ b/src/Makefile_Ecore_Js.am
@@ -23,7 +23,8 @@ lib_ecore_js_libecore_js_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@
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_timer.cc \
+bindings/ecore_js/ecore_js_event.cc
ECORE_JS_TEST_CXXFLAGS = -I$(top_builddir)/src/lib/efl \
-DTESTS_WD=\"`pwd`\" \
@@ -42,7 +43,8 @@ installed_ecorejsheadersdir = $(includedir)/ecore-js-@VMAJ@
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_timer.hh \
+bindings/ecore_js/ecore_js_event.hh
### Unit tests
diff --git a/src/bindings/ecore_js/ecore_js_event.cc b/src/bindings/ecore_js/ecore_js_event.cc
new file mode 100644
index 0000000000..1ee12cb9a9
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_event.cc
@@ -0,0 +1,706 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ecore_js_init.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_Event *extract_event(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Ecore_Event*>(object, 0);
+}
+
+static v8::Local<v8::Object> wrap_event(Ecore_Event *event,
+ v8::Isolate *isolate)
+{
+ 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_event_del(extract_event(info.This()));
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, event);
+
+ return ret;
+}
+
+static Ecore_Event_Handler *extract_event_handler(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Ecore_Event_Handler*>
+ (object, 0);
+}
+
+static v8::Local<v8::Object> wrap_event_handler(Ecore_Event_Handler *handler,
+ v8::Isolate *isolate)
+{
+ 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();
+
+ auto p = ecore_event_handler_del(extract_event_handler(info.This()));
+
+ delete reinterpret_cast<persistent_with_isolate_t*>(p);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, handler);
+
+ return ret;
+}
+
+static Ecore_Event_Filter *extract_event_filter(v8::Local<v8::Object> object)
+{
+ return compatibility_get_pointer_internal_field<Ecore_Event_Filter*>
+ (object, 0);
+}
+
+static v8::Local<v8::Object> wrap_event_filter(Ecore_Event_Filter *filter,
+ v8::Isolate *isolate)
+{
+ 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();
+
+ auto p = ecore_event_filter_del(extract_event_filter(info.This()));
+ delete[] reinterpret_cast<persistent_with_isolate_t*>(p);
+ };
+
+ ret->Set(compatibility_new<String>(isolate, "del"),
+ compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
+
+ compatibility_set_pointer_internal_field(ret, 0, filter);
+
+ return ret;
+}
+
+EAPI
+void register_event_none(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_NONE));
+}
+
+EAPI
+void register_event_signal_user(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_USER));
+}
+
+EAPI
+void register_event_signal_hup(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_HUP));
+}
+
+EAPI
+void register_event_signal_exit(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_EXIT));
+}
+
+EAPI
+void register_event_signal_power(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_POWER));
+}
+
+EAPI
+void register_event_signal_realtime(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_EVENT_SIGNAL_REALTIME));
+}
+
+EAPI
+void register_event_memory_state(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_MEMORY_STATE));
+}
+
+EAPI
+void register_event_power_state(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_EVENT_POWER_STATE));
+}
+
+EAPI
+void register_event_locale_changed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_EVENT_LOCALE_CHANGED));
+}
+
+EAPI
+void register_event_hostname_changed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_EVENT_HOSTNAME_CHANGED));
+}
+
+EAPI
+void register_event_system_timedate_changed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate,
+ ECORE_EVENT_SYSTEM_TIMEDATE_CHANGED));
+}
+
+EAPI
+void register_event_type_new(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() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_event_type_new();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_add(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();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_event_add(args[0]->NumberValue(), NULL, NULL, NULL);
+ return compatibility_return(wrap_event(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::Value;
+ using v8::Function;
+ using v8::Handle;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 2 || !args[0]->IsNumber()
+ || !args[1]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto p = new persistent_with_isolate_t(isolate, args[1]);
+
+ auto cb = [](void *d, int type, void */*event*/) -> Eina_Bool {
+ auto persistent = reinterpret_cast<persistent_with_isolate_t*>(d);
+ auto value = Local<Value>::New(persistent->isolate,
+ persistent->persistent);
+ auto closure = Function::Cast(*value);
+
+ Handle<Value> args = compatibility_new<Integer>(persistent->isolate,
+ type);
+
+ auto ret = closure->Call(Undefined(persistent->isolate), 1, &args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_event_handler_add(args[0]->Int32Value(), cb, p);
+ return compatibility_return(wrap_event_handler(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_filter_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::Value;
+ using v8::Function;
+ using v8::Handle;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 3 || !args[0]->IsFunction()
+ || !args[1]->IsFunction() || !args[2]->IsFunction()) {
+ return compatibility_return();
+ }
+
+ auto isolate = args.GetIsolate();
+
+ auto p = new persistent_with_isolate_t[3]{{isolate, args[0]},
+ {isolate, args[1]},
+ {isolate, args[2]}};
+
+ auto start_cb = [](void *data) -> void* {
+ auto p = reinterpret_cast<persistent_with_isolate_t*>(data);
+ auto value = Local<Value>::New(p->isolate, p->persistent);
+ auto closure = Function::Cast(*value);
+
+ auto ret = closure->Call(Undefined(p->isolate), 0, NULL);
+ return new persistent_with_isolate_t{p->isolate, ret};
+ };
+
+ auto filter_cb = [](void *data, void *loop_data, int type,
+ void */*event*/) -> Eina_Bool {
+ typedef persistent_with_isolate_t p_t;
+
+ auto p = reinterpret_cast<p_t*>(data) + 1;
+ auto value = Local<Value>::New(p->isolate, p->persistent);
+ auto closure = Function::Cast(*value);
+
+ Handle<Value> args[2]{
+ [loop_data]() {
+ auto ret = reinterpret_cast<p_t*>(loop_data);
+ return Local<Value>::New(ret->isolate, ret->persistent);
+ }(),
+ compatibility_new<Integer>(p->isolate, type)
+ };
+
+ auto ret = closure->Call(Undefined(p->isolate), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto end_cb = [](void *user_data, void *func_data) -> void {
+ typedef persistent_with_isolate_t p_t;
+
+ auto loop_data = std::unique_ptr<p_t>(reinterpret_cast<p_t*>
+ (func_data));
+ auto p = reinterpret_cast<p_t*>(user_data) + 2;
+ auto value = Local<Value>::New(p->isolate, p->persistent);
+ auto closure = Function::Cast(*value);
+
+ Handle<Value> args = Local<Value>::New(loop_data->isolate,
+ loop_data->persistent);
+
+ closure->Call(Undefined(p->isolate), 1, &args);
+ };
+
+ auto ret = ecore_event_filter_add(start_cb, filter_cb, end_cb, p);
+ return compatibility_return(wrap_event_filter(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_current_type_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() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_event_current_type_get();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_memory_state_normal(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_MEMORY_STATE_NORMAL));
+}
+
+EAPI
+void register_memory_state_low(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_MEMORY_STATE_LOW));
+}
+
+EAPI
+void register_power_state_mains(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POWER_STATE_MAINS));
+}
+
+EAPI
+void register_power_state_battery(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POWER_STATE_BATTERY));
+}
+
+EAPI
+void register_power_state_low(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ global->Set(name,
+ compatibility_new<Integer>(isolate, ECORE_POWER_STATE_LOW));
+}
+
+EAPI
+void register_memory_state_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() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_memory_state_get();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_power_state_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() != 0)
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+ auto ret = ecore_power_state_get();
+ return compatibility_return(compatibility_new<Integer>(isolate, ret),
+ args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_signal_user_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::String;
+ using v8::Value;
+ using v8::Object;
+ using v8::Function;
+ using v8::Handle;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ auto p = new persistent_with_isolate_t(isolate, args[0]);
+
+ auto cb = [](void *d, int type, void *event) -> Eina_Bool {
+ auto p = reinterpret_cast<persistent_with_isolate_t*>(d);
+ auto value = Local<Value>::New(p->isolate, p->persistent);
+ auto closure = Function::Cast(*value);
+
+ auto wrapped_event = compatibility_new<Object>(p->isolate);
+
+ {
+ auto n
+ = reinterpret_cast<Ecore_Event_Signal_User*>(event)->number;
+ wrapped_event->Set(compatibility_new<String>(p->isolate,
+ "number"),
+ compatibility_new<Integer>(p->isolate, n));
+ }
+
+ Handle<Value> args[2]{
+ compatibility_new<Integer>(p->isolate, type),
+ wrapped_event
+ };
+
+ auto ret = closure->Call(Undefined(p->isolate), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER, cb, p);
+ return compatibility_return(wrap_event_handler(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_signal_exit_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::Boolean;
+ using v8::String;
+ using v8::Value;
+ using v8::Object;
+ using v8::Function;
+ using v8::Handle;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ auto p = new persistent_with_isolate_t(isolate, args[0]);
+
+ auto cb = [](void *d, int type, void *ev) -> Eina_Bool {
+ auto p = reinterpret_cast<persistent_with_isolate_t*>(d);
+ auto value = Local<Value>::New(p->isolate, p->persistent);
+ auto closure = Function::Cast(*value);
+
+ auto wrapped_event = compatibility_new<Object>(p->isolate);
+
+ {
+ auto event = reinterpret_cast<Ecore_Event_Signal_Exit*>(ev);
+ auto interrupt = event->interrupt;
+ auto quit = event->quit;
+ auto terminate = event->terminate;
+
+ wrapped_event->Set(compatibility_new<String>(p->isolate,
+ "interrupt"),
+ compatibility_new<Boolean>(p->isolate,
+ interrupt));
+ wrapped_event->Set(compatibility_new<String>(p->isolate,
+ "quit"),
+ compatibility_new<Boolean>(p->isolate,
+ quit));
+ wrapped_event->Set(compatibility_new<String>(p->isolate,
+ "terminate"),
+ compatibility_new<Boolean>(p->isolate,
+ terminate));
+ }
+
+ Handle<Value> args[2]{
+ compatibility_new<Integer>(p->isolate, type),
+ wrapped_event
+ };
+
+ auto ret = closure->Call(Undefined(p->isolate), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, cb, p);
+ return compatibility_return(wrap_event_handler(ret, isolate), args);
+ };
+
+ global->Set(name,
+ compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
+}
+
+EAPI
+void register_event_signal_realtime_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name)
+{
+ using v8::Integer;
+ using v8::String;
+ using v8::Value;
+ using v8::Object;
+ using v8::Function;
+ using v8::Handle;
+ using v8::Local;
+ using v8::FunctionTemplate;
+
+ auto f = [](compatibility_callback_info_type args)
+ -> compatibility_return_type {
+ if (args.Length() != 1 || !args[0]->IsFunction())
+ return compatibility_return();
+
+ auto isolate = args.GetIsolate();
+
+ auto p = new persistent_with_isolate_t(isolate, args[0]);
+
+ auto cb = [](void *d, int type, void *ev) -> Eina_Bool {
+ auto p = reinterpret_cast<persistent_with_isolate_t*>(d);
+ auto value = Local<Value>::New(p->isolate, p->persistent);
+ auto closure = Function::Cast(*value);
+
+ auto wrapped_event = compatibility_new<Object>(p->isolate);
+
+ {
+ auto n
+ = reinterpret_cast<Ecore_Event_Signal_Realtime*>(ev)->num;
+ wrapped_event->Set(compatibility_new<String>(p->isolate, "num"),
+ compatibility_new<Integer>(p->isolate, n));
+ }
+
+ Handle<Value> args[2]{
+ compatibility_new<Integer>(p->isolate, type),
+ wrapped_event
+ };
+
+ auto ret = closure->Call(Undefined(p->isolate), 2, args);
+ auto bret = ret->IsBoolean() && ret->BooleanValue();
+
+ return bret ? EINA_TRUE : EINA_FALSE;
+ };
+
+ auto ret = ecore_event_handler_add(ECORE_EVENT_SIGNAL_REALTIME, cb, p);
+ return compatibility_return(wrap_event_handler(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_event.hh b/src/bindings/ecore_js/ecore_js_event.hh
new file mode 100644
index 0000000000..e9f4e609a3
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_event.hh
@@ -0,0 +1,122 @@
+#ifndef ECORE_JS_EVENT_HH
+#define ECORE_JS_EVENT_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_event_none(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_signal_user(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_signal_hup(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_signal_exit(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_signal_power(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_signal_realtime(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_memory_state(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_power_state(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_locale_changed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_hostname_changed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_system_timedate_changed(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_type_new(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_filter_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_current_type_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_memory_state_normal(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_memory_state_low(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_power_state_mains(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_power_state_battery(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_power_state_low(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_memory_state_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_power_state_get(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_signal_user_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_signal_exit_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+void register_event_signal_realtime_handler_add(v8::Isolate *isolate,
+ v8::Handle<v8::Object> global,
+ v8::Handle<v8::String> name);
+
+} } } // namespace efl { namespace ecore { namespace js {
+
+#endif /* ECORE_JS_EVENT_HH */
diff --git a/src/tests/ecore_js/ecore_js_suite.cc b/src/tests/ecore_js/ecore_js_suite.cc
index eb4ad14dd0..391ac9ac94 100644
--- a/src/tests/ecore_js/ecore_js_suite.cc
+++ b/src/tests/ecore_js/ecore_js_suite.cc
@@ -16,6 +16,7 @@
#include <ecore_js_init.hh>
#include <ecore_js_mainloop.hh>
#include <ecore_js_timer.hh>
+#include <ecore_js_event.hh>
const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>";
@@ -164,6 +165,87 @@ void test_setup(v8::Handle<v8::Object> exports)
compatibility_new<String>(isolate,
"ecore_timer_loop_add"));
+ // event
+ register_event_none(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ECORE_EVENT_NONE"));
+ register_event_signal_user(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_EVENT_SIGNAL_USER"));
+ register_event_signal_hup(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_EVENT_SIGNAL_HUP"));
+ register_event_signal_exit(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_EVENT_SIGNAL_EXIT"));
+ register_event_signal_power(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_EVENT_SIGNAL_POWER"));
+ register_event_signal_realtime(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_EVENT_SIGNAL_REALTIME"));
+ register_event_memory_state(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_EVENT_MEMORY_STATE"));
+ register_event_power_state(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_EVENT_POWER_STATE"));
+ register_event_locale_changed(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_EVENT_LOCALE_CHANGED"));
+ register_event_hostname_changed(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_EVENT_HOSTNAME_CHANGED"));
+ register_event_system_timedate_changed(isolate, exports,
+ compatibility_new<String>
+ (isolate,
+ "ECORE_EVENT_SYSTEM_TIMEDATE"
+ "_CHANGED"));
+ register_event_type_new(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ecore_event_type_new"));
+ register_event_add(isolate, exports,
+ compatibility_new<String>(isolate, "ecore_event_add"));
+ register_event_handler_add(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ecore_event_handler_add"));
+ register_event_filter_add(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ecore_event_filter_add"));
+ register_event_current_type_get(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ecore_event_current_type_get"));
+ register_memory_state_normal(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_MEMORY_STATE_NORMAL"));
+ register_memory_state_low(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_MEMORY_STATE_LOW"));
+ register_power_state_mains(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_POWER_STATE_MAINS"));
+ register_power_state_battery(isolate, exports,
+ compatibility_new<String>
+ (isolate, "ECORE_POWER_STATE_BATTERY"));
+ register_power_state_low(isolate, exports,
+ compatibility_new<String>(isolate,
+ "ECORE_POWER_STATE_LOW"));
+ register_event_signal_user_handler_add(isolate, exports,
+ compatibility_new<String>
+ (isolate,
+ "ecore_event_signal_user_handler"
+ "_add"));
+ register_event_signal_exit_handler_add(isolate, exports,
+ compatibility_new<String>
+ (isolate,
+ "ecore_event_signal_exit_handler"
+ "_add"));
+ register_event_signal_realtime_handler_add(isolate, exports,
+ compatibility_new<String>
+ (isolate,
+ "ecore_event_signal_realtime"
+ "_handler_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 6882ae9aca..5f0eea2d0a 100755
--- a/src/tests/ecore_js/ecore_js_suite.js
+++ b/src/tests/ecore_js/ecore_js_suite.js
@@ -121,6 +121,76 @@ suite.ecore_timer_add(2, function() {
suite.ecore_mainloop_begin();
assert(captured === false);
+// Ecore event
+
+var myevent = suite.ecore_event_type_new();
+
+captured = [0, 0, 0]
+
+var handler1 = suite.ecore_event_handler_add(myevent, function(event) {
+ assert(suite.ecore_event_current_type_get() === myevent);
+ assert(event === myevent);
+ captured[0] += 1;
+ return suite.ECORE_CALLBACK_PASS_ON;
+});
+
+suite.ecore_event_handler_add(myevent, function(event) {
+ assert(suite.ecore_event_current_type_get() === myevent);
+ assert(event === myevent);
+ captured[1] += 1;
+ return suite.ECORE_CALLBACK_DONE;
+});
+
+suite.ecore_event_handler_add(myevent, function(event) {
+ assert(suite.ecore_event_current_type_get() === myevent);
+ assert(event === myevent);
+ captured[2] += 1;
+ return suite.ECORE_CALLBACK_DONE;
+});
+
+suite.ecore_timer_add(1, function() {
+ suite.ecore_event_add(myevent);
+ assert(captured[0] === 0 && captured[1] === 0 && captured[2] === 0);
+ suite.ecore_timer_add(1, function() {
+ assert(captured[0] === 1 && captured[1] === 1 && captured[2] === 0);
+ handler1.del();
+ suite.ecore_event_add(myevent);
+ suite.ecore_event_add(myevent);
+ suite.ecore_timer_add(1, function() {
+ assert(captured[0] === 1 && captured[1] === 3 && captured[2] === 0);
+ suite.ecore_mainloop_quit();
+ });
+ });
+});
+
+suite.ecore_mainloop_begin();
+
+suite.ecore_event_add(myevent);
+suite.ecore_event_add(myevent);
+suite.ecore_event_add(myevent);
+
+var filter = suite.ecore_event_filter_add(function() {
+ return {count: 0};
+}, function(loop_data, event) {
+ assert(event === myevent);
+ var c = loop_data.count;
+ ++loop_data.count;
+ return c != 0;
+}, function(loop_data) {});
+
+suite.ecore_timer_add(1, suite.ecore_mainloop_quit);
+suite.ecore_mainloop_begin();
+assert(captured[1] === 5);
+filter.del();
+
+suite.ecore_event_add(myevent);
+suite.ecore_event_add(myevent);
+suite.ecore_event_add(myevent);
+
+suite.ecore_timer_add(1, suite.ecore_mainloop_quit);
+suite.ecore_mainloop_begin();
+assert(captured[1] === 8);
+
// Ecore shutdown
suite.ecore_shutdown();