Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 5 additions & 40 deletions src/lv_interop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ typedef int32_t(*RTSetCleanupProc_T)(grpc_labview::CleanupProcPtr cleanUpProc, g
typedef unsigned char** (*DSNewHandlePtr_T)(size_t);
typedef int (*DSSetHandleSize_T)(void* h, size_t);
typedef long (*DSDisposeHandle_T)(void* h);
typedef int (*ConvertSystemStringToUTF8_T)(grpc_labview::LStrHandle, grpc_labview::LStrHandle *);
typedef int (*ConvertUTF8StringToSystem_T)(grpc_labview::LStrHandle, grpc_labview::LStrHandle *);


//---------------------------------------------------------------------
Expand All @@ -35,8 +33,6 @@ static std::string ModulePath = "";
static DSNewHandlePtr_T DSNewHandleImpl = nullptr;
static DSSetHandleSize_T DSSetHandleSizeImpl = nullptr;
static DSDisposeHandle_T DSDisposeHandleImpl = nullptr;
static ConvertSystemStringToUTF8_T ConvertSystemStringToUTF8Impl = nullptr;
static ConvertUTF8StringToSystem_T ConvertUTF8StringToSystemImpl = nullptr;

namespace grpc_labview
{
Expand Down Expand Up @@ -87,8 +83,6 @@ namespace grpc_labview
DSNewHandleImpl = (DSNewHandlePtr_T)GetProcAddress(lvModule, "DSNewHandle");
DSSetHandleSizeImpl = (DSSetHandleSize_T)GetProcAddress(lvModule, "DSSetHandleSize");
DSDisposeHandleImpl = (DSDisposeHandle_T)GetProcAddress(lvModule, "DSDisposeHandle");
ConvertSystemStringToUTF8Impl = (ConvertSystemStringToUTF8_T)GetProcAddress(lvModule, "ConvertSystemStringToUTF8");
ConvertUTF8StringToSystemImpl = (ConvertUTF8StringToSystem_T)GetProcAddress(lvModule, "ConvertUTF8StringToSystem");
}

#else
Expand All @@ -109,8 +103,6 @@ namespace grpc_labview
DSNewHandleImpl = (DSNewHandlePtr_T)dlsym(RTLD_DEFAULT, "DSNewHandle");
DSSetHandleSizeImpl = (DSSetHandleSize_T)dlsym(RTLD_DEFAULT, "DSSetHandleSize");
DSDisposeHandleImpl = (DSDisposeHandle_T)dlsym(RTLD_DEFAULT, "DSDisposeHandle");
ConvertSystemStringToUTF8Impl = (ConvertSystemStringToUTF8_T)dlsym(RTLD_DEFAULT, "ConvertSystemStringToUTF8");
ConvertUTF8StringToSystemImpl = (ConvertUTF8StringToSystem_T)dlsym(RTLD_DEFAULT, "ConvertUTF8StringToSystem");
}

#endif
Expand Down Expand Up @@ -162,17 +154,9 @@ namespace grpc_labview
void SetLVString(LStrHandle* lvString, std::string str)
{
auto length = str.length();

LStrHandle utf8String = nullptr;
auto error = NumericArrayResize(0x01, 1, &utf8String, length);
std::unique_ptr<LStrPtr, long (*)(void*)> utf8StringDeleter(utf8String, &DSDisposeHandle);
if (error != 0) throw std::bad_alloc();

memcpy((*utf8String)->str, str.c_str(), length);
(*utf8String)->cnt = (int)length;

error = ConvertUTF8StringToSystem(utf8String, lvString);
if (error != 0) throw std::runtime_error("Failed to convert string encoding.");
auto error = NumericArrayResize(0x01, 1, lvString, length);
memcpy((**lvString)->str, str.c_str(), length);
(**lvString)->cnt = (int)length;
}

//---------------------------------------------------------------------
Expand All @@ -184,13 +168,8 @@ namespace grpc_labview
return std::string();
}

LStrHandle utf8String = nullptr;
auto error = ConvertSystemStringToUTF8(lvString, &utf8String);
std::unique_ptr<LStrPtr, long (*)(void*)> utf8StringDeleter(utf8String, &DSDisposeHandle);
if (error != 0) throw std::runtime_error("Failed to convert string encoding.");

auto count = (*utf8String)->cnt;
auto chars = (*utf8String)->str;
auto count = (*lvString)->cnt;
auto chars = (*lvString)->str;

std::string result(chars, count);
return result;
Expand Down Expand Up @@ -239,18 +218,4 @@ namespace grpc_labview
return 0x8; // uQ
}
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
int ConvertSystemStringToUTF8(LStrHandle stringIn, LStrHandle *stringOut)
{
return ConvertSystemStringToUTF8Impl(stringIn, stringOut);
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
int ConvertUTF8StringToSystem(LStrHandle stringIn, LStrHandle *stringOut)
{
return ConvertUTF8StringToSystemImpl(stringIn, stringOut);
}
}
2 changes: 0 additions & 2 deletions src/lv_interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,4 @@ namespace grpc_labview
int SignalOccurrence(MagicCookie occurrence);
int32_t RegisterCleanupProc(CleanupProcPtr cleanUpProc, grpc_labview::gRPCid* id, CleanupProcMode cleanupCondition = CleanupProcMode::CleanOnIdle);
int32_t DeregisterCleanupProc(CleanupProcPtr cleanUpProc, grpc_labview::gRPCid* id);
int ConvertSystemStringToUTF8(LStrHandle stringIn, LStrHandle *stringOut);
int ConvertUTF8StringToSystem(LStrHandle stringIn, LStrHandle *stringOut);
}
Binary file not shown.
Binary file removed tests/AutoTests/Test_HelloWorld_Utf8Encoding.vi
Binary file not shown.
2 changes: 0 additions & 2 deletions tests/Tests.lst
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
AutoTests\Test_HelloWorld.vi
AutoTests\Test_HelloWorld_Internationalization.vi
AutoTests\Test_HelloWorld_Utf8Encoding.vi
AutoTests\Test_RouteGuide_Unary.vi
AutoTests\Test_RouteGuide_ResponseStreaming.vi
AutoTests\Test_RouteGuide_BidirectionalStreaming.vi
Expand Down
Loading