Skip to content

Commit 09c412f

Browse files
Added Subfield support
1 parent 2920026 commit 09c412f

16 files changed

+358
-76
lines changed

ACT/LibGRPCWrapper.xml

+13-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
<error name="COULDNOTRETRIEVETEMPPATHS" code="1026" description="Could not retrieve temp paths" />
6767
<error name="COULDNOTCONVERTUNICODESTRING" code="1027" description="Could not convert unicode string" />
6868

69+
<error name="MESSAGEFIELDNOTFOUND" code="1028" description="Message field not found" />
70+
6971

7072
</errors>
7173

@@ -87,6 +89,16 @@
8789
<param name="FieldName" type="string" pass="in" description="Name of the field." />
8890
<param name="StringFieldExists" type="bool" pass="return" description="True if field exists and is of type string." />
8991
</method>
92+
93+
<method name="HasMessageField" description="Returns if the message has a field of a certain name and this field is a submessage field.">
94+
<param name="FieldName" type="string" pass="in" description="Name of the field." />
95+
<param name="MessageFieldExists" type="bool" pass="return" description="True if field exists and is of type message." />
96+
</method>
97+
98+
<method name="GetMessageField" description="Returns the submessage of a field. Fails if the field does not exist or is not a submessage field.">
99+
<param name="FieldName" type="string" pass="in" description="Name of the field." />
100+
<param name="MessageFieldInstance" type="class" class="Message" pass="return" description="Sub message object" />
101+
</method>
90102

91103
<method name="SetStringField" description="Sets a string field of the message. Fails if the field does not exist or is not a string field.">
92104
<param name="FieldName" type="string" pass="in" description="Name of the field." />
@@ -165,7 +177,7 @@
165177

166178
<method name="GetDoubleField" description="Gets a double field of the message. Fails if the field does not exist or is not a double field.">
167179
<param name="FieldName" type="string" pass="in" description="Name of the field." />
168-
<param name="Value" type="int32" pass="return" description="Current value of the field." />
180+
<param name="Value" type="double" pass="return" description="Current value of the field." />
169181
</method>
170182

171183
</class>

Headers/CppDynamic/libgrpcwrapper_dynamic.h

