diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 94c25502..1195d25b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,11 +5,11 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 strategy: matrix: - node-version: [8.x, 10.x] + node-version: [10.x, 12.x, 14.x] steps: - uses: actions/checkout@v2 @@ -17,8 +17,10 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} + - run: sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' + - run: wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add - - run: sudo apt update - - run: sudo apt install -y libjansson-dev libboost-dev imagemagick libtinyxml-dev git cmake build-essential wget libgazebo7-dev + - run: sudo apt install -y libjansson-dev libboost-dev imagemagick libtinyxml-dev git cmake build-essential wget libgazebo11-dev - run: sudo npm install -g grunt # - run: sudo bash -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/chrome.list' # - run: sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index f6cdad0d..db1b853f 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -15,7 +15,7 @@ * */ -#include +#include #include "GZNode.hh" #include "GazeboInterface.hh" @@ -47,120 +47,118 @@ GZNode::~GZNode() }; ///////////////////////////////////////////////// -void GZNode::Init(Handle exports) +NAN_MODULE_INIT(GZNode::Init) { - Isolate* isolate = exports->GetIsolate(); // Prepare constructor template - Local tpl = FunctionTemplate::New(isolate, New); - tpl->SetClassName(String::NewFromUtf8(isolate, "GZNode")); + Local class_name = Nan::New("GZNode").ToLocalChecked(); + + Local tpl = Nan::New(GZNode::New); + + tpl->SetClassName(class_name); tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype - NODE_SET_PROTOTYPE_METHOD(tpl, "loadMaterialScripts", LoadMaterialScripts); + Nan::SetPrototypeMethod(tpl, "loadMaterialScripts", LoadMaterialScripts); - NODE_SET_PROTOTYPE_METHOD(tpl, "setConnected", SetConnected); + Nan::SetPrototypeMethod(tpl, "setConnected", SetConnected); - NODE_SET_PROTOTYPE_METHOD(tpl, "setPoseMsgFilterMinimumDistanceSquared", SetPoseMsgFilterMinimumDistanceSquared); - NODE_SET_PROTOTYPE_METHOD(tpl, "getPoseMsgFilterMinimumDistanceSquared", GetPoseMsgFilterMinimumDistanceSquared); - NODE_SET_PROTOTYPE_METHOD(tpl, "setPoseMsgFilterMinimumQuaternionSquared", SetPoseMsgFilterMinimumQuaternionSquared); - NODE_SET_PROTOTYPE_METHOD(tpl, "getPoseMsgFilterMinimumQuaternionSquared", GetPoseMsgFilterMinimumQuaternionSquared); + Nan::SetPrototypeMethod(tpl, "setPoseMsgFilterMinimumDistanceSquared", SetPoseMsgFilterMinimumDistanceSquared); + Nan::SetPrototypeMethod(tpl, "getPoseMsgFilterMinimumDistanceSquared", GetPoseMsgFilterMinimumDistanceSquared); + Nan::SetPrototypeMethod(tpl, "setPoseMsgFilterMinimumQuaternionSquared", SetPoseMsgFilterMinimumQuaternionSquared); + Nan::SetPrototypeMethod(tpl, "getPoseMsgFilterMinimumQuaternionSquared", GetPoseMsgFilterMinimumQuaternionSquared); - NODE_SET_PROTOTYPE_METHOD(tpl, "getPoseMsgFilterMinimumAge", + Nan::SetPrototypeMethod(tpl, "getPoseMsgFilterMinimumAge", GetPoseMsgFilterMinimumAge); - NODE_SET_PROTOTYPE_METHOD(tpl, "setPoseMsgFilterMinimumAge", + Nan::SetPrototypeMethod(tpl, "setPoseMsgFilterMinimumAge", SetPoseMsgFilterMinimumAge); - NODE_SET_PROTOTYPE_METHOD(tpl, "getMessages", GetMessages); + Nan::SetPrototypeMethod(tpl, "getMessages", GetMessages); - NODE_SET_PROTOTYPE_METHOD(tpl, "request", Request); + Nan::SetPrototypeMethod(tpl, "request", Request); - NODE_SET_PROTOTYPE_METHOD(tpl, "getIsGzServerConnected", + Nan::SetPrototypeMethod(tpl, "getIsGzServerConnected", GetIsGzServerConnected); - NODE_SET_PROTOTYPE_METHOD(tpl, "getMaterialScriptsMessage", + Nan::SetPrototypeMethod(tpl, "getMaterialScriptsMessage", GetMaterialScriptsMessage); - exports->Set(String::NewFromUtf8(isolate, "GZNode"), - tpl->GetFunction()); + target->Set(Nan::GetCurrentContext(), class_name, + tpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked() + ).ToChecked(); } ///////////////////////////////////////////////// -void GZNode::New(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::New) { - if (args.IsConstructCall()) { + if (info.IsConstructCall()) { // Invoked as constructor: `new MyObject(...)` GZNode* obj = new GZNode(); - obj->Wrap(args.This()); - args.GetReturnValue().Set(args.This()); + obj->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + }else{ + return Nan::ThrowTypeError("GZNode::New - called without new keyword"); } } ///////////////////////////////////////////////// -void GZNode::LoadMaterialScripts(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::LoadMaterialScripts) { - Isolate* isolate = args.GetIsolate(); + Isolate* isolate = info.GetIsolate(); - if (args.Length() < 1) + if (info.Length() < 1) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong number of arguments"))); - return; + return Nan::ThrowTypeError("GZNode::LoadMaterialScripts - Wrong number of arguments. One arg expected"); } - if (!args[0]->IsString()) + if (!info[0]->IsString()) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong argument type. String expected."))); - return; + return Nan::ThrowTypeError("GZNode::LoadMaterialScripts - Wrong argument type. String expected."); } - GZNode* obj = ObjectWrap::Unwrap(args.This()); + GZNode* obj = ObjectWrap::Unwrap(info.This()); - String::Utf8Value path(args[0]->ToString()); + String::Utf8Value path(isolate, info[0]); obj->gzIface->LoadMaterialScripts(std::string(*path)); return; } ///////////////////////////////////////////////// -void GZNode::SetConnected(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::SetConnected) { - GZNode *obj = ObjectWrap::Unwrap(args.This()); - bool value = args[0]->BooleanValue(); + + GZNode *obj = ObjectWrap::Unwrap(info.This()); + bool value = Nan::To(info[0]).ToChecked(); obj->gzIface->SetConnected(value); return; } ///////////////////////////////////////////////// -void GZNode::GetIsGzServerConnected(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetIsGzServerConnected) { - GZNode *obj = ObjectWrap::Unwrap(args.This()); + GZNode *obj = ObjectWrap::Unwrap(info.This()); bool value = obj->isGzServerConnected; - args.GetReturnValue().Set(value); + info.GetReturnValue().Set(value); } ///////////////////////////////////////////////// -void GZNode::GetMaterialScriptsMessage(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetMaterialScriptsMessage) { - Isolate* isolate = args.GetIsolate(); + Isolate* isolate = info.GetIsolate(); - if (args.Length() < 1) + if (info.Length() < 1) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong number of arguments"))); - return; + return Nan::ThrowTypeError("GZNode::GetMaterialScriptsMessage - Wrong number of arguments. One arg expected."); } - if (!args[0]->IsString()) + if (!info[0]->IsString()) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong argument type. String expected."))); - return; + return Nan::ThrowTypeError("GZNode::GetMaterialScriptsMessage - Wrong argument type. String expected."); } - String::Utf8Value path(args[0]->ToString()); + String::Utf8Value path(isolate, info[0]); OgreMaterialParser materialParser; materialParser.Load(std::string(*path)); @@ -171,16 +169,15 @@ void GZNode::GetMaterialScriptsMessage(const FunctionCallbackInfo& args) msg += materialJson; msg += "}"; - args.GetReturnValue().Set(String::NewFromUtf8(isolate ,msg.c_str())); + info.GetReturnValue().Set(Nan::New(msg.c_str()).ToLocalChecked()); } ///////////////////////////////////////////////// -void GZNode::SetPoseMsgFilterMinimumDistanceSquared(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::SetPoseMsgFilterMinimumDistanceSquared) { - GZNode *obj = ObjectWrap::Unwrap(args.This()); + GZNode *obj = ObjectWrap::Unwrap(info.This()); - Local v = Local::Cast(args[0]); + Local v = Nan::To(info[0]).ToLocalChecked(); double value = v->Value(); obj->gzIface->SetPoseFilterMinimumDistanceSquared(value); @@ -188,21 +185,18 @@ void GZNode::SetPoseMsgFilterMinimumDistanceSquared(const } ///////////////////////////////////////////////// -void GZNode::GetPoseMsgFilterMinimumDistanceSquared(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetPoseMsgFilterMinimumDistanceSquared) { - Isolate* isolate = args.GetIsolate(); - GZNode *obj = ObjectWrap::Unwrap(args.This()); + GZNode *obj = ObjectWrap::Unwrap(info.This()); double value = obj->gzIface->GetPoseFilterMinimumDistanceSquared(); - args.GetReturnValue().Set(Number::New(isolate ,value)); + info.GetReturnValue().Set(Nan::New(value)); } ///////////////////////////////////////////////////// -void GZNode::SetPoseMsgFilterMinimumQuaternionSquared(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::SetPoseMsgFilterMinimumQuaternionSquared) { - GZNode *obj = ObjectWrap::Unwrap(args.This()); - Local v = Local::Cast(args[0]); + GZNode *obj = ObjectWrap::Unwrap(info.This()); + Local v = Nan::To(info[0]).ToLocalChecked(); double value = v->Value(); obj->gzIface->SetPoseFilterMinimumQuaternionSquared(value); @@ -210,66 +204,58 @@ void GZNode::SetPoseMsgFilterMinimumQuaternionSquared(const } ///////////////////////////////////////////////// -void GZNode::GetPoseMsgFilterMinimumQuaternionSquared(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetPoseMsgFilterMinimumQuaternionSquared) { - Isolate* isolate = args.GetIsolate(); - GZNode *obj = ObjectWrap::Unwrap(args.This()); + GZNode *obj = ObjectWrap::Unwrap(info.This()); double value = obj->gzIface->GetPoseFilterMinimumQuaternionSquared(); - args.GetReturnValue().Set(Number::New(isolate ,value)); + info.GetReturnValue().Set(Nan::New(value)); } ///////////////////////////////////////////////// -void GZNode::GetMessages(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetMessages) { - Isolate* isolate = args.GetIsolate(); - GZNode* obj = ObjectWrap::Unwrap(args.This()); + GZNode* obj = ObjectWrap::Unwrap(info.This()); std::vector msgs = obj->gzIface->PopOutgoingMessages(); - // args.GetReturnValue().Set(Number::New(isolate ,msgs.size())); - Local arguments = Array::New(isolate, msgs.size()); + Local arguments = Nan::New(msgs.size()); for (unsigned int i = 0; i < msgs.size(); ++i) { - arguments->Set(i ,String::NewFromUtf8(isolate, msgs[i].c_str())); + Local v8_msg = Nan::New(msgs[i].c_str()).ToLocalChecked(); + Nan::Set(arguments, i, v8_msg); } - args.GetReturnValue().Set(arguments); + info.GetReturnValue().Set(arguments); } //////////////////////////////////////////////// -void GZNode::Request(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::Request) { - Isolate* isolate = args.GetIsolate(); + Isolate* isolate = info.GetIsolate(); - if (args.Length() < 1) + if (info.Length() < 1) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong number of arguments"))); - return; + return Nan::ThrowTypeError("GZNode::Request - Wrong number of arguments. One arg expected."); } - if (!args[0]->IsString()) + if (!info[0]->IsString()) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong argument type. String expected."))); - return; + return Nan::ThrowTypeError("GZNode::Request - Wrong argument type. String expected."); } - GZNode* obj = ObjectWrap::Unwrap(args.This()); + GZNode* obj = ObjectWrap::Unwrap(info.This()); - String::Utf8Value request(args[0]->ToString()); + String::Utf8Value request(isolate, info[0]); obj->gzIface->PushRequest(std::string(*request)); return; } ///////////////////////////////////////////////// -void GZNode::SetPoseMsgFilterMinimumAge(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::SetPoseMsgFilterMinimumAge) { - GZNode* obj = ObjectWrap::Unwrap(args.This()); - Local v = Local::Cast(args[0]); + GZNode* obj = ObjectWrap::Unwrap(info.This()); + Local v = Nan::To(info[0]).ToLocalChecked(); double value = v->Value(); obj->gzIface->SetPoseFilterMinimumMsgAge(value); @@ -277,16 +263,15 @@ void GZNode::SetPoseMsgFilterMinimumAge(const } ///////////////////////////////////////////////// -void GZNode::GetPoseMsgFilterMinimumAge(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetPoseMsgFilterMinimumAge) { - GZNode* obj = ObjectWrap::Unwrap(args.This()); + GZNode* obj = ObjectWrap::Unwrap(info.This()); double value = obj->gzIface->GetPoseFilterMinimumMsgAge(); - args.GetReturnValue().Set(value); + info.GetReturnValue().Set(value); } ///////////////////////////////////////////////// -void InitAll(Handle exports) +void InitAll(Local exports, Local module, void* priv) { GZNode::Init(exports); } diff --git a/gzbridge/GZNode.hh b/gzbridge/GZNode.hh index 74872df1..8b561836 100644 --- a/gzbridge/GZNode.hh +++ b/gzbridge/GZNode.hh @@ -18,62 +18,46 @@ #ifndef GZBRIDGE_GZNODE_HH_ #define GZBRIDGE_GZNODE_HH_ -#include -#include +#include namespace gzweb { - using v8::FunctionCallbackInfo; - using v8::Value; - using v8::FunctionTemplate; - using v8::Object; - using v8::Persistent; class GazeboInterface; - class GZNode : public node::ObjectWrap + class GZNode : public Nan::ObjectWrap { - public: static void Init(v8::Handle exports); + public: static NAN_MODULE_INIT(Init); private: GZNode(); private: ~GZNode(); - private: static void New(const FunctionCallbackInfo& args); + private: static NAN_METHOD(New); - private: static void LoadMaterialScripts( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(LoadMaterialScripts); - private: static void SetConnected( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(SetConnected); - private: static void GetIsGzServerConnected( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetIsGzServerConnected); - private: static void GetMaterialScriptsMessage( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetMaterialScriptsMessage); - private: static void SetPoseMsgFilterMinimumDistanceSquared( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(SetPoseMsgFilterMinimumDistanceSquared); - private: static void GetPoseMsgFilterMinimumDistanceSquared( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetPoseMsgFilterMinimumDistanceSquared); - private: static void SetPoseMsgFilterMinimumQuaternionSquared( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(SetPoseMsgFilterMinimumQuaternionSquared); - private: static void GetPoseMsgFilterMinimumQuaternionSquared( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetPoseMsgFilterMinimumQuaternionSquared); - private: static void GetMessages(const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetMessages); - private: static void Request(const FunctionCallbackInfo& args); + private: static NAN_METHOD(Request); - private: static void SetPoseMsgFilterMinimumAge( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(SetPoseMsgFilterMinimumAge); - private: static void GetPoseMsgFilterMinimumAge( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetPoseMsgFilterMinimumAge); private: GazeboInterface* gzIface = nullptr; diff --git a/gzbridge/binding.gyp b/gzbridge/binding.gyp index 53d0cad3..936725c5 100644 --- a/gzbridge/binding.gyp +++ b/gzbridge/binding.gyp @@ -7,8 +7,12 @@ "pb2json.cc", "pb2json.hh", "ConfigLoader.cc", "ConfigLoader.hh", "OgreMaterialParser.cc", "OgreMaterialParser.hh"], + "include_dirs" : [ + " result_index(num_results); std::vector out_dist_sqr(num_results); static const int offset[] = {1,2,-1,1,-2,-1}; - for (int i = 0; i < outTriIndexCount; ++i) + for (unsigned int i = 0; i < outTriIndexCount; ++i) { unsigned int outIndex = _outSubMesh->GetIndex(i); ignition::math::Vector3d outVertex = _outSubMesh->Vertex(outIndex); @@ -146,7 +146,7 @@ void ExportTextureSource(const gazebo::common::SubMesh *_outSubMesh, std::vector closestIndices; double closestDistance = 1000; - for (int j = 0; j < num_results; ++j) + for (unsigned int j = 0; j < num_results; ++j) { inVertex = _inSubMesh->Vertex(result_index[j]); @@ -214,7 +214,7 @@ void ExportTextureSource(const gazebo::common::SubMesh *_outSubMesh, // Find the closest direction among all triangles containing overlapping // vertices - for (int k = 1; k < closestIndices.size(); ++k) + for (unsigned int k = 1; k < closestIndices.size(); ++k) { // Current vertex size_t currentIndex = closestIndices[k]; @@ -1246,7 +1246,7 @@ int main(int argc, char **argv) gazebo::common::Mesh *outGz = new gazebo::common::Mesh(); - for (int s = 0; s < inGz->GetSubMeshCount(); ++s) + for (unsigned int s = 0; s < inGz->GetSubMeshCount(); ++s) { const gazebo::common::SubMesh *inSubMesh = inGz->GetSubMesh(s);