#ifdef HAVE_CONFIG_H #include #endif #include namespace efl { namespace eio { 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; namespace { Eio_File* extract_eio_file(v8::Local object) { return compatibility_get_pointer_internal_field(object, 0); } v8::Local wrap_eio_file(Eio_File *file, v8::Isolate *isolate) { using v8::String; using v8::Boolean; using v8::ObjectTemplate; using v8::FunctionTemplate; auto obj_tpl = compatibility_new(isolate); obj_tpl->SetInternalFieldCount(1); auto ret = obj_tpl->NewInstance(); auto cancel = [](compatibility_callback_info_type info) -> compatibility_return_type { if (info.Length() != 0) return compatibility_return(); auto isolate = info.GetIsolate(); auto ret = eio_file_cancel(extract_eio_file(info.This())); return compatibility_return(compatibility_new(isolate, ret), info); }; auto check = [](compatibility_callback_info_type info) -> compatibility_return_type { if (info.Length() != 0) return compatibility_return(); auto isolate = info.GetIsolate(); auto ret = eio_file_check(extract_eio_file(info.This())); return compatibility_return(compatibility_new(isolate, ret), info); }; ret->Set(compatibility_new(isolate, "cancel"), compatibility_new(isolate, cancel) ->GetFunction()); ret->Set(compatibility_new(isolate, "check"), compatibility_new(isolate, check) ->GetFunction()); compatibility_set_pointer_internal_field(ret, 0, file); return ret; } static Eina_File* extract_eina_file(v8::Local object) { return compatibility_get_pointer_internal_field(object, 0); } static v8::Local wrap_eina_file(Eina_File *file, v8::Isolate *isolate) { using v8::String; using v8::ObjectTemplate; using v8::Object; using v8::FunctionTemplate; auto obj_tpl = compatibility_new(isolate); obj_tpl->SetInternalFieldCount(1); auto ret = obj_tpl->NewInstance(); /* TODO: Eina_File only handle files open in read-only mode. Althought there aren't many useful functions exposed to a JavaScript binding, the exposed `file->fd` can be used to expose a few read operations found in ``. */ auto close = [](compatibility_callback_info_type info) -> compatibility_return_type { if (info.Length() != 0) return compatibility_return(); auto o = info.This(); auto file = extract_eina_file(o); if (!file) return compatibility_return(); eina_file_close(file); compatibility_set_pointer_internal_field(o, 0, nullptr); return compatibility_return(); }; ret->Set(compatibility_new(isolate, "close"), compatibility_new(isolate, close) ->GetFunction()); compatibility_set_pointer_internal_field(ret, 0, file); auto on_gc = [ret]() { auto file = extract_eina_file(ret); if (file) { eina_file_close(file); compatibility_set_pointer_internal_field(ret, 0, nullptr); } }; efl::eina::js::make_weak(isolate, ret, on_gc); return ret; } static Eio_Monitor* extract_monitor(v8::Local object) { return compatibility_get_pointer_internal_field(object, 0); } static v8::Local wrap_monitor(Eio_Monitor *monitor, v8::Isolate *isolate) { using v8::String; using v8::ObjectTemplate; using v8::FunctionTemplate; auto obj_tpl = compatibility_new(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(); eio_monitor_del(extract_monitor(info.This())); return compatibility_return(); }; auto path_get = [](compatibility_callback_info_type info) -> compatibility_return_type { if (info.Length() != 0) return compatibility_return(); auto ret = eio_monitor_path_get(extract_monitor(info.This())); return compatibility_return(compatibility_new(info.GetIsolate(), ret), info); }; ret->Set(compatibility_new(isolate, "del"), compatibility_new(isolate, del)->GetFunction()); ret->Set(compatibility_new(isolate, "getPath"), compatibility_new(isolate, path_get) ->GetFunction()); compatibility_set_pointer_internal_field(ret, 0, monitor); return ret; } static Ecore_Event_Handler *extract_event_handler(v8::Local object) { return compatibility_get_pointer_internal_field (object, 0); } static v8::Local wrap_event_handler(Ecore_Event_Handler *handler, v8::Isolate *isolate) { using v8::String; using v8::ObjectTemplate; using v8::FunctionTemplate; using v8::Value; auto obj_tpl = compatibility_new(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())); auto per = static_cast*>(p); per->dispose(); delete per; return compatibility_return(); }; ret->Set(compatibility_new(isolate, "del"), compatibility_new(isolate, del)->GetFunction()); compatibility_set_pointer_internal_field(ret, 0, handler); return ret; } static v8::Local wrap_eina_file_direct_info(const Eina_File_Direct_Info* info, v8::Isolate *isolate) { using v8::Object; using v8::String; using v8::Integer; auto wrapped_info = compatibility_new(isolate); wrapped_info->Set(compatibility_new(isolate, "pathLength"), compatibility_new(isolate, info->path_length)); wrapped_info->Set(compatibility_new(isolate, "nameLength"), compatibility_new(isolate, info->name_length)); wrapped_info->Set(compatibility_new(isolate, "nameStart"), compatibility_new(isolate, info->name_start)); wrapped_info->Set(compatibility_new(isolate, "type"), compatibility_new(isolate, info->type)); wrapped_info->Set(compatibility_new(isolate, "path"), compatibility_new(isolate, info->path)); return wrapped_info; } EAPI void register_init(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; using v8::FunctionTemplate; auto init = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 0) return compatibility_return(); auto isolate = args.GetIsolate(); auto ret = eio_init(); return compatibility_return(compatibility_new(isolate, ret), args); }; global->Set(name, compatibility_new(isolate, init) ->GetFunction()); } EAPI void register_shutdown(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; using v8::FunctionTemplate; auto shutdown = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 0) return compatibility_return(); auto isolate = args.GetIsolate(); auto ret = eio_shutdown(); return compatibility_return(compatibility_new(isolate, ret), args); }; global->Set(name, compatibility_new(isolate, shutdown) ->GetFunction()); } EAPI void register_op_file_copy(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_FILE_COPY)); } EAPI void register_op_file_move(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_FILE_MOVE)); } EAPI void register_op_dir_copy(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_DIR_COPY)); } EAPI void register_op_dir_move(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_DIR_MOVE)); } EAPI void register_op_unlink(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_UNLINK)); } EAPI void register_op_file_getpwnam(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_FILE_GETPWNAM)); } EAPI void register_op_file_getgrnam(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_FILE_GETGRNAM)); } EAPI void register_file_open(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; using v8::Value; using v8::String; using v8::FunctionTemplate; using v8::Function; using v8::Handle; using std::unique_ptr; typedef efl::eina::js::global_ref persistent_t; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsBoolean() || !args[2]->IsFunction() || !args[3]->IsFunction()) return compatibility_return(); auto isolate = args.GetIsolate(); auto cb_data = unique_ptr(new persistent_t[2]); cb_data[0] = persistent_t(isolate, args[2]); cb_data[1] = persistent_t(isolate, args[3]); auto open_cb = [](void *data, Eio_File *handler, Eina_File *file) { auto persistent = reinterpret_cast(data); auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), wrap_eina_file(file, isolate) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] persistent; }; auto error_cb = [](void *data, Eio_File *handler, int error) { auto persistent = reinterpret_cast(data) + 1; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, error) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] (persistent - 1); }; auto ret = eio_file_open(*String::Utf8Value(args[0]), args[1]->BooleanValue(), open_cb, error_cb, cb_data.release()); return compatibility_return(wrap_eio_file(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } EAPI void register_monitor_file_created(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_MONITOR_FILE_CREATED)); } EAPI void register_monitor_file_deleted(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_MONITOR_FILE_DELETED)); } EAPI void register_monitor_file_modified(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_MONITOR_FILE_MODIFIED)); } EAPI void register_monitor_file_closed(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_MONITOR_FILE_CLOSED)); } EAPI void register_monitor_directory_created(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_MONITOR_DIRECTORY_CREATED)); } EAPI void register_monitor_directory_deleted(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_MONITOR_DIRECTORY_DELETED)); } EAPI void register_monitor_directory_modified(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_MONITOR_DIRECTORY_MODIFIED)); } EAPI void register_monitor_directory_closed(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_MONITOR_DIRECTORY_CLOSED)); } EAPI void register_monitor_self_rename(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_MONITOR_SELF_RENAME)); } EAPI void register_monitor_self_deleted(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_MONITOR_SELF_DELETED)); } EAPI void register_monitor_error(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::Integer; global->Set(name, compatibility_new(isolate, EIO_MONITOR_ERROR)); } EAPI void register_monitor_add(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::String; using v8::Integer; using v8::FunctionTemplate; using v8::Handle; using v8::Value; using v8::Function; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 1 || !args[0]->IsString()) return compatibility_return(); auto isolate = args.GetIsolate(); auto ret = eio_monitor_add(*String::Utf8Value(args[0])); return compatibility_return(wrap_monitor(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } template static void register_monitor_event_handler_add(v8::Isolate *isolate, v8::Handle global, v8::Handle 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 efl::eina::js::global_ref(isolate, args[0]); auto cb = [](void *d, int type, void *event) -> Eina_Bool { auto p = reinterpret_cast*>(d); auto e = reinterpret_cast(event); auto isolate = v8::Isolate::GetCurrent(); auto o = p->handle(); auto wrapped_event = compatibility_new(isolate); wrapped_event->Set(compatibility_new(isolate, "monitor"), wrap_monitor(e->monitor, isolate)); wrapped_event->Set(compatibility_new(isolate, "filename"), compatibility_new(isolate, e->filename)); Handle args[2]{ compatibility_new(isolate, type), wrapped_event }; auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args); auto bret = ret->IsBoolean() && ret->BooleanValue(); return bret ? EINA_TRUE : EINA_FALSE; }; auto ret = ecore_event_handler_add(wanted_event, cb, p); return compatibility_return(wrap_event_handler(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } EAPI void register_event_monitor_file_created_handler_add(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { return register_monitor_event_handler_add (isolate, global, name); } EAPI void register_event_monitor_file_deleted_handler_add(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { return register_monitor_event_handler_add (isolate, global, name); } EAPI void register_event_monitor_file_modified_handler_add(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { return register_monitor_event_handler_add (isolate, global, name); } EAPI void register_event_monitor_file_closed_handler_add(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { return register_monitor_event_handler_add (isolate, global, name); } EAPI void register_event_monitor_directory_created_handler_add (v8::Isolate *isolate, v8::Handle global, v8::Handle name) { return register_monitor_event_handler_add (isolate, global, name); } EAPI void register_event_monitor_directory_deleted_handler_add (v8::Isolate *isolate, v8::Handle global, v8::Handle name) { return register_monitor_event_handler_add (isolate, global, name); } EAPI void register_event_monitor_directory_modified_handler_add (v8::Isolate *isolate, v8::Handle global, v8::Handle name) { return register_monitor_event_handler_add (isolate, global, name); } EAPI void register_event_monitor_directory_closed_handler_add (v8::Isolate *isolate, v8::Handle global, v8::Handle name) { return register_monitor_event_handler_add (isolate, global, name); } EAPI void register_event_monitor_self_rename_handler_add(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { return register_monitor_event_handler_add (isolate, global, name); } EAPI void register_event_monitor_self_deleted_handler_add(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { return register_monitor_event_handler_add (isolate, global, name); } EAPI void register_event_monitor_error_handler_add(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { return register_monitor_event_handler_add (isolate, global, name); } EAPI void register_file_ls(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::String; using v8::Integer; using v8::FunctionTemplate; using v8::Handle; using v8::Value; using v8::Function; using std::unique_ptr; typedef efl::eina::js::global_ref persistent_t; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsFunction() || !args[2]->IsFunction() || !args[3]->IsFunction() || !args[4]->IsFunction()) { return compatibility_return(); } auto isolate = args.GetIsolate(); auto cb_data = unique_ptr(new persistent_t[4]); cb_data[0] = persistent_t(isolate, args[1]); cb_data[1] = persistent_t(isolate, args[2]); cb_data[2] = persistent_t(isolate, args[3]); cb_data[3] = persistent_t(isolate, args[4]); auto filter_cb = [](void *data, Eio_File *handler, const char *file) -> Eina_Bool { auto persistent = reinterpret_cast(data); auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, file) }; auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args); auto bret = ret->IsBoolean() && ret->BooleanValue(); return bret ? EINA_TRUE : EINA_FALSE; }; auto main_cb = [](void *data, Eio_File *handler, const char *file) { auto persistent = reinterpret_cast(data) + 1; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, file) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); }; auto done_cb = [](void *data, Eio_File *handler) { auto persistent = reinterpret_cast(data) + 2; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args = wrap_eio_file(handler, isolate); Function::Cast(*o)->Call(o->ToObject(), 1, &args); delete[] (persistent - 2); }; auto error_cb = [](void *data, Eio_File *handler, int error) { auto persistent = reinterpret_cast(data) + 3; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, error) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] (persistent - 3); }; auto ret = eio_file_ls(*String::Utf8Value(args[0]), filter_cb, main_cb, done_cb, error_cb, cb_data.release()); return compatibility_return(wrap_eio_file(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } EAPI void register_file_chmod(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::String; using v8::Integer; using v8::FunctionTemplate; using v8::Handle; using v8::Value; using v8::Function; using std::unique_ptr; typedef efl::eina::js::global_ref persistent_t; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsNumber() || !args[2]->IsFunction() || !args[3]->IsFunction()) { return compatibility_return(); } auto isolate = args.GetIsolate(); auto cb_data = unique_ptr(new persistent_t[2]); cb_data[0] = persistent_t(isolate, args[2]); cb_data[1] = persistent_t(isolate, args[3]); auto done_cb = [](void *data, Eio_File *handler) { auto persistent = reinterpret_cast(data); auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args = wrap_eio_file(handler, isolate); Function::Cast(*o)->Call(o->ToObject(), 1, &args); delete[] persistent; }; auto error_cb = [](void *data, Eio_File *handler, int error) { auto persistent = reinterpret_cast(data) + 1; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, error) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] (persistent - 1); }; auto ret = eio_file_chmod(*String::Utf8Value(args[0]), args[1]->IntegerValue(), done_cb, error_cb, cb_data.release()); return compatibility_return(wrap_eio_file(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } EAPI void register_file_chown(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::String; using v8::Integer; using v8::FunctionTemplate; using v8::Handle; using v8::Value; using v8::Function; using std::unique_ptr; typedef efl::eina::js::global_ref persistent_t; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString() || !args[3]->IsFunction() || !args[4]->IsFunction()) { return compatibility_return(); } auto isolate = args.GetIsolate(); auto cb_data = unique_ptr(new persistent_t[2]); cb_data[0] = persistent_t(isolate, args[3]); cb_data[1] = persistent_t(isolate, args[4]); auto done_cb = [](void *data, Eio_File *handler) { auto persistent = reinterpret_cast(data); auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args = wrap_eio_file(handler, isolate); Function::Cast(*o)->Call(o->ToObject(), 1, &args); delete[] persistent; }; auto error_cb = [](void *data, Eio_File *handler, int error) { auto persistent = reinterpret_cast(data) + 1; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, error) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] (persistent - 1); }; auto ret = eio_file_chown(*String::Utf8Value(args[0]), *String::Utf8Value(args[1]), *String::Utf8Value(args[2]), done_cb, error_cb, cb_data.release()); return compatibility_return(wrap_eio_file(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } EAPI void register_file_unlink(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::String; using v8::Integer; using v8::FunctionTemplate; using v8::Handle; using v8::Value; using v8::Function; using std::unique_ptr; typedef efl::eina::js::global_ref persistent_t; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 3 || !args[0]->IsString() || !args[1]->IsFunction() || !args[2]->IsFunction()) { return compatibility_return(); } auto isolate = args.GetIsolate(); auto cb_data = unique_ptr(new persistent_t[2]); cb_data[0] = persistent_t(isolate, args[1]); cb_data[1] = persistent_t(isolate, args[2]); auto done_cb = [](void *data, Eio_File *handler) { auto persistent = reinterpret_cast(data); auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args = wrap_eio_file(handler, isolate); Function::Cast(*o)->Call(o->ToObject(), 1, &args); delete[] persistent; }; auto error_cb = [](void *data, Eio_File *handler, int error) { auto persistent = reinterpret_cast(data) + 1; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, error) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] (persistent - 1); }; auto ret = eio_file_unlink(*String::Utf8Value(args[0]), done_cb, error_cb, cb_data.release()); return compatibility_return(wrap_eio_file(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } EAPI void register_file_mkdir(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::String; using v8::Integer; using v8::FunctionTemplate; using v8::Handle; using v8::Value; using v8::Function; using std::unique_ptr; typedef efl::eina::js::global_ref persistent_t; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsNumber() || !args[2]->IsString() || !args[3]->IsFunction()) { return compatibility_return(); } auto isolate = args.GetIsolate(); auto cb_data = unique_ptr(new persistent_t[2]); cb_data[0] = persistent_t(isolate, args[2]); cb_data[1] = persistent_t(isolate, args[3]); auto done_cb = [](void *data, Eio_File *handler) { auto persistent = reinterpret_cast(data); auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args = wrap_eio_file(handler, isolate); Function::Cast(*o)->Call(o->ToObject(), 1, &args); delete[] persistent; }; auto error_cb = [](void *data, Eio_File *handler, int error) { auto persistent = reinterpret_cast(data) + 1; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, error) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] (persistent - 1); }; auto ret = eio_file_mkdir(*String::Utf8Value(args[0]), args[1]->IntegerValue(), done_cb, error_cb, cb_data.release()); return compatibility_return(wrap_eio_file(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } EAPI void register_file_move(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::String; using v8::Integer; using v8::Number; using v8::Object; using v8::FunctionTemplate; using v8::Handle; using v8::Value; using v8::Function; using std::unique_ptr; typedef efl::eina::js::global_ref persistent_t; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsFunction() || !args[3]->IsFunction() || !args[4]->IsFunction()) { return compatibility_return(); } auto isolate = args.GetIsolate(); auto cb_data = unique_ptr(new persistent_t[3]); cb_data[0] = persistent_t(isolate, args[2]); cb_data[1] = persistent_t(isolate, args[3]); cb_data[2] = persistent_t(isolate, args[4]); auto progress_cb = [](void *data, Eio_File *handler, const Eio_Progress *info) { auto persistent = reinterpret_cast(data); auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); auto wrapped_info = compatibility_new(isolate); wrapped_info->Set(compatibility_new(isolate, "op"), compatibility_new(isolate, info->op)); wrapped_info->Set(compatibility_new(isolate, "current"), compatibility_new(isolate, info->current)); wrapped_info->Set(compatibility_new(isolate, "max"), compatibility_new(isolate, info->max)); wrapped_info->Set(compatibility_new(isolate, "percent"), compatibility_new(isolate, info->percent)); wrapped_info->Set(compatibility_new(isolate, "source"), compatibility_new(isolate, info->source)); wrapped_info->Set(compatibility_new(isolate, "dest"), compatibility_new(isolate, info->dest)); Handle args[2] = { wrap_eio_file(handler, isolate), wrapped_info }; Function::Cast(*o)->Call(o->ToObject(), 2, args); }; auto done_cb = [](void *data, Eio_File *handler) { auto persistent = reinterpret_cast(data) + 1; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args = wrap_eio_file(handler, isolate); Function::Cast(*o)->Call(o->ToObject(), 1, &args); delete[] (persistent - 1); }; auto error_cb = [](void *data, Eio_File *handler, int error) { auto persistent = reinterpret_cast(data) + 2; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, error) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] (persistent - 2); }; auto ret = eio_file_move(*String::Utf8Value(args[0]), *String::Utf8Value(args[1]), progress_cb, done_cb, error_cb, cb_data.release()); return compatibility_return(wrap_eio_file(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } EAPI void register_file_copy(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::String; using v8::Integer; using v8::Number; using v8::Object; using v8::FunctionTemplate; using v8::Handle; using v8::Value; using v8::Function; using std::unique_ptr; typedef efl::eina::js::global_ref persistent_t; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsFunction() || !args[3]->IsFunction() || !args[4]->IsFunction()) { return compatibility_return(); } auto isolate = args.GetIsolate(); auto cb_data = unique_ptr(new persistent_t[3]); cb_data[0] = persistent_t(isolate, args[2]); cb_data[1] = persistent_t(isolate, args[3]); cb_data[2] = persistent_t(isolate, args[4]); auto progress_cb = [](void *data, Eio_File *handler, const Eio_Progress *info) { auto persistent = reinterpret_cast(data); auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); auto wrapped_info = compatibility_new(isolate); wrapped_info->Set(compatibility_new(isolate, "op"), compatibility_new(isolate, info->op)); wrapped_info->Set(compatibility_new(isolate, "current"), compatibility_new(isolate, info->current)); wrapped_info->Set(compatibility_new(isolate, "max"), compatibility_new(isolate, info->max)); wrapped_info->Set(compatibility_new(isolate, "percent"), compatibility_new(isolate, info->percent)); wrapped_info->Set(compatibility_new(isolate, "source"), compatibility_new(isolate, info->source)); wrapped_info->Set(compatibility_new(isolate, "dest"), compatibility_new(isolate, info->dest)); Handle args[2] = { wrap_eio_file(handler, isolate), wrapped_info }; Function::Cast(*o)->Call(o->ToObject(), 2, args); }; auto done_cb = [](void *data, Eio_File *handler) { auto persistent = reinterpret_cast(data) + 1; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args = wrap_eio_file(handler, isolate); Function::Cast(*o)->Call(o->ToObject(), 1, &args); delete[] (persistent - 1); }; auto error_cb = [](void *data, Eio_File *handler, int error) { auto persistent = reinterpret_cast(data) + 2; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, error) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] (persistent - 2); }; auto ret = eio_file_copy(*String::Utf8Value(args[0]), *String::Utf8Value(args[1]), progress_cb, done_cb, error_cb, cb_data.release()); return compatibility_return(wrap_eio_file(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } EAPI void register_dir_move(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::String; using v8::Integer; using v8::Number; using v8::Object; using v8::FunctionTemplate; using v8::Handle; using v8::Value; using v8::Function; using std::unique_ptr; typedef efl::eina::js::global_ref persistent_t; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 6 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsFunction() || !args[3]->IsFunction() || !args[4]->IsFunction() || !args[5]->IsFunction()) { return compatibility_return(); } auto isolate = args.GetIsolate(); auto cb_data = unique_ptr(new persistent_t[4]); cb_data[0] = persistent_t(isolate, args[2]); cb_data[1] = persistent_t(isolate, args[3]); cb_data[2] = persistent_t(isolate, args[4]); cb_data[3] = persistent_t(isolate, args[5]); auto filter_cb = [](void *data, Eio_File *handler, const Eina_File_Direct_Info *info) -> Eina_Bool { auto persistent = reinterpret_cast(data); auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), wrap_eina_file_direct_info(info, isolate) }; auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args); auto bret = ret->IsBoolean() && ret->BooleanValue(); return bret ? EINA_TRUE : EINA_FALSE; }; auto progress_cb = [](void *data, Eio_File *handler, const Eio_Progress *info) { auto persistent = reinterpret_cast(data) + 1; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); auto wrapped_info = compatibility_new(isolate); wrapped_info->Set(compatibility_new(isolate, "op"), compatibility_new(isolate, info->op)); wrapped_info->Set(compatibility_new(isolate, "current"), compatibility_new(isolate, info->current)); wrapped_info->Set(compatibility_new(isolate, "max"), compatibility_new(isolate, info->max)); wrapped_info->Set(compatibility_new(isolate, "percent"), compatibility_new(isolate, info->percent)); wrapped_info->Set(compatibility_new(isolate, "source"), compatibility_new(isolate, info->source)); wrapped_info->Set(compatibility_new(isolate, "dest"), compatibility_new(isolate, info->dest)); Handle args[2] = { wrap_eio_file(handler, isolate), wrapped_info }; Function::Cast(*o)->Call(o->ToObject(), 2, args); }; auto done_cb = [](void *data, Eio_File *handler) { auto persistent = reinterpret_cast(data) + 2; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args = wrap_eio_file(handler, isolate); Function::Cast(*o)->Call(o->ToObject(), 1, &args); delete[] (persistent - 2); }; auto error_cb = [](void *data, Eio_File *handler, int error) { auto persistent = reinterpret_cast(data) + 3; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, error) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] (persistent - 3); }; auto ret = eio_dir_move(*String::Utf8Value(args[0]), *String::Utf8Value(args[1]), filter_cb, progress_cb, done_cb, error_cb, cb_data.release()); return compatibility_return(wrap_eio_file(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } EAPI void register_dir_copy(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::String; using v8::Integer; using v8::Number; using v8::Object; using v8::FunctionTemplate; using v8::Handle; using v8::Value; using v8::Function; using std::unique_ptr; typedef efl::eina::js::global_ref persistent_t; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 6 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsFunction() || !args[3]->IsFunction() || !args[4]->IsFunction() || !args[5]->IsFunction()) { return compatibility_return(); } auto isolate = args.GetIsolate(); auto cb_data = unique_ptr(new persistent_t[4]); cb_data[0] = persistent_t(isolate, args[2]); cb_data[1] = persistent_t(isolate, args[3]); cb_data[2] = persistent_t(isolate, args[4]); cb_data[3] = persistent_t(isolate, args[5]); auto filter_cb = [](void *data, Eio_File *handler, const Eina_File_Direct_Info *info) -> Eina_Bool { auto persistent = reinterpret_cast(data); auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), wrap_eina_file_direct_info(info, isolate) }; auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args); auto bret = ret->IsBoolean() && ret->BooleanValue(); return bret ? EINA_TRUE : EINA_FALSE; }; auto progress_cb = [](void *data, Eio_File *handler, const Eio_Progress *info) { auto persistent = reinterpret_cast(data) + 1; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); auto wrapped_info = compatibility_new(isolate); wrapped_info->Set(compatibility_new(isolate, "op"), compatibility_new(isolate, info->op)); wrapped_info->Set(compatibility_new(isolate, "current"), compatibility_new(isolate, info->current)); wrapped_info->Set(compatibility_new(isolate, "max"), compatibility_new(isolate, info->max)); wrapped_info->Set(compatibility_new(isolate, "percent"), compatibility_new(isolate, info->percent)); wrapped_info->Set(compatibility_new(isolate, "source"), compatibility_new(isolate, info->source)); wrapped_info->Set(compatibility_new(isolate, "dest"), compatibility_new(isolate, info->dest)); Handle args[2] = { wrap_eio_file(handler, isolate), wrapped_info }; Function::Cast(*o)->Call(o->ToObject(), 2, args); }; auto done_cb = [](void *data, Eio_File *handler) { auto persistent = reinterpret_cast(data) + 2; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args = wrap_eio_file(handler, isolate); Function::Cast(*o)->Call(o->ToObject(), 1, &args); delete[] (persistent - 2); }; auto error_cb = [](void *data, Eio_File *handler, int error) { auto persistent = reinterpret_cast(data) + 3; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, error) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] (persistent - 3); }; auto ret = eio_dir_copy(*String::Utf8Value(args[0]), *String::Utf8Value(args[1]), filter_cb, progress_cb, done_cb, error_cb, cb_data.release()); return compatibility_return(wrap_eio_file(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } EAPI void register_dir_unlink(v8::Isolate *isolate, v8::Handle global, v8::Handle name) { using v8::String; using v8::Integer; using v8::Number; using v8::Object; using v8::FunctionTemplate; using v8::Handle; using v8::Value; using v8::Function; using std::unique_ptr; typedef efl::eina::js::global_ref persistent_t; auto f = [](compatibility_callback_info_type args) -> compatibility_return_type { if (args.Length() != 5 || !args[0]->IsString() || !args[1]->IsFunction() || !args[2]->IsFunction() || !args[3]->IsFunction() || !args[4]->IsFunction()) { return compatibility_return(); } auto isolate = args.GetIsolate(); auto cb_data = unique_ptr(new persistent_t[4]); cb_data[0] = persistent_t(isolate, args[1]); cb_data[1] = persistent_t(isolate, args[2]); cb_data[2] = persistent_t(isolate, args[3]); cb_data[3] = persistent_t(isolate, args[4]); auto filter_cb = [](void *data, Eio_File *handler, const Eina_File_Direct_Info *info) -> Eina_Bool { auto persistent = reinterpret_cast(data); auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), wrap_eina_file_direct_info(info, isolate) }; auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args); auto bret = ret->IsBoolean() && ret->BooleanValue(); return bret ? EINA_TRUE : EINA_FALSE; }; auto progress_cb = [](void *data, Eio_File *handler, const Eio_Progress *info) { auto persistent = reinterpret_cast(data) + 1; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); auto wrapped_info = compatibility_new(isolate); wrapped_info->Set(compatibility_new(isolate, "op"), compatibility_new(isolate, info->op)); wrapped_info->Set(compatibility_new(isolate, "current"), compatibility_new(isolate, info->current)); wrapped_info->Set(compatibility_new(isolate, "max"), compatibility_new(isolate, info->max)); wrapped_info->Set(compatibility_new(isolate, "percent"), compatibility_new(isolate, info->percent)); wrapped_info->Set(compatibility_new(isolate, "source"), compatibility_new(isolate, info->source)); wrapped_info->Set(compatibility_new(isolate, "dest"), compatibility_new(isolate, info->dest)); Handle args[2] = { wrap_eio_file(handler, isolate), wrapped_info }; Function::Cast(*o)->Call(o->ToObject(), 2, args); }; auto done_cb = [](void *data, Eio_File *handler) { auto persistent = reinterpret_cast(data) + 2; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args = wrap_eio_file(handler, isolate); Function::Cast(*o)->Call(o->ToObject(), 1, &args); delete[] (persistent - 2); }; auto error_cb = [](void *data, Eio_File *handler, int error) { auto persistent = reinterpret_cast(data) + 3; auto o = persistent->handle(); auto isolate = v8::Isolate::GetCurrent(); Handle args[2] = { wrap_eio_file(handler, isolate), compatibility_new(isolate, error) }; Function::Cast(*o)->Call(o->ToObject(), 2, args); delete[] (persistent - 3); }; auto ret = eio_dir_unlink(*String::Utf8Value(args[0]), filter_cb, progress_cb, done_cb, error_cb, cb_data.release()); return compatibility_return(wrap_eio_file(ret, isolate), args); }; global->Set(name, compatibility_new(isolate, f)->GetFunction()); } } EAPI void register_eio(v8::Isolate* isolate, v8::Handle exports) { using v8::String; auto eioNamespace = efl::eo::js::get_namespace({"Eio"}, isolate, exports); register_init(isolate, eioNamespace, compatibility_new(isolate, "init")); register_shutdown(isolate, eioNamespace, compatibility_new(isolate, "shutdown")); register_op_file_copy(isolate, eioNamespace, compatibility_new(isolate, "FILE_COPY")); register_op_file_move(isolate, eioNamespace, compatibility_new(isolate, "FILE_MOVE")); register_op_dir_copy(isolate, eioNamespace, compatibility_new(isolate, "DIR_COPY")); register_op_dir_move(isolate, eioNamespace, compatibility_new(isolate, "DIR_MOVE")); register_op_unlink(isolate, eioNamespace, compatibility_new(isolate, "UNLINK")); register_op_file_getpwnam(isolate, eioNamespace, compatibility_new(isolate, "FILE_GETPWNAM")); register_op_file_getgrnam(isolate, eioNamespace, compatibility_new(isolate, "FILE_GETGRNAM")); register_file_open(isolate, eioNamespace, compatibility_new(isolate, "openFile")); register_monitor_file_created(isolate, eioNamespace, compatibility_new(isolate, "MONITOR_FILE" "_CREATED")); register_monitor_file_deleted(isolate, eioNamespace, compatibility_new(isolate, "MONITOR_FILE" "_DELETED")); register_monitor_file_modified(isolate, eioNamespace, compatibility_new(isolate, "MONITOR_FILE" "_MODIFIED")); register_monitor_file_closed(isolate, eioNamespace, compatibility_new(isolate, "MONITOR_FILE" "_CLOSED")); register_monitor_directory_created(isolate, eioNamespace, compatibility_new (isolate, "MONITOR_DIRECTORY_CREATED")); register_monitor_directory_deleted(isolate, eioNamespace, compatibility_new (isolate, "MONITOR_DIRECTORY_DELETED")); register_monitor_directory_modified(isolate, eioNamespace, compatibility_new (isolate, "MONITOR_DIRECTORY_MODIFIED")); register_monitor_directory_closed(isolate, eioNamespace, compatibility_new (isolate, "MONITOR_DIRECTORY_CLOSED")); register_monitor_self_rename(isolate, eioNamespace, compatibility_new (isolate, "MONITOR_SELF_RENAME")); register_monitor_self_deleted(isolate, eioNamespace, compatibility_new (isolate, "MONITOR_SELF_DELETED")); register_monitor_error(isolate, eioNamespace, compatibility_new(isolate, "MONITOR_ERROR")); register_monitor_add(isolate, eioNamespace, compatibility_new(isolate, "addMonitor")); register_event_monitor_file_created_handler_add (isolate, eioNamespace, compatibility_new(isolate, "addEventMonitorFileCreatedHandler")); register_event_monitor_file_deleted_handler_add (isolate, eioNamespace, compatibility_new(isolate, "addEventMonitorFileDeletedHandler")); register_event_monitor_file_modified_handler_add (isolate, eioNamespace, compatibility_new (isolate, "addEventMonitorFileModifiedHandler")); register_event_monitor_file_closed_handler_add (isolate, eioNamespace, compatibility_new(isolate, "addEventMonitorFileClosedHandler")); register_event_monitor_directory_created_handler_add (isolate, eioNamespace, compatibility_new (isolate, "addEventMonitorDirectoryCreatedHandler")); register_event_monitor_directory_deleted_handler_add (isolate, eioNamespace, compatibility_new (isolate, "addEventMonitorDirectoryDeletedHandler")); register_event_monitor_directory_modified_handler_add (isolate, eioNamespace, compatibility_new (isolate, "addEventMonitorDirectoryModifiedHandler")); register_event_monitor_directory_closed_handler_add (isolate, eioNamespace, compatibility_new (isolate, "addEventMonitorDirectoryClosedHandler")); register_event_monitor_self_rename_handler_add (isolate, eioNamespace, compatibility_new(isolate, "addEventMonitorSelfRenameHandler")); register_event_monitor_self_deleted_handler_add (isolate, eioNamespace, compatibility_new(isolate, "addEventMonitorSelfDeletedHandler")); register_event_monitor_error_handler_add (isolate, eioNamespace, compatibility_new(isolate, "addEventMonitorErrorHandler")); register_file_ls(isolate, eioNamespace, compatibility_new(isolate, "lsFile")); register_file_chmod(isolate, eioNamespace, compatibility_new(isolate, "chmodFile")); register_file_chown(isolate, eioNamespace, compatibility_new(isolate, "chownFile")); register_file_unlink(isolate, eioNamespace, compatibility_new(isolate, "unlinkFile")); register_file_mkdir(isolate, eioNamespace, compatibility_new(isolate, "mkdirFile")); register_file_move(isolate, eioNamespace, compatibility_new(isolate, "moveFile")); register_file_copy(isolate, eioNamespace, compatibility_new(isolate, "copyFile")); register_dir_move(isolate, eioNamespace, compatibility_new(isolate, "moveDir")); register_dir_copy(isolate, eioNamespace, compatibility_new(isolate, "copyDir")); register_dir_unlink(isolate, eioNamespace, compatibility_new(isolate, "unlinkDir")); } } } } // namespace efl { namespace eio { namespace js {