Example #1
0
/* Extract files into directory.
 *
 * Extract an array of files (args[0]) into a directory of choice (args[1]).
 * @param (string) Source directory of CASC archive
 * @param (string) Destination directory to extract files
 * @param (array) Array of files within the CASC archive
 * @return (int) Number of files successfully extracted.
 */
void nodeExtractFiles(const Nan::FunctionCallbackInfo<v8::Value> &args) {
    // Allocate a new scope when we create v8 JavaScript objects.
    v8::Isolate *isolate = args.GetIsolate();
    Nan::HandleScope scope;

    // strSource
    strSource = *v8::String::Utf8Value(args[0]->ToString());
    if ((strSource[strSource.size() - 1] == '/') || (strSource[strSource.size() - 1] == '\\'))
        strSource = strSource.substr(0, strSource.size() - 1);

    // strDestination
    strDestination = *v8::String::Utf8Value(args[1]->ToString());
    if (strDestination.at(strDestination.size() - 1) != '/')
        strDestination += "/";

    // Open CASC archive
    if (!CascOpenStorage(strSource.c_str(), 0, &hStorage)) {
        cerr << "Failed to open the storage '" << strSource << "'" << endl;
        args.GetReturnValue().Set(-1);
        return;
    }

    int filesDone = 0;

    if (args[2]->IsArray()) {
        v8::Handle<v8::Array> files = v8::Handle<v8::Array>::Cast(args[2]);
        for (uint32_t i = 0; i < files->Length(); i++) {
            v8::String::Utf8Value item(files->Get(i)->ToString());
            std::basic_string<char> file = std::string(*item);
            size_t bytesWritten = extractFile(file);
            if (bytesWritten > 0) {
              filesDone++;
            }
        }
    }

    // Clean it up...
    CascCloseStorage(hStorage);
    hStorage = NULL;

    // Ship it out...
    args.GetReturnValue().Set(filesDone);
    return;
}
Example #2
0
void Client::Stop(const Nan::FunctionCallbackInfo<v8::Value>& info) {
	Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());

	CHECK_ARGUMENT_LENGTH(info, 1, "1")
	CHECK_N_ARGS_IS_A_FUNCTION(info, 0, "0")
	Callback* callback = new Callback(info[0].As<v8::Function>());

	memClient->progressWorker->setCallback(callback);
	memClient->isRunning = false;
}
Example #3
0
/* List all files in a CASC archive.
 *
 * @param (string) Source directory of CASC files
 * @return (array) Full paths of files in the archive
 */
void nodeListFiles(const Nan::FunctionCallbackInfo<v8::Value> &args) {
    // Set API variables
    bQuiet = true;
    bVerbose = false;

    // Allocate a new scope when we create v8 JavaScript objects.
    v8::Isolate *isolate = args.GetIsolate();
    Nan::HandleScope scope;

    strSource = *v8::String::Utf8Value(args[0]->ToString());

    if ((strSource[strSource.size() - 1] == '/') || (strSource[strSource.size() - 1] == '\\'))
        strSource = strSource.substr(0, strSource.size() - 1);

    if (!CascOpenStorage(strSource.c_str(), 0, &hStorage)) {
        cerr << "Failed to open the storage '" << strSource << "'" << endl;
        return;
    }

    // Define variables
    CASC_FIND_DATA findData;
    HANDLE handle = CascFindFirstFile(hStorage, "*", &findData, NULL);

    // Let's get this party started..
    vector<string> results = searchArchive();

    // Convert returned vector of *chars to a v8::Array of v8::Strings
    v8::Handle<v8::Array> files = v8::Array::New(isolate);
    for (unsigned int i = 0; i < results.size(); i++ ) {
      v8::Handle<v8::String> result = v8::String::NewFromUtf8(isolate, results[i].c_str());
      files->Set(i, result);
    }

    // Clean it up...
    CascFindClose(handle);
    CascCloseStorage(hStorage);
    handle = NULL;
    hStorage = NULL;

    // Ship it out...
    args.GetReturnValue().Set(files);
    return;
}
void CheckPass(const Nan::FunctionCallbackInfo<v8::Value>& info) {
	Nan::Utf8String recipfile(info[0]->ToString());
	Nan::Utf8String pass(info[1]->ToString());

	//wchar_t* w_recipfile = CharToWchar_New(*recipfile);
	int ret = parse_cert_file(*recipfile, *pass,NULL);
	//delete[] w_recipfile;
	v8::Local<v8::Number> res = Nan::New(ret);
	info.GetReturnValue().Set(res);
}
 void SecureCellContextImprint::decrypt(const Nan::FunctionCallbackInfo<v8::Value>& args) {
   SecureCellContextImprint* obj = Nan::ObjectWrap::Unwrap<SecureCellContextImprint>(args.This());
   size_t length=0;
   const uint8_t* context=(const uint8_t*)(node::Buffer::Data(args[1]));
   size_t context_length=node::Buffer::Length(args[1]);
   if(themis_secure_cell_decrypt_context_imprint(&(obj->key_)[0], obj->key_.size(), (const uint8_t*)(node::Buffer::Data(args[0])), node::Buffer::Length(args[0]), context, context_length, NULL, &length)!=THEMIS_BUFFER_TOO_SMALL){
     Nan::ThrowError("Secure Cell (Context Imprint) failed  decrypting");
     args.GetReturnValue().SetUndefined();
     return;
   }
   uint8_t* data=(uint8_t*)(malloc(length));
   if(themis_secure_cell_decrypt_context_imprint(&(obj->key_)[0], obj->key_.size(), (const uint8_t*)(node::Buffer::Data(args[0])), node::Buffer::Length(args[0]), context, context_length, data, &length)!=THEMIS_SUCCESS){
     Nan::ThrowError("Secure Cell (Context Imprint) failed  decrypting");
     free(data);
     args.GetReturnValue().SetUndefined();
     return;
   }
   args.GetReturnValue().Set(Nan::NewBuffer((char*)(data), length).ToLocalChecked());
 }
