Skip to content

Commit 2920026

Browse files
committed
LibGRPC fixes
1 parent af1b8ca commit 2920026

7 files changed

+69
-7
lines changed

ACT/LibGRPCWrapper.xml

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
<error name="MESSAGEDESCRIPTORISNULL" code="1023" description="Internal error: Message descriptor is null" />
6464
<error name="MESSAGISNULL" code="1024" description="Internal error: Message is null" />
6565
<error name="MESSAGREFLECTIONISNULL" code="1025" description="Internal error: Message reflection is null" />
66+
<error name="COULDNOTRETRIEVETEMPPATHS" code="1026" description="Could not retrieve temp paths" />
67+
<error name="COULDNOTCONVERTUNICODESTRING" code="1027" description="Could not convert unicode string" />
68+
6669

6770
</errors>
6871

Headers/CppDynamic/libgrpcwrapper_dynamic.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ class ELibGRPCWrapperException : public std::exception {
202202
case LIBGRPCWRAPPER_ERROR_MESSAGEDESCRIPTORISNULL: return "MESSAGEDESCRIPTORISNULL";
203203
case LIBGRPCWRAPPER_ERROR_MESSAGISNULL: return "MESSAGISNULL";
204204
case LIBGRPCWRAPPER_ERROR_MESSAGREFLECTIONISNULL: return "MESSAGREFLECTIONISNULL";
205+
case LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS: return "COULDNOTRETRIEVETEMPPATHS";
206+
case LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING: return "COULDNOTCONVERTUNICODESTRING";
205207
}
206208
return "UNKNOWN";
207209
}
@@ -235,6 +237,8 @@ class ELibGRPCWrapperException : public std::exception {
235237
case LIBGRPCWRAPPER_ERROR_MESSAGEDESCRIPTORISNULL: return "Internal error: Message descriptor is null";
236238
case LIBGRPCWRAPPER_ERROR_MESSAGISNULL: return "Internal error: Message is null";
237239
case LIBGRPCWRAPPER_ERROR_MESSAGREFLECTIONISNULL: return "Internal error: Message reflection is null";
240+
case LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS: return "Could not retrieve temp paths";
241+
case LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING: return "Could not convert unicode string";
238242
}
239243
return "unknown error";
240244
}

Headers/CppDynamic/libgrpcwrapper_types.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ typedef void * LibGRPCWrapper_pvoid;
121121
#define LIBGRPCWRAPPER_ERROR_MESSAGEDESCRIPTORISNULL 1023 /** Internal error: Message descriptor is null */
122122
#define LIBGRPCWRAPPER_ERROR_MESSAGISNULL 1024 /** Internal error: Message is null */
123123
#define LIBGRPCWRAPPER_ERROR_MESSAGREFLECTIONISNULL 1025 /** Internal error: Message reflection is null */
124+
#define LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS 1026 /** Could not retrieve temp paths */
125+
#define LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING 1027 /** Could not convert unicode string */
124126

