void Grid::EIO_AfterEncode(uv_work_t* req)
{
    NanScope();

    encode_grid_baton_t *closure = static_cast<encode_grid_baton_t *>(req->data);


    if (closure->error) 
    {
        // There is no known ways to throw errors in the processing prior
        // so simply removing the following from coverage
        /* LCOV_EXCL_START */
        Local<Value> argv[1] = { NanError(closure->error_name.c_str()) };
        NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv);
        /* LCOV_EXCL_END */
    } 
    else 
    {

        // convert key order to proper javascript array
        Local<Array> keys_a = NanNew<Array>(closure->key_order.size());
        std::vector<std::string>::iterator it;
        unsigned int i;
        for (it = closure->key_order.begin(), i = 0; it < closure->key_order.end(); ++it, ++i)
        {
            keys_a->Set(i, NanNew((*it).c_str()));
        }

        mapnik::grid const& grid_type = *closure->g->get();
        // gather feature data
        Local<Object> feature_data = NanNew<Object>();
        if (closure->add_features) {
            node_mapnik::write_features<mapnik::grid>(grid_type,
                                                      feature_data,
                                                      closure->key_order);
        }

        // Create the return hash.
        Local<Object> json = NanNew<Object>();
        Local<Array> grid_array = NanNew<Array>(closure->lines.size());
        unsigned array_size = std::ceil(grid_type.width()/static_cast<float>(closure->resolution));
        for (unsigned j=0;j<closure->lines.size();++j)
        {
            node_mapnik::grid_line_type const & line = closure->lines[j];
            grid_array->Set(j, NanNew<String>(line.get(),array_size));
        }
        json->Set(NanNew("grid"), grid_array);
        json->Set(NanNew("keys"), keys_a);
        json->Set(NanNew("data"), feature_data);

        Local<Value> argv[2] = { NanNull(), NanNew(json) };
        NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv);
    }

    closure->g->Unref();
    NanDisposePersistent(closure->cb);
    delete closure;
}
Ejemplo n.º 2
0
/*
   DESCRIPTION
     Callback function of Get Connection method

   PARAMETERS:
     UV queue work block

   NOTES:
     Connection handle is formed and handed over to JS.

*/
void Oracledb::Async_AfterGetConnection (uv_work_t *req)
{
  NanScope();
  connectionBaton *connBaton = (connectionBaton*)req->data;

  v8::TryCatch tc;
  Handle<Value> argv[2];
  if( !(connBaton->error).empty() )
  {
    argv[0] = v8::Exception::Error(NanNew<v8::String>( (connBaton->error).c_str() ));
    argv[1] = NanNull();
  } 
  else
  {
    argv[0] = NanUndefined();
    Local<FunctionTemplate> lft = NanNew(Connection::connectionTemplate_s);
    Handle<Object> connection = lft->GetFunction()-> NewInstance();
    (ObjectWrap::Unwrap<Connection> (connection))->
                                setConnection( connBaton->dpiconn,
                                               connBaton->oracledb );
    argv[1] = connection;
  }
  Local<Function> callback = NanNew(connBaton->cb);
  delete connBaton;
  NanMakeCallback( NanGetCurrentContext()->Global(),
                      callback, 2, argv );
  if(tc.HasCaught())
    node::FatalException(tc);
}
Ejemplo n.º 3
0
void CoreClrFuncInvokeContext::InvokeCallback(void* data)
{
	DBG("CoreClrFuncInvokeContext::InvokeCallback");

	CoreClrFuncInvokeContext* context = (CoreClrFuncInvokeContext*)data;
	v8::Handle<v8::Value> callbackData = NanNull();
	v8::Handle<v8::Value> errors = NanNull();

	if (context->taskState == TaskStatus::Faulted)
	{
		errors = CoreClrFunc::MarshalCLRToV8(context->resultData, context->resultType);
	}

	else
	{
		callbackData = CoreClrFunc::MarshalCLRToV8(context->resultData, context->resultType);
	}

	Handle<Value> argv[] = { errors, callbackData };
	int argc = 2;

	TryCatch tryCatch;
	NanNew<v8::Function>(*(context->callback))->Call(NanGetCurrentContext()->Global(), argc, argv);
	delete context;

	if (tryCatch.HasCaught())
	{
		node::FatalException(tryCatch);
	}
}
Ejemplo n.º 4
0
Handle<Value> TypedArray::New(GDALDataType type, unsigned int length)  {
	NanEscapableScope();

	Handle<Value> val;
	Handle<Function> constructor;
	Local<Object> global = NanGetCurrentContext()->Global();

	const char *name;
	switch(type) {
		case GDT_Byte:    name = "Uint8Array";   break;
		case GDT_Int16:   name = "Int16Array";   break;
		case GDT_UInt16:  name = "Uint16Array";  break;
		case GDT_Int32:   name = "Int32Array";   break;
		case GDT_UInt32:  name = "Uint32Array";  break;
		case GDT_Float32: name = "Float32Array"; break;
		case GDT_Float64: name = "Float64Array"; break;
		default: 
			NanThrowError("Unsupported array type"); 
			return NanEscapeScope(NanUndefined());
	}


	// make ArrayBuffer
	val = global->Get(NanNew("ArrayBuffer"));

	if(val.IsEmpty() || !val->IsFunction()) {
		NanThrowError("Error getting ArrayBuffer constructor");
		return NanEscapeScope(NanUndefined());
	}

	constructor = val.As<Function>();
	Local<Value> size = NanNew<Integer>(length * GDALGetDataTypeSize(type) / 8);
	Local<Value> array_buffer = constructor->NewInstance(1, &size);

	if(array_buffer.IsEmpty() || !array_buffer->IsObject()) {
		NanThrowError("Error allocating ArrayBuffer");
		return NanEscapeScope(NanUndefined());
	}


	// make TypedArray
	val = global->Get(NanNew(name));

	if(val.IsEmpty() || !val->IsFunction()) {
		NanThrowError("Error getting typed array constructor");
		return NanEscapeScope(NanUndefined());
	}

	constructor = val.As<Function>();
	Local<Object> array = constructor->NewInstance(1, &array_buffer);

	if(array.IsEmpty() || !array->IsObject()) {
		NanThrowError("Error creating TypedArray");
		return NanEscapeScope(NanUndefined());
	}

	return NanEscapeScope(array);
}
Ejemplo n.º 5
0
void Grid::EIO_AfterClear(uv_work_t* req)
{
    NanScope();
    clear_grid_baton_t *closure = static_cast<clear_grid_baton_t *>(req->data);
    if (closure->error)
    {
        Local<Value> argv[1] = { NanError(closure->error_name.c_str()) };
        NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv);
    }
    else
    {
        Local<Value> argv[2] = { NanNull() };
        NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv);
    }
    closure->g->Unref();
    NanDisposePersistent(closure->cb);
    delete closure;
}
void Grid::EIO_AfterClear(uv_work_t* req)
{
    NanScope();
    clear_grid_baton_t *closure = static_cast<clear_grid_baton_t *>(req->data);
    if (closure->error)
    {
        // There seems to be no possible way for the exception to be thrown in the previous 
        // process and therefore not possible to have an error here so removing it from code
        // coverage
        /* LCOV_EXCL_START */
        Local<Value> argv[1] = { NanError(closure->error_name.c_str()) };
        NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv);
        /* LCOV_EXCL_END */
    }
    else
    {
        Local<Value> argv[2] = { NanNull(), NanObjectWrapHandle(closure->g) };
        NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv);
    }
    closure->g->Unref();
    NanDisposePersistent(closure->cb);
    delete closure;
}
Ejemplo n.º 7
0
void OracleClient::EIO_AfterConnect(uv_work_t* req, int status) {
  UNI_SCOPE(scope);
  ConnectBaton* baton = static_cast<ConnectBaton*>(req->data);
  baton->client->Unref();

  Handle<Value> argv[2];
  if(baton->error) {
    argv[0] = Exception::Error(NanNew<String>(baton->error->c_str()));
    argv[1] = NanUndefined();
  } else {
    argv[0] = NanUndefined();
    Handle<Object> connection = uni::Deref(Connection::constructorTemplate)->GetFunction()->NewInstance();
    (node::ObjectWrap::Unwrap<Connection>(connection))->setConnection(baton->client->m_environment, baton->connection);
    argv[1] = connection;
  }

  NanMakeCallback(NanGetCurrentContext()->Global(), uni::Deref(baton->callback), 2, argv);

  delete baton;
  delete req;
}
void NodeFileSource::processAdd(const mbgl::Resource& resource) {
    NanScope();

    // Make sure the loop stays alive as long as request is pending.
    if (pending.empty()) {
        queue->ref();
    }

    auto requestHandle = NanNew<v8::Object>(NodeRequest::Create(this, resource));

    v8::Persistent<v8::Object> requestPersistent;
    NanAssignPersistent(requestPersistent, requestHandle);
    pending.emplace(resource, std::move(requestPersistent));

#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION)
    auto requestFunction = v8::Local<v8::Object>::New(v8::Isolate::GetCurrent(), options)->Get(NanNew("request")).As<v8::Function>();
#else
    auto requestFunction = options->Get(NanNew("request")).As<v8::Function>();
#endif

    v8::Local<v8::Value> argv[] = { requestHandle };
    NanMakeCallback(NanGetCurrentContext()->Global(), requestFunction, 1, argv);
}
Ejemplo n.º 9
0
/*
   DESCRIPTION
     Worker Function of CreatePool.

   PARAMETERS:
     UV queue work block

   NOTES:
     Pool handle is created and handed over to JS.
*/
void Oracledb::Async_AfterCreatePool (uv_work_t *req)
{
  NanScope() ;
  connectionBaton *poolBaton = (connectionBaton *)req->data;

  v8::TryCatch tc;
  Handle<Value> argv[2];

  if (!poolBaton->error.empty())
  {
    argv[0] = v8::Exception::Error(NanNew<v8::String>(( poolBaton->error).c_str() ));
    argv[1] = NanUndefined();
  }
  else
  {
    argv[0] = NanUndefined ();
    Handle<Object> njsPool = NanNew(Pool::poolTemplate_s)->
                             GetFunction() ->NewInstance();
    (ObjectWrap::Unwrap<Pool> (njsPool))-> setPool ( poolBaton->dpipool,
                                                     poolBaton->oracledb,
                                                     poolBaton->poolMax,
                                                     poolBaton->poolMin,
                                                     poolBaton->poolIncrement,
                                                     poolBaton->poolTimeout,
                                                     poolBaton->stmtCacheSize,
                                                     poolBaton->lobPrefetchSize);
    argv[1] = njsPool;
  }
  Local<Function> callback = NanNew(poolBaton->cb);
  delete poolBaton;
  NanMakeCallback ( NanGetCurrentContext()->Global(),
                       callback, 2, argv);
  if(tc.HasCaught())
  {
    node::FatalException (tc);
  }
}
void NodeFileSource::processCancel(const mbgl::Resource& resource) {
    NanScope();

    auto it = pending.find(resource);
    if (it == pending.end()) {
        // The response callback was already fired. There is no point in calling the cancelation
        // callback because the request is already completed.
    } else {
#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION)
        auto requestHandle = v8::Local<v8::Object>::New(v8::Isolate::GetCurrent(), it->second);
        it->second.Reset();
#else
        auto requestHandle = NanNew<v8::Object>(it->second);
        NanDisposePersistent(it->second);
#endif
        pending.erase(it);

        // Make sure the the loop can exit when there are no pending requests.
        if (pending.empty()) {
            queue->unref();
        }

#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION)
        auto optionsObject = v8::Local<v8::Object>::New(v8::Isolate::GetCurrent(), options);
        if (optionsObject->Has(NanNew("cancel"))) {
            auto cancelFunction = optionsObject->Get(NanNew("cancel")).As<v8::Function>();
#else
        if (options->Has(NanNew("cancel"))) {
            auto cancelFunction = options->Get(NanNew("cancel")).As<v8::Function>();
#endif
            v8::Local<v8::Value> argv[] = { requestHandle };
            NanMakeCallback(NanGetCurrentContext()->Global(), cancelFunction, 1, argv);
        }

        // Set the request handle in the request wrapper handle to null
        node::ObjectWrap::Unwrap<NodeRequest>(requestHandle)->cancel();
    }
}

void NodeFileSource::notify(const mbgl::Resource& resource, const std::shared_ptr<const mbgl::Response>& response) {
    // First, remove the request, since it might be destructed at any point now.
    auto it = pending.find(resource);
    if (it != pending.end()) {
#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION)
        it->second.Reset();
#else
        NanDisposePersistent(it->second);
#endif
        pending.erase(it);

        // Make sure the the loop can exit when there are no pending requests.
        if (pending.empty()) {
            queue->unref();
        }
    }

    std::lock_guard<std::mutex> lock(observersMutex);

    auto observersIt = observers.find(resource);
    if (observersIt == observers.end()) {
        return;
    }

    observersIt->second->notify(response);
    observers.erase(observersIt);
}