/**
  *  Inverse:
  *  Compute the (multiplicative) inverse of a matrix.
  *   Given a square matrix a, return the matrix ainv satisfying dot(a, ainv) = dot(ainv, a)
  *
  *  arguments:
  *  info[0]: Buffer(object created by smalloc) represent the numjs.Matrix object to be inverted.
  *           Must be square, i.e. M.rows == M.cols.
  *  info[1]: Number represent the number of rows of the matrix.
  *  info[2]: Number represent the number of columns of the matrix.
  *  info[3]: Buffer(object created by smalloc) for return value, inverse of the given matrix.
*/
void Inverse(const Nan::FunctionCallbackInfo<v8::Value>& info){
    using CMd = Eigen::Map <const Eigen::MatrixXd >;
    using Md = Eigen::Map <Eigen::MatrixXd >;

    if (info.Length() < 4) {
        Nan::ThrowTypeError("Wrong number of arguments");
        return;
    }

    if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
        Nan::ThrowTypeError("Wrong arguments");
        return;
    }

    Local<Object> matrixBuffer = info[0].As<Object>();
    if (matrixBuffer->HasIndexedPropertiesInExternalArrayData()) {
        double *refMatrixData = static_cast<double*>(matrixBuffer->GetIndexedPropertiesExternalArrayData());
        size_t rowsMatrix(info[1]->Uint32Value());
        size_t colsMatrix(info[2]->Uint32Value());

        Md inputMat(refMatrixData, rowsMatrix, colsMatrix);

        Local<Object> resBuffer = info[4].As<Object>();
        if (resBuffer->HasIndexedPropertiesInExternalArrayData()) {
            double *refResData = static_cast<double*>(resBuffer->GetIndexedPropertiesExternalArrayData());
            Md res(refResData, rowsMatrix, colsMatrix);
            res = inputMat.inverse();
            Local<Boolean> b = Nan::New(true);
            info.GetReturnValue().Set(b);
        }
        else{
            Nan::ThrowTypeError("Wrong arguments2");
            Local<Boolean> b = Nan::New(false);
            info.GetReturnValue().Set(b);
        }
    }
    else{
        Nan::ThrowTypeError("Wrong arguments3");
        Local<Boolean> b = Nan::New(false);
        info.GetReturnValue().Set(b);
    }
}
Example #7
0
//#include <string>
void sayHello(const Nan::FunctionCallbackInfo<v8::Value>& info){
//    v8::Local<v8::String> str=info.Data().Cast<v8::String>(info.Data());
    Nan::Utf8String str(info[0]);
//    std::cout<<*str<<std::endl;
//    char* helloStr="hello ";
    std::string hello=std::string("hello ")+std::string(*str);
//    v8::Local<v8::String> helloStr=
//            v8::String::NewFromUtf8(Nan::GetCurrentContext()->GetIsolate(),hello.c_str());
    v8::Local<v8::String> helloStr=Nan::New<v8::String>("hello ").ToLocalChecked();
    info.GetReturnValue().Set(helloStr);
}
Example #8
0
void Client::Replace(const Nan::FunctionCallbackInfo<v8::Value>& info) {
	Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());

	CHECK_ARGUMENT_LENGTH(info, 4, "4")
	CHECK_N_ARGS_IS_A_STRING(info, 0, "0")
	CHECK_N_ARGS_IS_A_STRING(info, 1, "1")
	CHECK_N_ARGS_IS_A_NUMBER(info, 2, "2")
	CHECK_N_ARGS_IS_A_FUNCTION(info, 3, "3")

	const string memcached_key = GET_STRING_FROM_PARAM(info[0]);
	const string memcached_value = GET_STRING_FROM_PARAM(info[1]);
	time_t ttl = (time_t) GET_NUMBER_FROM_PARAM(info[2]);
	Callback* callback = GET_CALLBACK_FROM_PARAM(info[3]);

	JobBase* job = new ReplaceJob(callback, memcached_key, memcached_value, ttl);
	job->setDebug(memClient->debug);
	memClient->jobs.insert(job);

	info.GetReturnValue().Set(Nan::Undefined());
}
Example #9
0
void RegisterRemoved(const Nan::FunctionCallbackInfo<v8::Value>& args) {
	Nan::HandleScope scope;

	v8::Local<v8::Function> callback;

	if (args.Length() == 0) {
		return Nan::ThrowTypeError("First argument must be a function");
	}

	if (args.Length() == 1) {
		// callback
		if(!args[0]->IsFunction()) {
			return Nan::ThrowTypeError("First argument must be a function");
		}

		callback = args[0].As<v8::Function>();
	}

	removedCallback = new Nan::Callback(callback);
	isRemovedRegistered = true;
}
Example #10
0
void GetClipDatabase(const Nan::FunctionCallbackInfo<v8::Value>& info) {
  if ((info.Length() < 1) || (info.Length() > 1)) {
    Nan::ThrowTypeError("Wrong number of arguments");
    return;
  }

  if (!info[0]->IsNumber()) {
    Nan::ThrowTypeError("Wrong arguments");
    return;
  }

  int sizeOfData = 0;
  char* clipDatabase = GetClipDatabase(sizeOfData);

  v8::Local<v8::String> v8ClipDatabase = v8::String::New(clipDatabase, sizeOfData);
  v8::Local<v8::Object> obj = Nan::New<v8::Object>();
  obj->Set(Nan::New("msg").ToLocalChecked(), v8ClipDatabase);
  info.GetReturnValue().Set(obj);

  FreeClipDatabase(clipDatabase);
}
/**
  *  Inverse:
  *  Compute the (multiplicative) inverse of a matrix.
  *  Given a square matrix a, return the matrix ainv satisfying dot(a, ainv) = dot(ainv, a)
  *
  *  arguments:
  *  info[0]: Buffer(object created by Float64Array) represent the numjs.Matrix object to be inverted.
  *           Must be square, i.e. M.rows == M.cols.
  *  info[1]: Number represent the number of rows of the matrix.
  *  info[2]: Number represent the number of columns of the matrix.
  *  info[3]: Buffer(object created by Float64Array) for return value, inverse of the given matrix.
*/
void Inverse(const Nan::FunctionCallbackInfo<v8::Value>& info){
    using CMd = Eigen::Map <const Eigen::MatrixXd >;
    using Md = Eigen::Map <Eigen::MatrixXd >;

    if (info.Length() < 4) {
        Nan::ThrowTypeError("Wrong number of arguments");
        return;
    }

    if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
        Nan::ThrowTypeError("Wrong arguments");
        return;
    }

	if (info[0]->IsFloat64Array()) {
		double *refMatrixData = *(Nan::TypedArrayContents<double>(info[0]));
        size_t rowsMatrix(info[1]->Uint32Value());
        size_t colsMatrix(info[2]->Uint32Value());

        Md inputMat(refMatrixData, rowsMatrix, colsMatrix);

		if (info[3]->IsFloat64Array()) {
			double *refResData = *(Nan::TypedArrayContents<double>(info[3]));
            Md res(refResData, rowsMatrix, colsMatrix);
            res = inputMat.inverse();
            Local<Boolean> b = Nan::New(true);
            info.GetReturnValue().Set(b);
        }
        else{
            Nan::ThrowTypeError("Wrong arguments (4th arg)");
            Local<Boolean> b = Nan::New(false);
            info.GetReturnValue().Set(b);
        }
    }
    else{
        Nan::ThrowTypeError("Wrong arguments (1st arg)");
        Local<Boolean> b = Nan::New(false);
        info.GetReturnValue().Set(b);
    }
}
Example #12
0
void MeCab_Tagger::Parse(const Nan::FunctionCallbackInfo<v8::Value>& info) {
  MeCab_Tagger* mecabTagger = ObjectWrap::Unwrap<MeCab_Tagger>(info.Holder());
  v8::String::Utf8Value input(info[0]);
  v8::Local<v8::Function> callback = info[1].As<v8::Function>();

  const char *result = mecabTagger->tagger->parse(*input);

  const unsigned argc = 2;
  v8::Local<v8::Value> argv[] = {
    Nan::Null(),
    Nan::New(result).ToLocalChecked()
  };
  Nan::MakeCallback(Nan::GetCurrentContext()->Global(), callback, argc, argv);
}
/**
  *  Tri:
  *  Creates a new nXm matrix with ones at and below the matrix diagonal
  *  and zeros elsewhere.
  *
  *  arguments:
  *  info[0]: Number n which represents the number of rows in the newly built matrix
  *  info[1]: Number m which represents the number of cols in the newly built matrix
  *  info[2]: Buffer(object created by Float64Array) for return value(eye matrix nXm).
*/
void Tri(const Nan::FunctionCallbackInfo<v8::Value>& info){
    using CMd = Eigen::Map <const Eigen::MatrixXd >;
    using Md = Eigen::Map <Eigen::MatrixXd >;

    if (info.Length() < 3) {
        Nan::ThrowTypeError("Wrong number of arguments");
        return;
    }

    if (!info[0]->IsNumber() || !info[1]->IsNumber()) {
        Nan::ThrowTypeError("Wrong argument given, should be a number");
        return;
    }

    if (info[2]->IsFloat64Array()) {
        size_t rowsMatrix(info[0]->Uint32Value());
        size_t colsMatrix(info[1]->Uint32Value());

        double *refResData = *(Nan::TypedArrayContents<double>(info[2]));
        Md res(refResData, rowsMatrix, colsMatrix);
        res = Md::Ones(rowsMatrix, colsMatrix);
        for (int i = 0; i < rowsMatrix; i++) {
            for (int j = i + 1; j < colsMatrix; j++) {
                res(i, j) = 0;
            }
        }

        Local<Boolean> b = Nan::New(true);
        info.GetReturnValue().Set(b);
    }

    else{
        Nan::ThrowTypeError("Wrong arguments2");
        Local<Boolean> b = Nan::New(false);
        info.GetReturnValue().Set(b);
    }
}
Example #14
0
  void getTelemetryDescription(const Nan::FunctionCallbackInfo<v8::Value>& args)
  {
    Local<Object> obj = Nan::New<Object>();
    std::vector<irsdk_varHeader*> headers = irsdk.getVarHeaders();

    for (const auto item : headers)
    {
      IRSDKWrapper::TelemetryVar var(item);
      irsdk.getVarVal(var);
      Handle<Object> varObj = Nan::New<Object>();
      convertVarHeaderToObject(var, varObj);
      Nan::Set(obj, Nan::New(var.header->name).ToLocalChecked(), varObj);
    }
    args.GetReturnValue().Set(obj);
  }
