/* Copyright (C) 2016 -2017 Jerry Jin */ #include #include #include "browniangenerators.hpp" #include #include #include #include #include #include #include "../loop.hpp" void MTBrownianGeneratorFactoryWorker::Execute(){ try{ // Construct the Value Object boost::shared_ptr valueObject( new QuantLibAddin::ValueObjects::qlMTBrownianGeneratorFactory( mObjectID, mSeed, false )); // Construct the Object boost::shared_ptr object( new QuantLibAddin::MTBrownianGeneratorFactory( valueObject, mSeed, false )); // Store the Object in the Repository mReturnValue = ObjectHandler::Repository::instance().storeObject(mObjectID, object, false, valueObject); }catch(const std::exception &e){ mError = e.what(); }catch (...){ mError = "unkown error"; } } void MTBrownianGeneratorFactoryWorker::HandleOKCallback(){ Nan::HandleScope scope; Local argv[2] = { Nan::New(mError).ToLocalChecked(), Nan::New(mReturnValue).ToLocalChecked() }; callback->Call(2, argv); } NAN_METHOD(QuantLibNode::MTBrownianGeneratorFactory) { // validate js arguments if (info.Length() == 0 || !info[0]->IsString()) { return Nan::ThrowError("ObjectID is required."); } if (info.Length() == 1 || !info[1]->IsNumber()) { return Nan::ThrowError("Seed is required."); } // convert js argument to c++ type String::Utf8Value strObjectID(info[0]->ToString()); string ObjectIDCpp(strdup(*strObjectID)); // convert js argument to c++ type long SeedCpp = Nan::To(info[1]).FromJust(); // declare callback Nan::Callback *callback = new Nan::Callback(info[2].As()); // launch Async worker Nan::AsyncQueueWorker(new MTBrownianGeneratorFactoryWorker( callback ,ObjectIDCpp ,SeedCpp )); } //MTBrownianGeneratorFactoryWorker::~MTBrownianGeneratorFactoryWorker(){ // //} //void MTBrownianGeneratorFactoryWorker::Destroy(){ // //}