# ignite-496
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/26989ad5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/26989ad5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/26989ad5 Branch: refs/heads/ignite-496 Commit: 26989ad51f1b063dd9ff50e10c3fb00b1238c2d5 Parents: a46c13c Author: sboikov <semen.boi...@inria.fr> Authored: Thu Mar 19 07:04:47 2015 +0300 Committer: sboikov <semen.boi...@inria.fr> Committed: Thu Mar 19 07:04:47 2015 +0300 ---------------------------------------------------------------------- .../include/ignite_cache.h | 3 + .../src/ignite_cache.cpp | 80 +++++++++++++++++++- .../ignite-nodejs-prototype/src/main.cpp | 2 +- 3 files changed, 80 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/26989ad5/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/include/ignite_cache.h ---------------------------------------------------------------------- diff --git a/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/include/ignite_cache.h b/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/include/ignite_cache.h index 7b8c589..627f6f9 100644 --- a/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/include/ignite_cache.h +++ b/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/include/ignite_cache.h @@ -19,6 +19,7 @@ #define MYOBJECT_H #include <node.h> +#include <uv.h> #include <node_object_wrap.h> #include "ignite-interop-api.h" @@ -35,6 +36,8 @@ private: static void Put(const v8::FunctionCallbackInfo<v8::Value>& args); + static void PutAsync(const v8::FunctionCallbackInfo<v8::Value>& args); + static void ObjectInfo(const v8::FunctionCallbackInfo<v8::Value>& args); static v8::Persistent<v8::Function> constructor; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/26989ad5/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/src/ignite_cache.cpp ---------------------------------------------------------------------- diff --git a/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/src/ignite_cache.cpp b/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/src/ignite_cache.cpp index 04d4820..4b218e2 100644 --- a/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/src/ignite_cache.cpp +++ b/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/src/ignite_cache.cpp @@ -37,12 +37,10 @@ IgniteCache::~IgniteCache() { IgniteInteropNode* igniteNode; void IgniteCache::Init(Handle<Object> exports) { - /* igniteNode = StartNode(); if (!igniteNode) return; - */ Isolate* isolate = Isolate::GetCurrent(); @@ -53,6 +51,7 @@ void IgniteCache::Init(Handle<Object> exports) { // Prototype NODE_SET_PROTOTYPE_METHOD(tpl, "put", Put); + NODE_SET_PROTOTYPE_METHOD(tpl, "putAsync", PutAsync); NODE_SET_PROTOTYPE_METHOD(tpl, "objectInfo", ObjectInfo); constructor.Reset(isolate, tpl->GetFunction()); @@ -69,7 +68,6 @@ void IgniteCache::New(const FunctionCallbackInfo<Value>& args) { IgniteInteropCache* cache = 0; - /* if (!args[0]->IsUndefined()) { Local<String> name = args[0]->ToString(); @@ -84,7 +82,6 @@ void IgniteCache::New(const FunctionCallbackInfo<Value>& args) { if (!cache) return; - */ IgniteCache* obj = new IgniteCache(cache); @@ -132,6 +129,81 @@ void IgniteCache::Put(const FunctionCallbackInfo<Value>& args) { //args.GetReturnValue().Set(Number::New(isolate, obj->value_)); } +struct AsyncData +{ + Persistent<Function> cb; +}; + +void noop(uv_work_t* req) +{ +} + +void AfterExecute(uv_work_t *req) +{ + +} + +void asyncCallback(AsyncData* asyncData) +{ + Isolate* isolate = Isolate::GetCurrent(); + + HandleScope scope(isolate); + + Local<Function> cb = Local<Function>::New(isolate, asyncData->cb); + + asyncData->cb.Reset(); + + delete asyncData; + + const unsigned argc = 1; + + Local<Value> argv[argc] = { String::NewFromUtf8(isolate, "hello world") }; + + cb->Call(isolate->GetCurrentContext()->Global(), argc, argv); + + node::MakeCallback(isolate, + isolate->GetCurrentContext()->Global(), + cb, + argc, + argv); +} + +void IgniteCache::PutAsync(const FunctionCallbackInfo<Value>& args) { + Isolate* isolate = Isolate::GetCurrent(); + HandleScope scope(isolate); + + IgniteCache* cache = ObjectWrap::Unwrap<IgniteCache>(args.Holder()); + + if (args.Length() != 3) { + std::cout << "Three arguments expected.\n"; + + return; + } + + int key = args[0]->Int32Value(); + int val = args[1]->Int32Value(); + + Local<Function> cb = Local<Function>::Cast(args[2]); + + AsyncData* asyncData = new AsyncData(); + + asyncData->cb = Persistent<Function>(isolate, cb); + + std::cout << "Put async key=" << key << ", val=" << val << "\n"; + + InterupOutputStream out(8); + + out.writeInt32(key); + out.writeInt32(val); + + cache->cache->put(out.data(), out.size()); + + uv_queue_work(uv_default_loop(), 0, noop, (uv_after_work_cb)AfterExecute); + + //obj->value_ += 1; + //args.GetReturnValue().Set(Number::New(isolate, obj->value_)); +} + void IgniteCache::ObjectInfo(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/26989ad5/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/src/main.cpp ---------------------------------------------------------------------- diff --git a/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/src/main.cpp b/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/src/main.cpp index d4c9188..b00b3d2 100644 --- a/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/src/main.cpp +++ b/modules/interop/src/main/cpp/ignite-interop/ignite-nodejs-prototype/src/main.cpp @@ -22,7 +22,7 @@ using namespace v8; void InitAll(Handle<Object> exports) { - //TestInit(); + TestInit(); IgniteCache::Init(exports); }