Example #15
0
void Client::MGetAndFetchAll(const Nan::FunctionCallbackInfo<v8::Value>& info) {
	Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());

	CHECK_ARGUMENT_LENGTH(info, 2, "2")
	CHECK_N_ARGS_IS_AN_ARRAY(info, 0, "0")
	CHECK_N_ARGS_IS_A_FUNCTION(info, 1, "1")

	v8::Local<v8::Object> arr = info[0]->ToObject();
	size_t number_of_keys = arr->GetOwnPropertyNames()->Length();
	memClient->debug && printf("%s %lu %s\n", "Array with", number_of_keys, "keys");

	std::vector<string> keys;
	for(size_t i = 0; i < number_of_keys; i++) {
		keys.push_back(GET_STRING_FROM_PARAM(arr->Get(i)));
	}

	Callback* callback = GET_CALLBACK_FROM_PARAM(info[1]);

	JobBase* job = new MGetAndFetchAllJob(callback, keys);
	job->setDebug(memClient->debug);
	memClient->jobs.insert(job);

	info.GetReturnValue().Set(Nan::Undefined());
}
Example #16
0
  void getTelemetry(const Nan::FunctionCallbackInfo<v8::Value>& args)
  {
    Local<Object> rootObj = Nan::New<v8::Object>();
    Local<Object> valuesObj = Nan::New<v8::Object>();
    Nan::Set(rootObj, Nan::New("timestamp").ToLocalChecked(), Nan::New<Date>(irsdk.getLastTelemetryUpdateTS()).ToLocalChecked());

    std::vector<irsdk_varHeader*> headers = irsdk.getVarHeaders();

    for (const auto item : headers)
    {
      IRSDKWrapper::TelemetryVar var(item);
      irsdk.getVarVal(var);
      Handle<Value> varValue = convertTelemetryVarToObject(var);
      Nan::Set(valuesObj, Nan::New(var.header->name).ToLocalChecked(), varValue);
    }
    Nan::Set(rootObj, Nan::New("values").ToLocalChecked(), valuesObj);
    args.GetReturnValue().Set(rootObj);
  }