+23-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ typedef LibGRPCWrapperResult (*PLibGRPCWrapperMessage_HasFieldPtr) (LibGRPCWrapp
7171
*/
7272
typedef LibGRPCWrapperResult (*PLibGRPCWrapperMessage_HasStringFieldPtr) (LibGRPCWrapper_Message pMessage, const char * pFieldName, bool * pStringFieldExists);
7373

74+
/**
75+
* Returns if the message has a field of a certain name and this field is a submessage field.
76+
*
77+
* @param[in] pMessage - Message instance.
78+
* @param[in] pFieldName - Name of the field.
79+
* @param[out] pMessageFieldExists - True if field exists and is of type message.
80+
* @return error code or 0 (success)
81+
*/
82+
typedef LibGRPCWrapperResult (*PLibGRPCWrapperMessage_HasMessageFieldPtr) (LibGRPCWrapper_Message pMessage, const char * pFieldName, bool * pMessageFieldExists);
83+
84+
/**
85+
* Returns the submessage of a field. Fails if the field does not exist or is not a submessage field.
86+
*
87+
* @param[in] pMessage - Message instance.
88+
* @param[in] pFieldName - Name of the field.
89+
* @param[out] pMessageFieldInstance - Sub message object
90+
* @return error code or 0 (success)
91+
*/
92+
typedef LibGRPCWrapperResult (*PLibGRPCWrapperMessage_GetMessageFieldPtr) (LibGRPCWrapper_Message pMessage, const char * pFieldName, LibGRPCWrapper_Message * pMessageFieldInstance);
93+
7494
/**
7595
* Sets a string field of the message. Fails if the field does not exist or is not a string field.
7696
*
@@ -231,7 +251,7 @@ typedef LibGRPCWrapperResult (*PLibGRPCWrapperMessage_SetDoubleFieldPtr) (LibGRP
231251
* @param[out] pValue - Current value of the field.
232252
* @return error code or 0 (success)
233253
*/
234-
typedef LibGRPCWrapperResult (*PLibGRPCWrapperMessage_GetDoubleFieldPtr) (LibGRPCWrapper_Message pMessage, const char * pFieldName, LibGRPCWrapper_int32 * pValue);
254+
typedef LibGRPCWrapperResult (*PLibGRPCWrapperMessage_GetDoubleFieldPtr) (LibGRPCWrapper_Message pMessage, const char * pFieldName, LibGRPCWrapper_double * pValue);
235255

236256
/*************************************************************************************************************************
237257
Class definition for Response
@@ -421,6 +441,8 @@ typedef struct {
421441
void * m_LibraryHandle;
422442
PLibGRPCWrapperMessage_HasFieldPtr m_Message_HasField;
423443
PLibGRPCWrapperMessage_HasStringFieldPtr m_Message_HasStringField;
444+
PLibGRPCWrapperMessage_HasMessageFieldPtr m_Message_HasMessageField;
445+
PLibGRPCWrapperMessage_GetMessageFieldPtr m_Message_GetMessageField;
424446
PLibGRPCWrapperMessage_SetStringFieldPtr m_Message_SetStringField;
425447
PLibGRPCWrapperMessage_GetStringFieldPtr m_Message_GetStringField;
426448
PLibGRPCWrapperMessage_SetInt32FieldPtr m_Message_SetInt32Field;

Headers/CppDynamic/libgrpcwrapper_dynamic.hpp

+64-3
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class ELibGRPCWrapperException : public std::exception {
204204
case LIBGRPCWRAPPER_ERROR_MESSAGREFLECTIONISNULL: return "MESSAGREFLECTIONISNULL";
205205
case LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS: return "COULDNOTRETRIEVETEMPPATHS";
206206
case LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING: return "COULDNOTCONVERTUNICODESTRING";
207+
case LIBGRPCWRAPPER_ERROR_MESSAGEFIELDNOTFOUND: return "MESSAGEFIELDNOTFOUND";
207208
}
208209
return "UNKNOWN";
209210
}
@@ -239,6 +240,7 @@ class ELibGRPCWrapperException : public std::exception {
239240
case LIBGRPCWRAPPER_ERROR_MESSAGREFLECTIONISNULL: return "Internal error: Message reflection is null";
240241
case LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS: return "Could not retrieve temp paths";
241242
case LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING: return "Could not convert unicode string";
243+
case LIBGRPCWRAPPER_ERROR_MESSAGEFIELDNOTFOUND: return "Message field not found";
242244
}
243245
return "unknown error";
244246
}
@@ -438,6 +440,8 @@ class CMessage : public CBase {
438440

439441
inline bool HasField(const std::string & sFieldName);
440442
inline bool HasStringField(const std::string & sFieldName);
443+
inline bool HasMessageField(const std::string & sFieldName);
444+
inline PMessage GetMessageField(const std::string & sFieldName);
441445
inline void SetStringField(const std::string & sFieldName, const std::string & sValue);
442446
inline std::string GetStringField(const std::string & sFieldName);
443447
inline void SetInt32Field(const std::string & sFieldName, const LibGRPCWrapper_int32 nValue);
@@ -453,7 +457,7 @@ class CMessage : public CBase {
453457
inline void SetFloatField(const std::string & sFieldName, const LibGRPCWrapper_single fValue);
454458
inline LibGRPCWrapper_single GetFloatField(const std::string & sFieldName);
455459
inline void SetDoubleField(const std::string & sFieldName, const LibGRPCWrapper_double dValue);
456-
inline LibGRPCWrapper_int32 GetDoubleField(const std::string & sFieldName);
460+
inline LibGRPCWrapper_double GetDoubleField(const std::string & sFieldName);
457461
};
458462

459463
/*************************************************************************************************************************
@@ -629,6 +633,8 @@ class CProtocol : public CBase {
629633
pWrapperTable->m_LibraryHandle = nullptr;
630634
pWrapperTable->m_Message_HasField = nullptr;
631635
pWrapperTable->m_Message_HasStringField = nullptr;
636+
pWrapperTable->m_Message_HasMessageField = nullptr;
637+
pWrapperTable->m_Message_GetMessageField = nullptr;
632638
pWrapperTable->m_Message_SetStringField = nullptr;
633639
pWrapperTable->m_Message_GetStringField = nullptr;
634640
pWrapperTable->m_Message_SetInt32Field = nullptr;
@@ -729,6 +735,24 @@ class CProtocol : public CBase {
729735
if (pWrapperTable->m_Message_HasStringField == nullptr)
730736
return LIBGRPCWRAPPER_ERROR_COULDNOTFINDLIBRARYEXPORT;
731737

738+
#ifdef _WIN32
739+
pWrapperTable->m_Message_HasMessageField = (PLibGRPCWrapperMessage_HasMessageFieldPtr) GetProcAddress(hLibrary, "libgrpcwrapper_message_hasmessagefield");
740+
#else // _WIN32
741+
pWrapperTable->m_Message_HasMessageField = (PLibGRPCWrapperMessage_HasMessageFieldPtr) dlsym(hLibrary, "libgrpcwrapper_message_hasmessagefield");
742+
dlerror();
743+
#endif // _WIN32
744+
if (pWrapperTable->m_Message_HasMessageField == nullptr)
745+
return LIBGRPCWRAPPER_ERROR_COULDNOTFINDLIBRARYEXPORT;
746+
747+
#ifdef _WIN32
748+
pWrapperTable->m_Message_GetMessageField = (PLibGRPCWrapperMessage_GetMessageFieldPtr) GetProcAddress(hLibrary, "libgrpcwrapper_message_getmessagefield");
749+
#else // _WIN32
750+
pWrapperTable->m_Message_GetMessageField = (PLibGRPCWrapperMessage_GetMessageFieldPtr) dlsym(hLibrary, "libgrpcwrapper_message_getmessagefield");
751+
dlerror();
752+
#endif // _WIN32
753+
if (pWrapperTable->m_Message_GetMessageField == nullptr)
754+
return LIBGRPCWRAPPER_ERROR_COULDNOTFINDLIBRARYEXPORT;
755+
732756
#ifdef _WIN32
733757
pWrapperTable->m_Message_SetStringField = (PLibGRPCWrapperMessage_SetStringFieldPtr) GetProcAddress(hLibrary, "libgrpcwrapper_message_setstringfield");
734758
#else // _WIN32
@@ -1041,6 +1065,14 @@ class CProtocol : public CBase {
10411065
if ( (eLookupError != 0) || (pWrapperTable->m_Message_HasStringField == nullptr) )
10421066
return LIBGRPCWRAPPER_ERROR_COULDNOTFINDLIBRARYEXPORT;
10431067

1068+
eLookupError = (*pLookup)("libgrpcwrapper_message_hasmessagefield", (void**)&(pWrapperTable->m_Message_HasMessageField));
1069+
if ( (eLookupError != 0) || (pWrapperTable->m_Message_HasMessageField == nullptr) )
1070+
return LIBGRPCWRAPPER_ERROR_COULDNOTFINDLIBRARYEXPORT;
1071+
1072+
eLookupError = (*pLookup)("libgrpcwrapper_message_getmessagefield", (void**)&(pWrapperTable->m_Message_GetMessageField));
1073+
if ( (eLookupError != 0) || (pWrapperTable->m_Message_GetMessageField == nullptr) )
1074+
return LIBGRPCWRAPPER_ERROR_COULDNOTFINDLIBRARYEXPORT;
1075+
10441076
eLookupError = (*pLookup)("libgrpcwrapper_message_setstringfield", (void**)&(pWrapperTable->m_Message_SetStringField));
10451077
if ( (eLookupError != 0) || (pWrapperTable->m_Message_SetStringField == nullptr) )
10461078
return LIBGRPCWRAPPER_ERROR_COULDNOTFINDLIBRARYEXPORT;
@@ -1208,6 +1240,35 @@ class CProtocol : public CBase {
12081240
return resultStringFieldExists;
12091241
}
12101242

1243+
/**
1244+
* CMessage::HasMessageField - Returns if the message has a field of a certain name and this field is a submessage field.
1245+
* @param[in] sFieldName - Name of the field.
1246+
* @return True if field exists and is of type message.
1247+
*/
1248+
bool CMessage::HasMessageField(const std::string & sFieldName)
1249+
{
1250+
bool resultMessageFieldExists = 0;
1251+
CheckError(m_pWrapper->m_WrapperTable.m_Message_HasMessageField(m_pHandle, sFieldName.c_str(), &resultMessageFieldExists));
1252+
1253+
return resultMessageFieldExists;
1254+
}
1255+
1256+
/**
1257+
* CMessage::GetMessageField - Returns the submessage of a field. Fails if the field does not exist or is not a submessage field.
1258+
* @param[in] sFieldName - Name of the field.
1259+
* @return Sub message object
1260+
*/
1261+
PMessage CMessage::GetMessageField(const std::string & sFieldName)
1262+
{
1263+
LibGRPCWrapperHandle hMessageFieldInstance = nullptr;
1264+
CheckError(m_pWrapper->m_WrapperTable.m_Message_GetMessageField(m_pHandle, sFieldName.c_str(), &hMessageFieldInstance));
1265+
1266+
if (!hMessageFieldInstance) {
1267+
CheckError(LIBGRPCWRAPPER_ERROR_INVALIDPARAM);
1268+
}
1269+
return std::make_shared<CMessage>(m_pWrapper, hMessageFieldInstance);
1270+
}
1271+
12111272
/**
12121273
* CMessage::SetStringField - Sets a string field of the message. Fails if the field does not exist or is not a string field.
12131274
* @param[in] sFieldName - Name of the field.
@@ -1387,9 +1448,9 @@ class CProtocol : public CBase {
13871448
* @param[in] sFieldName - Name of the field.
13881449
* @return Current value of the field.
13891450
*/
1390-
LibGRPCWrapper_int32 CMessage::GetDoubleField(const std::string & sFieldName)
1451+
LibGRPCWrapper_double CMessage::GetDoubleField(const std::string & sFieldName)
13911452
{
1392-
LibGRPCWrapper_int32 resultValue = 0;
1453+
LibGRPCWrapper_double resultValue = 0;
13931454
CheckError(m_pWrapper->m_WrapperTable.m_Message_GetDoubleField(m_pHandle, sFieldName.c_str(), &resultValue));
13941455

13951456
return resultValue;

Headers/CppDynamic/libgrpcwrapper_types.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ typedef void * LibGRPCWrapper_pvoid;
123123
#define LIBGRPCWRAPPER_ERROR_MESSAGREFLECTIONISNULL 1025 /** Internal error: Message reflection is null */
124124
#define LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS 1026 /** Could not retrieve temp paths */
125125
#define LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING 1027 /** Could not convert unicode string */
126+
#define LIBGRPCWRAPPER_ERROR_MESSAGEFIELDNOTFOUND 1026 /** Message field not found */
126127

127128
/*************************************************************************************************************************
128129
Error strings for LibGRPCWrapper
@@ -158,6 +159,7 @@ inline const char * LIBGRPCWRAPPER_GETERRORSTRING (LibGRPCWrapperResult nErrorCo
158159
case LIBGRPCWRAPPER_ERROR_MESSAGREFLECTIONISNULL: return "Internal error: Message reflection is null";
159160
case LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS: return "Could not retrieve temp paths";
160161
case LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING: return "Could not convert unicode string";
162+
case LIBGRPCWRAPPER_ERROR_MESSAGEFIELDNOTFOUND: return "Message field not found";
161163
default: return "unknown error";
162164
}
163165
}

Implementation/libgrpcwrapper_connectinstance.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ std::shared_ptr<google::protobuf::Message> CConnectionInstance::createMessage(co
147147
return pMessageInstance;
148148
}
149149

150-
grpc::ByteBuffer CConnectionInstance::sendMessageBlocking(std::shared_ptr<google::protobuf::Message> pMessage, const std::string& sServiceMethod, uint32_t nTimeoutInMS)
150+
grpc::ByteBuffer CConnectionInstance::sendMessageBlocking(google::protobuf::Message* pMessage, const std::string& sServiceMethod, uint32_t nTimeoutInMS)
151151
{
152-
if (pMessage.get () == nullptr)
152+
if (pMessage == nullptr)
153153
throw ELibGRPCWrapperInterfaceException(LIBGRPCWRAPPER_ERROR_INVALIDPARAM);
154154
if (sServiceMethod.empty ())
155155
throw ELibGRPCWrapperInterfaceException(LIBGRPCWRAPPER_ERROR_EMPTYSERVICEMETHOD);

Implementation/libgrpcwrapper_connectioninstance.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace Impl {
100100

101101
std::shared_ptr<google::protobuf::Message> createMessage(const std::string& sMessageTypeName);
102102

103-
grpc::ByteBuffer sendMessageBlocking (std::shared_ptr<google::protobuf::Message> pMessage, const std::string & sServiceMethod, uint32_t nTimeoutInMS);
103+
grpc::ByteBuffer sendMessageBlocking (google::protobuf::Message* pMessage, const std::string & sServiceMethod, uint32_t nTimeoutInMS);
104104
};
105105

106106
} // namespace Impl

0 commit comments

Comments
 (0)