125127
/*************************************************************************************************************************
126128
Error strings for LibGRPCWrapper
@@ -154,6 +156,8 @@ inline const char * LIBGRPCWRAPPER_GETERRORSTRING (LibGRPCWrapperResult nErrorCo
154156
case LIBGRPCWRAPPER_ERROR_MESSAGEDESCRIPTORISNULL: return "Internal error: Message descriptor is null";
155157
case LIBGRPCWRAPPER_ERROR_MESSAGISNULL: return "Internal error: Message is null";
156158
case LIBGRPCWRAPPER_ERROR_MESSAGREFLECTIONISNULL: return "Internal error: Message reflection is null";
159+
case LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS: return "Could not retrieve temp paths";
160+
case LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING: return "Could not convert unicode string";
157161
default: return "unknown error";
158162
}
159163
}

Implementation/libgrpcwrapper_connectinstance.cpp

+42-3
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,52 @@ CConnectionInstance::CConnectionInstance(const std::string& sProtobufDefinition,
5151
throw ELibGRPCWrapperInterfaceException(LIBGRPCWRAPPER_ERROR_COULDNOTCREATECHANNEL, "Could not create channel: " + sEndPoint);
5252

5353
// Create temporary.proto file and fill with given content
54-
const std::string sProtoFilePathTemp = "temp.proto";
55-
std::ofstream tempFile(sProtoFilePathTemp);
54+
// TODO: Make virtual path readers!!!
55+
std::wstring sMapPathW;
56+
std::string sMapPath;
57+
#ifdef _WIN32
58+
std::vector<wchar_t> TempPathBufferW;
59+
TempPathBufferW.resize(MAX_PATH + 1);
60+
auto nSize = GetTempPathW(MAX_PATH, TempPathBufferW.data());
61+
if (nSize == 0)
62+
throw ELibGRPCWrapperInterfaceException(LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS);
63+
64+
TempPathBufferW[MAX_PATH] = 0;
65+
sMapPathW = TempPathBufferW.data();
66+
67+
std::vector<char> TempPathBuffer(MAX_PATH * 2 + 4);
68+
int nResult = WideCharToMultiByte(CP_UTF8, 0, sMapPathW.c_str(), sMapPathW.size (), TempPathBuffer.data (), MAX_PATH, nullptr, nullptr);
69+
if (nResult == 0)
70+
throw ELibGRPCWrapperInterfaceException(LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING);
71+
72+
TempPathBuffer.at(TempPathBuffer.size() - 1) = 0;
73+
74+
sMapPath = TempPathBuffer.data ();
75+
76+
#else
77+
sMapPath = "/tmp";
78+
#endif
79+
80+
std::string sProtoFilePathTemp = "libgrpc_temp_";
81+
82+
for (int index = 0; index < 16; index++) {
83+
uint8_t nValue = rand() % 16;
84+
if (nValue < 10)
85+
sProtoFilePathTemp += ('0' + nValue);
86+
else
87+
sProtoFilePathTemp += ('a' + nValue - 10);
88+
}
89+
90+
sProtoFilePathTemp += ".proto";
91+
92+
std::wstring sProtoFilePathTempW (sProtoFilePathTemp.begin (), sProtoFilePathTemp.end());
93+
94+
std::ofstream tempFile(sMapPathW + L"/" + sProtoFilePathTempW);
5695
tempFile << sProtobufDefinition;
5796
tempFile.close();
5897

5998
m_pSourceTree = std::make_shared<google::protobuf::compiler::DiskSourceTree>();
60-
m_pSourceTree->MapPath("", "W:/libgrpc/build/Release");
99+
m_pSourceTree->MapPath("", sMapPath);
61100

62101
m_pErrorCollector = std::make_shared<CConnectionErrorCollector> ();
63102

Interfaces/libgrpcwrapper_types.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ typedef void * LibGRPCWrapper_pvoid;
121121
#define LIBGRPCWRAPPER_ERROR_MESSAGEDESCRIPTORISNULL 1023 /** Internal error: Message descriptor is null */
122122
#define LIBGRPCWRAPPER_ERROR_MESSAGISNULL 1024 /** Internal error: Message is null */
123123
#define LIBGRPCWRAPPER_ERROR_MESSAGREFLECTIONISNULL 1025 /** Internal error: Message reflection is null */
124+
#define LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS 1026 /** Could not retrieve temp paths */
125+
#define LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING 1027 /** Could not convert unicode string */
124126

125127
/*************************************************************************************************************************
126128
Error strings for LibGRPCWrapper
@@ -154,6 +156,8 @@ inline const char * LIBGRPCWRAPPER_GETERRORSTRING (LibGRPCWrapperResult nErrorCo
154156
case LIBGRPCWRAPPER_ERROR_MESSAGEDESCRIPTORISNULL: return "Internal error: Message descriptor is null";
155157
case LIBGRPCWRAPPER_ERROR_MESSAGISNULL: return "Internal error: Message is null";
156158
case LIBGRPCWRAPPER_ERROR_MESSAGREFLECTIONISNULL: return "Internal error: Message reflection is null";
159+
case LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS: return "Could not retrieve temp paths";
160+
case LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING: return "Could not convert unicode string";
157161
default: return "unknown error";
158162
}
159163
}

TestApp/MinimalTest.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main()
4747
auto pProtocol = pWrapper->CreateProtocol(buffer.str());
4848

4949
std::cout << "Connecting\n";
50-
auto pConnection = pProtocol->ConnectUnsecure("localhost:50051");
50+
auto pConnection = pProtocol->ConnectUnsecure("192.168.5.2:50051");
5151

5252
std::cout << "Connection end point: " << pConnection->GetEndPoint() << std::endl;
5353

@@ -59,10 +59,17 @@ int main()
5959

6060
std::cout << "Sending Request\n";
6161
auto pResponse = pRequest->SendBlocking("/machine_interface.Machine/OpenDoors", 10000);
62+
if (pResponse->HasField("success")) {
63+
std::cout << "Call succeeded: " << pResponse->GetBoolField ("success") << std::endl;
64+
65+
}
66+
else {
67+
std::string sResponseField = pResponse->GetStringField("error");
68+
std::cout << "Error field: " << sResponseField << std::endl;
69+
70+
}
6271
// = pResponse->GetBoolField("success");
63-
std::string sResponseField = pResponse->GetStringField("error");
6472

65-
std::cout << "Response field: " << sResponseField << std::endl;
6673
//std::cout << "Response bool field: " << pRequest->GetBoolField ("response_2") << std::endl;
6774

6875
std::cout << "done\n";

build_win64.bat

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mkdir build
22
cd build
33
cmake ..
4-
cmake -DCMAKE_TOOLCHAIN_FILE=w:/vcpkg/scripts/buildsystems/vcpkg.cmake --build . --config Release
4+
REM cmake -DCMAKE_TOOLCHAIN_FILE=c:\vcpkg\scripts\buildsystems\vcpkg.cmake --build . --config Release
5+
cmake --build . --config Release
56

67
pause

0 commit comments

Comments
 (0)