Example #17
0
void MeCab_Tagger::ParseToNode(const Nan::FunctionCallbackInfo<v8::Value>& info) {
  MeCab_Tagger* mecabTagger = ObjectWrap::Unwrap<MeCab_Tagger>(info.Holder());
  v8::String::Utf8Value input(info[0]);
  v8::Local<v8::Function> callback = info[1].As<v8::Function>();
  std::vector<v8::Local<v8::Object>> node_list;
  const MeCab::Node* node = mecabTagger->tagger->parseToNode(*input);

  for (; node; node = node->next) {
    v8::Local<v8::Object> obj = Nan::New<v8::Object>();
    obj->Set(Nan::New("word").ToLocalChecked(), Nan::New(std::string(node->surface, node->length)).ToLocalChecked());
    obj->Set(Nan::New("id").ToLocalChecked(), Nan::New(node->id));
    obj->Set(Nan::New("surface").ToLocalChecked(), Nan::New(node->surface).ToLocalChecked());
    obj->Set(Nan::New("feature").ToLocalChecked(), Nan::New(node->feature).ToLocalChecked());
    obj->Set(Nan::New("len").ToLocalChecked(), Nan::New(node->length));
    obj->Set(Nan::New("rcAttr").ToLocalChecked(), Nan::New(node->rcAttr));
    obj->Set(Nan::New("lcAttr").ToLocalChecked(), Nan::New(node->lcAttr));
    obj->Set(Nan::New("posid").ToLocalChecked(), Nan::New(node->posid));
    obj->Set(Nan::New("char_type").ToLocalChecked(), Nan::New(node->char_type));
    obj->Set(Nan::New("stat").ToLocalChecked(), Nan::New(node->stat));
    obj->Set(Nan::New("isbest").ToLocalChecked(), Nan::New(node->isbest));
    obj->Set(Nan::New("alpha").ToLocalChecked(), Nan::New(node->alpha));
    obj->Set(Nan::New("beta").ToLocalChecked(), Nan::New(node->beta));
    obj->Set(Nan::New("prob").ToLocalChecked(), Nan::New(node->prob));
    obj->Set(Nan::New("cost").ToLocalChecked(), Nan::New((int)node->cost));
    node_list.push_back(obj);
  }

  v8::Local<v8::Array> results = Nan::New<v8::Array>(node_list.size());
  for(unsigned int i = 0; i < results->Length(); ++i) {
    results->Set(i, node_list.at(i));
  }

  const unsigned argc = 2;
  v8::Local<v8::Value> argv[] = {
    Nan::Null(),
    results
  };
  Nan::MakeCallback(Nan::GetCurrentContext()->Global(), callback, argc, argv);
}
Example #18
0
void SecureCellSeal::encrypt(const Nan::FunctionCallbackInfo<v8::Value>& args)
{
    themis_status_t status = THEMIS_FAIL;
    SecureCellSeal* obj = Nan::ObjectWrap::Unwrap<SecureCellSeal>(args.This());
    if (args.Length() < 1) {
        ThrowParameterError("Secure Cell (Seal) failed to encrypt",
                            "not enough arguments, expected message");
        args.GetReturnValue().SetUndefined();
        return;
    }
    if (!args[0]->IsUint8Array()) {
        ThrowParameterError("Secure Cell (Seal) failed to encrypt",
                            "message is not a byte buffer, use ByteBuffer or Uint8Array");
        args.GetReturnValue().SetUndefined();
        return;
    }
    if (node::Buffer::Length(args[0]) == 0) {
        ThrowParameterError("Secure Cell (Seal) failed to encrypt", "message is empty");
        args.GetReturnValue().SetUndefined();
        return;
    }
    size_t length = 0;
    const uint8_t* context = NULL;
    size_t context_length = 0;
    if (args.Length() == 2) {
        if (!args[1]->IsUint8Array()) {
            ThrowParameterError("Secure Cell (Seal) failed to encrypt",
                                "context is not a byte buffer, use ByteBuffer or Uint8Array");
            args.GetReturnValue().SetUndefined();
            return;
        }
        context = (const uint8_t*)(node::Buffer::Data(args[1]));
        context_length = node::Buffer::Length(args[1]);
    }
    status = themis_secure_cell_encrypt_seal(&(obj->key_)[0],
                                             obj->key_.size(),
                                             context,
                                             context_length,
                                             (const uint8_t*)(node::Buffer::Data(args[0])),
                                             node::Buffer::Length(args[0]),
                                             NULL,
                                             &length);
    if (status != THEMIS_BUFFER_TOO_SMALL) {
        ThrowError("Secure Cell (Seal) failed to encrypt", status);
        args.GetReturnValue().SetUndefined();
        return;
    }
    uint8_t* data = (uint8_t*)(malloc(length));
    status = themis_secure_cell_encrypt_seal(&(obj->key_)[0],
                                             obj->key_.size(),
                                             context,
                                             context_length,
                                             (const uint8_t*)(node::Buffer::Data(args[0])),
                                             node::Buffer::Length(args[0]),
                                             data,
                                             &length);
    if (status != THEMIS_SUCCESS) {
        ThrowError("Secure Cell (Seal) failed to encrypt", status);
        free(data);
        args.GetReturnValue().SetUndefined();
        return;
    }
    args.GetReturnValue().Set(Nan::NewBuffer((char*)(data), length).ToLocalChecked());
}
Example #19
0
 void updateTelemetry(const Nan::FunctionCallbackInfo<v8::Value>& args)
 {
   args.GetReturnValue().Set(Nan::New(irsdk.updateTelemetry()));
 }
