From b55b4d90b99103fa2cf5c8e243177ccd6dedcba3 Mon Sep 17 00:00:00 2001 From: Christopher Cifra Date: Mon, 12 Apr 2021 13:35:44 -0500 Subject: [PATCH] Fixing issues getting the correct LV exports on Linux. --- src/event_data.cc | 4 ++-- src/grpc_interop.cc | 2 +- src/lv_interop.cc | 29 ++++++++++++++++++----------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/event_data.cc b/src/event_data.cc index da906fb7..d40649d8 100644 --- a/src/event_data.cc +++ b/src/event_data.cc @@ -196,7 +196,7 @@ LVMessage::~LVMessage() google::protobuf::Message* LVMessage::New() const { assert(false); // not expected to be called - return NULL; + return nullptr; } //--------------------------------------------------------------------- @@ -1235,7 +1235,7 @@ GenericMethodData::GenericMethodData(CallData* call, ServerContext *context, std //--------------------------------------------------------------------- //--------------------------------------------------------------------- ServerStartEventData::ServerStartEventData() - : EventData(NULL) + : EventData(nullptr) { serverStartStatus = 0; } \ No newline at end of file diff --git a/src/grpc_interop.cc b/src/grpc_interop.cc index ae35b251..9e98b7ea 100644 --- a/src/grpc_interop.cc +++ b/src/grpc_interop.cc @@ -89,7 +89,7 @@ LIBRARY_EXPORT int32_t RegisterMessageMetadata(LVgRPCServerid* id, LVMessageMeta //--------------------------------------------------------------------- //--------------------------------------------------------------------- LIBRARY_EXPORT int32_t RegisterServerEvent(LVgRPCServerid* id, const char* name, LVUserEventRef* item, const char* requestMessageName, const char* responseMessageName) -{ +{ auto server = *(LabVIEWgRPCServer**)id; server->RegisterEvent(name, *item, requestMessageName, responseMessageName); diff --git a/src/lv_interop.cc b/src/lv_interop.cc index a4e5612c..33dbaddc 100644 --- a/src/lv_interop.cc +++ b/src/lv_interop.cc @@ -1,6 +1,7 @@ //--------------------------------------------------------------------- //--------------------------------------------------------------------- #include +#include #include #include @@ -19,8 +20,8 @@ typedef int (*PostLVUserEvent_T)(LVUserEventRef ref, void *data); //--------------------------------------------------------------------- //--------------------------------------------------------------------- -static NumericArrayResize_T NumericArrayResize; -static PostLVUserEvent_T PostLVUserEvent; +static NumericArrayResize_T NumericArrayResize = nullptr; +static PostLVUserEvent_T PostLVUserEvent = nullptr; #ifdef _WIN32 @@ -28,17 +29,17 @@ static PostLVUserEvent_T PostLVUserEvent; //--------------------------------------------------------------------- void InitCallbacks() { - if (NumericArrayResize != NULL) + if (NumericArrayResize != nullptr) { return; } auto lvModule = GetModuleHandle("LabVIEW.exe"); - if (lvModule == NULL) + if (lvModule == nullptr) { lvModule = GetModuleHandle("lvffrt.dll"); } - if (lvModule == NULL) + if (lvModule == nullptr) { lvModule = GetModuleHandle("lvrt.dll"); } @@ -52,18 +53,24 @@ void InitCallbacks() //--------------------------------------------------------------------- void InitCallbacks() { - if (NumericArrayResize != NULL) + if (NumericArrayResize != nullptr) { return; } - auto lvModule = dlopen("labview", RTLD_NOLOAD); - if (lvModule == NULL) + auto lvModule = dlopen(nullptr, RTLD_LAZY); + if (lvModule != nullptr) { + NumericArrayResize = (NumericArrayResize_T)dlsym(lvModule, "NumericArrayResize"); + PostLVUserEvent = (PostLVUserEvent_T)dlsym(lvModule, "PostLVUserEvent"); + } + if (NumericArrayResize == nullptr) + { + cout << "Loading LabVIEW Runtime engine!" << endl; lvModule = dlopen("liblvrt.so", RTLD_NOW); + NumericArrayResize = (NumericArrayResize_T)dlsym(lvModule, "NumericArrayResize"); + PostLVUserEvent = (PostLVUserEvent_T)dlsym(lvModule, "PostLVUserEvent"); } - NumericArrayResize = (NumericArrayResize_T)dlsym(lvModule, "NumericArrayResize"); - PostLVUserEvent = (PostLVUserEvent_T)dlsym(lvModule, "PostLVUserEvent"); } #endif @@ -96,7 +103,7 @@ void SetLVString(LStrHandle* lvString, string str) //--------------------------------------------------------------------- string GetLVString(LStrHandle lvString) { - if (lvString == NULL || *lvString == NULL) + if (lvString == nullptr || *lvString == nullptr) { return string(); }