Example #20
0
 void getSessionInfo(const Nan::FunctionCallbackInfo<v8::Value>& args)
 {
   args.GetReturnValue().Set(
     Nan::Encode(irsdk.getSessionInfo().c_str(), irsdk.getSessionInfo().length(), Nan::BINARY));
 }
Example #21
0
void Client::Start(const Nan::FunctionCallbackInfo<v8::Value>& info) {
	Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
	memClient->isRunning = true;
	memClient->progressWorker = new MemcachedAsyncProgressWorker(memClient, new Callback());
	Nan::AsyncQueueWorker(memClient->progressWorker);
}
Example #22
0
 void start(const Nan::FunctionCallbackInfo<v8::Value>& args)
 {
   args.GetReturnValue().Set(Nan::New(irsdk.startup()));
 }
/**
  *  SVD:
  *  Singular Value Decomposition.
  *  Factors the matrix a as u * np.diag(s) * v, where u and v are unitary and s is a 1-d array of a‘s singular values.
  *
  *  arguments:
  *  info[0]: Buffer(object created by Float64Array) represent the numjs.Matrix object to be inverted.
  *           Must be square, i.e. M.rows == M.cols.
  *  info[1]: Number represent the number of rows of the matrix.
  *  info[2]: Number represent the number of columns of the matrix.
  *  info[3]: full_matrices(bool, optional): If True (default), u and v have the shapes (M, M) and (N, N), respectively.
  *           Otherwise, the shapes are (M, K) and (K, N), respectively, where K = min(M, N).
  *  info[4]: compute_uv (bool, optional): Whether or not to compute u and v in addition to s. True by default.
  *  info[5]: outU - Unitary matrices. The actual shape depends on the value of full_matrices.
  *                  Only returned when compute_uv is True.
  *  info[6]: outS - The singular values for every matrix, sorted in descending order.
  *  info[7]: outV - Unitary matrices. The actual shape depends on the value of full_matrices.
  *                  Only returned when compute_uv is True.
*/
void SVD(const Nan::FunctionCallbackInfo<v8::Value>& info){
    using CMd = Eigen::Map <const Eigen::MatrixXd >;
    using Md = Eigen::Map <Eigen::MatrixXd >;

    if (info.Length() < 8) {
        Nan::ThrowTypeError("Wrong number of arguments");
        return;
    }

    if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
        Nan::ThrowTypeError("Wrong arguments");
        return;
    }

	if (info[0]->IsFloat64Array()) {
		double *refMatrixData = *(Nan::TypedArrayContents<double>(info[0]));
        int rowsMatrix(info[1]->Uint32Value());
        int colsMatrix(info[2]->Uint32Value());

        Md inputMat(refMatrixData, rowsMatrix, colsMatrix);

        bool isFullMatrices = info[3]->BooleanValue();
        bool isComputeUV = info[4]->BooleanValue();
        int k = min(rowsMatrix,colsMatrix);

        if(isComputeUV){
            if (info[5]->IsFloat64Array() && info[6]->IsFloat64Array() && info[7]->IsFloat64Array()) {

                double *refResU = *(Nan::TypedArrayContents<double>(info[5]));
                double *refResS = *(Nan::TypedArrayContents<double>(info[6]));
                double *refResV = *(Nan::TypedArrayContents<double>(info[7]));

                if(isFullMatrices){
                    Eigen::JacobiSVD<Eigen::MatrixXd> svd(inputMat, Eigen::ComputeFullU | Eigen::ComputeFullV);

                    Md resU(refResU, rowsMatrix, rowsMatrix);
                    Md resV(refResV, colsMatrix, colsMatrix);

                    resU = svd.matrixU();
                    resV = svd.matrixV();

                    std::memcpy(refResS, svd.singularValues().data(), k * sizeof(double));

                    Local<Boolean> b = Nan::New(true);
                    info.GetReturnValue().Set(b);
                }
                else{
                    Eigen::JacobiSVD<Eigen::MatrixXd> svd(inputMat, Eigen::ComputeThinU | Eigen::ComputeThinV);

                    Md resU(refResU, rowsMatrix, k);
                    Md resV(refResV, k, colsMatrix);

                    resU = svd.matrixU();
                    resV = svd.matrixV();

                    std::memcpy(refResS, svd.singularValues().data(), k * sizeof(double));

                    Local<Boolean> b = Nan::New(true);
                    info.GetReturnValue().Set(b);
                }
            }
        }
        else{
            if(info[6]->IsFloat64Array()){
                double *refResS = *(Nan::TypedArrayContents<double>(info[6]));
                Eigen::JacobiSVD<Eigen::MatrixXd> svd(inputMat);
                std::memcpy(refResS, svd.singularValues().data(), k * sizeof(double));

                Local<Boolean> b = Nan::New(true);
                info.GetReturnValue().Set(b);
            }
        }
    }
    else{
        Nan::ThrowTypeError("Wrong arguments");
        Local<Boolean> b = Nan::New(false);
        info.GetReturnValue().Set(b);
    }
}
void MyFunction(const Nan::FunctionCallbackInfo<v8::Value>& info) {
    info.GetReturnValue().Set(Nan::New("my function").ToLocalChecked());
}
void CreateObject(const Nan::FunctionCallbackInfo<v8::Value>& info) {
    v8::Local<v8::Object> obj = Nan::New<v8::Object>();
    obj->Set(Nan::New("msg").ToLocalChecked(), info[0]->ToString());

    info.GetReturnValue().Set(obj);
}
void Hello(const Nan::FunctionCallbackInfo<v8::Value>& info) {
    info.GetReturnValue().Set(Nan::New("world").ToLocalChecked());
}
/**
  *  Dot:
  *  Dot product of two arrays.
  *  For 2-D arrays it is equivalent to matrix multiplication, and for 1-D arrays to inner product of vectors
  * (without complex conjugation).
  *
  *  arguments:
  *  info[0]: Number represent the number of rows of the left matrix.
  *  info[1]: Number represent the number of columns of the left matrix.
  *  info[2]: Buffer(object created by smalloc) represent the left numjs.Matrix object .
  *  info[3]: Number represent the number of rows of the right matrix.
  *  info[4]: Number represent the number of columns of the right matrix.
  *  info[5]: Buffer(object created by smalloc) represent the right numjs.Matrix object .
  *  info[6]: Buffer(object created by smalloc) for return value, which is the dot product of
  *           left matrix and right matrix.
*/
void Dot(const Nan::FunctionCallbackInfo<v8::Value>& info){
    using CMd = Eigen::Map <const Eigen::MatrixXd >;
    using Md = Eigen::Map <Eigen::MatrixXd >;

	if (info.Length() < 7) {
		Nan::ThrowTypeError("Wrong number of arguments");
		return;
	}

    if (!info[0]->IsUint32() || !info[1]->IsUint32() ||
    	!info[3]->IsUint32() || !info[4]->IsUint32()) {
    	Nan::ThrowTypeError("Wrong arguments");
        return;
    }

	if (info[2]->IsNumber()) {
	    double leftParam(info[2]->NumberValue());

	    if(!info[5]->IsNumber()){
            Local<Object> rightBuffer = info[5].As<Object>();

            if (rightBuffer->HasIndexedPropertiesInExternalArrayData()) {
                double *refRightData = static_cast<double*>(rightBuffer->GetIndexedPropertiesExternalArrayData());
                size_t rowsRight(info[3]->Uint32Value());
                size_t colsRight(info[4]->Uint32Value());
                CMd rightMat(refRightData, rowsRight, colsRight);

                Local<Object> resBuffer = info[6].As<Object>();
                if (resBuffer->HasIndexedPropertiesInExternalArrayData()) {
                    double *refResData = static_cast<double*>(resBuffer->GetIndexedPropertiesExternalArrayData());
                    Md res(refResData, rowsRight, colsRight);
                    res = leftParam * rightMat;

                    Local<Boolean> b = Nan::New(true);
                    info.GetReturnValue().Set(b);
                }
            }
        }
    }
	else{
	    Local<Object> leftBuffer = info[2].As<Object>();
	    if (leftBuffer->HasIndexedPropertiesInExternalArrayData()) {
	        double *refLeftData = static_cast<double*>(leftBuffer->GetIndexedPropertiesExternalArrayData());
	        size_t rowsLeft(info[0]->Uint32Value());
            size_t colsLeft(info[1]->Uint32Value());
            CMd leftMat(refLeftData, rowsLeft, colsLeft);

            if(info[5]->IsNumber()){
                double rightParam(info[5]->NumberValue());
                Local<Object> resBuffer = info[6].As<Object>();
                if (resBuffer->HasIndexedPropertiesInExternalArrayData()) {
                    double *refResData = static_cast<double*>(resBuffer->GetIndexedPropertiesExternalArrayData());
                    Md res(refResData, rowsLeft, colsLeft);
                    res = leftMat * rightParam;
                    Local<Boolean> b = Nan::New(true);
                    info.GetReturnValue().Set(b);
                }
            }
            else{
                Local<Object> rightBuffer = info[5].As<Object>();
                if (rightBuffer->HasIndexedPropertiesInExternalArrayData()) {
                    double *refRightData = static_cast<double*>(rightBuffer->GetIndexedPropertiesExternalArrayData());
                	size_t rowsRight(info[3]->Uint32Value());
                    size_t colsRight(info[4]->Uint32Value());
                    CMd rightMat(refRightData, rowsRight, colsRight);

                    Local<Object> resBuffer = info[6].As<Object>();
                    if (resBuffer->HasIndexedPropertiesInExternalArrayData()) {
                        double *refResData = static_cast<double*>(resBuffer->GetIndexedPropertiesExternalArrayData());
                        Md res(refResData, rowsLeft, colsRight);
                         res = leftMat * rightMat;
                        Local<Boolean> b = Nan::New(true);
                        info.GetReturnValue().Set(b);
                    }
                }
            }
	    }
	    else{
	        Nan::ThrowTypeError("Wrong type of the first argument");
            return;
	    }

	    Local<Boolean> b = Nan::New(false);
        info.GetReturnValue().Set(b);
	}
}
Example #28
0
 void shutdown(const Nan::FunctionCallbackInfo<v8::Value>& args)
 {
   irsdk.shutdown();
   args.GetReturnValue().Set(Nan::Undefined());
 }
Example #29
0
void squashfs(const Nan::FunctionCallbackInfo<v8::Value>& info) {
  info.GetReturnValue().Set(Nan::New("Not implemented yet").ToLocalChecked());
}
Example #30
0
 void isConnected(const Nan::FunctionCallbackInfo<v8::Value>& args)
 {
   args.GetReturnValue().Set(Nan::New(irsdk.isConnected()));
 }