int retLen = 0;
char* retObjBytes = NULL;
retObjBytes = rmiClient->receiveBytes(retObjBytes, &retLen);
+ IoTRMIUtil::printBytes(retObjBytes, retLen, false);
retObj = IoTRMIUtil::getParamObject(retObj, retType.c_str(), retObjBytes, retLen);
}
// Find the parameter length
int paramLen = rmiUtil->getTypeSize(paramCls[i]);
if (paramLen == -1) { // Store the length of the field - indefinite length
- if (paramCls[i].compare("string") == 0) {
- // Get the length of the string through void* casting to string*
- paramLen = (*(string*)paramObj[i]).length();
- } else if (paramCls[i].compare("string[]") == 0) {
- paramLen = IoTRMIUtil::getByteStringLength(*(vector<string>*) paramObj[i]);
- } else {
- string error = "IoTRMICall: Unrecognizable type: " + paramCls[i];
- throw error;
- }
+ paramLen = rmiUtil->getVarTypeSize(paramCls[i], paramObj[i]);
// Some space for param length, i.e. 32 bits for integer
methodLen = methodLen + IoTRMIUtil::PARAM_LEN;
}
// Find the parameter length
int paramLen = rmiUtil->getTypeSize(paramCls[i]);
if (paramLen == -1) { // Store the length of the field - indefinite length
- if (paramCls[i].compare("string") == 0) {
- // Get the length of the string through void* casting to string*
- paramLen = (*(string*)paramObj[i]).length();
- } else if (paramCls[i].compare("string[]") == 0) {
- paramLen = IoTRMIUtil::getByteStringLength(*(vector<string>*) paramObj[i]);
- } else {
- string error = "IoTRMICall: Unrecognizable type: " + paramCls[i];
- throw error;
- }
+ paramLen = rmiUtil->getVarTypeSize(paramCls[i], paramObj[i]);
// Write the parameter length
char prmLenBytes[IoTRMIUtil::METHOD_ID_LEN];
IoTRMIUtil::intToByteArray(paramLen, prmLenBytes);
// Find the length of return object in bytes
int retLen = rmiUtil->getTypeSize(type);
if (retLen == -1) {
- if (type.compare("string") == 0) {
- // Get the length of the string through void* casting to string*
- retLen = (*(string*)retObj).length();
- } else if (type.compare("string[]") == 0) {
- retLen = IoTRMIUtil::getByteStringLength(*(vector<string>*) retObj);
- } else {
- string error = "IoTRMICall: Unrecognizable type: " + type;
- throw error;
- }
+ retLen = rmiUtil->getVarTypeSize(type, retObj);
}
// Need object bytes variable
char retObjBytes[retLen];
/**
- * Primitive sizes in Java - Long is 8 bytes and char is 2 bytes
+ * Primitive sizes in Java/C++
*/
- const static int primitivesJavaSizes[NUM_PRIMITIVES];
-
-
- /**
- * Primitive sizes in Cplus - Long is 4 bytes and char is 1 byte
- */
- const static int primitivesCplusSizes[NUM_PRIMITIVES];
+ const static int primitivesSizes[NUM_PRIMITIVES];
/**
};
-const int IoTRMITypes::primitivesJavaSizes[IoTRMITypes::NUM_PRIMITIVES] = {
-
- 1, 1, 2, 2, 4, 4, 8, 8, 4, 4, 8, 8, 1, 1, 2, 2, -1, -1, 0
-};
-
-
-const int IoTRMITypes::primitivesCplusSizes[IoTRMITypes::NUM_PRIMITIVES] = {
+const int IoTRMITypes::primitivesSizes[IoTRMITypes::NUM_PRIMITIVES] = {
1, 1, 2, 2, 4, 4, 8, 8, 4, 4, 8, 8, 1, 1, 2, 2, -1, -1, 0
};
static int hashCode(string str);
static char* getHashCodeBytes(string methodSign, char* bytes);
int getTypeSize(string type);
+ int getVarTypeSize(string type, void* paramObj);
static int getArrStringLength(vector<string> arrString);
static int getByteStringLength(vector<string> arrString);
private:
map<string,string> mapPrimitives;
- map<string,int> mapPrimitiveSizesJava;
- map<string,int> mapPrimitiveSizesCplus;
+ map<string,int> mapPrimitiveSizes;
map<string,string> mapNonPrimitives;
};
IoTRMITypes::primitivesJava + sizeof(IoTRMITypes::primitivesJava)/sizeof(string));
std::vector<string> primCplus (IoTRMITypes::primitivesCplus,
IoTRMITypes::primitivesCplus + sizeof(IoTRMITypes::primitivesCplus)/sizeof(string));
- std::vector<int> primJavaSizes (IoTRMITypes::primitivesJavaSizes,
- IoTRMITypes::primitivesJavaSizes + sizeof(IoTRMITypes::primitivesJavaSizes)/sizeof(int));
- std::vector<int> primCplusSizes (IoTRMITypes::primitivesCplusSizes,
- IoTRMITypes::primitivesCplusSizes + sizeof(IoTRMITypes::primitivesCplusSizes)/sizeof(int));
+ std::vector<int> primSizes (IoTRMITypes::primitivesSizes,
+ IoTRMITypes::primitivesSizes + sizeof(IoTRMITypes::primitivesSizes)/sizeof(int));
std::vector<string> nonPrimJava (IoTRMITypes::nonPrimitivesJava,
IoTRMITypes::nonPrimitivesJava + sizeof(IoTRMITypes::nonPrimitivesJava)/sizeof(string));
std::vector<string> nonPrimCplus (IoTRMITypes::nonPrimitivesCplus,
// Write into maps
IoTRMITypes::arraysToMap(mapPrimitives, primJava, primCplus);
- IoTRMITypes::arraysToMap(mapPrimitiveSizesJava, primJava, primJavaSizes);
- IoTRMITypes::arraysToMap(mapPrimitiveSizesCplus, primJava, primCplusSizes);
+ IoTRMITypes::arraysToMap(mapPrimitiveSizes, primJava, primSizes);
IoTRMITypes::arraysToMap(mapNonPrimitives, nonPrimJava, nonPrimCplus);
}
int IoTRMIUtil::getTypeSize(string type) {
// Handle the types and find the sizes
- if (mapPrimitiveSizesCplus.find(type) != mapPrimitiveSizesCplus.end())
- return mapPrimitiveSizesCplus.find(type)->second;
+ if (mapPrimitiveSizes.find(type) != mapPrimitiveSizes.end())
+ return mapPrimitiveSizes.find(type)->second;
else
return -1; // Size is unknown
}
+// Get variable type size, e.g. strings, arrays, etc.
+int IoTRMIUtil::getVarTypeSize(string type, void* paramObj) {
+
+ int paramLen = 0;
+ if (type.compare("string") == 0) {
+ // Get the length of the string through void* casting to string*
+ paramLen = (*(string*)paramObj).length();
+ } else if (type.compare("string[]") == 0) {
+ paramLen = IoTRMIUtil::getByteStringLength(*(vector<string>*) paramObj);
+ } else if (type.compare("byte[]") == 0) {
+ int dataSize = getTypeSize("byte");
+ paramLen = (*(vector<char>*) paramObj).size() * dataSize;
+ } else if (type.compare("short[]") == 0) {
+ int dataSize = getTypeSize("short");
+ paramLen = (*(vector<short>*) paramObj).size() * dataSize;
+ } else if (type.compare("int[]") == 0) {
+ int dataSize = getTypeSize("int");
+ paramLen = (*(vector<int>*) paramObj).size() * dataSize;
+ } else if (type.compare("long[]") == 0) {
+ int dataSize = getTypeSize("long");
+ paramLen = (*(vector<int64_t>*) paramObj).size() * dataSize;
+ } else if (type.compare("float[]") == 0) {
+ int dataSize = getTypeSize("float");
+ paramLen = (*(vector<float>*) paramObj).size() * dataSize;
+ } else if (type.compare("double[]") == 0) {
+ int dataSize = getTypeSize("double");
+ paramLen = (*(vector<double>*) paramObj).size() * dataSize;
+ } else if (type.compare("bool[]") == 0) {
+ int dataSize = getTypeSize("bool");
+ paramLen = (*(vector<bool>*) paramObj).size() * dataSize;
+ } else if (type.compare("char[]") == 0) {
+ int dataSize = getTypeSize("char");
+ paramLen = (*(vector<char>*) paramObj).size() * dataSize;
+ } else {
+ string error = "IoTRMICall: Unrecognizable type: " + type;
+ throw error;
+ }
+
+ return paramLen;
+}
+
+
int IoTRMIUtil::getArrStringLength(vector<string> arrString) {
int len = 0;
TestClassInterface *tc = new TestClass();
cout << "Return value: " << tc->setAndGetA(123) << endl;
cout << "Return value: " << tc->setACAndGetA("string", 123) << endl;
- vector<string> input;
+ /*vector<string> input;
input.push_back("123");
input.push_back("456");
- input.push_back("987");
+ input.push_back("987");*/
+ vector<int> input;
+ input.push_back(123);
+ input.push_back(456);
+ input.push_back(987);
cout << "Return value: " << tc->sumArray(input) << endl;
void setA(int _int);
void setB(float _float);
void setC(string _string);
- string sumArray(vector<string> newA);
+ //string sumArray(vector<string> newA);
+ int64_t sumArray(vector<int> newA);
int setAndGetA(int newA);
int setACAndGetA(string newC, int newA);
//void registerCallback(CallBackInterface _cb);
}
-string TestClass::sumArray(vector<string> newA) {
+/*string TestClass::sumArray(vector<string> newA) {
string sum = "";
int len = newA.size();
sum = sum + newA[c];
}
return sum;
+}*/
+
+
+int64_t TestClass::sumArray(vector<int> newA) {
+
+ int64_t sum = 0;
+ int len = newA.size();
+ for(int c = 0; c < len; c++) {
+ sum = sum + newA[c];
+ }
+ return sum;
}
virtual void setA(int _int) = 0;
virtual void setB(float _float) = 0;
virtual void setC(string _string) = 0;
- virtual string sumArray(vector<string> newA) = 0;
+ //virtual string sumArray(vector<string> newA) = 0;
+ virtual int64_t sumArray(vector<int> newA) = 0;
virtual int setAndGetA(int newA) = 0;
virtual int setACAndGetA(string newC, int newA) = 0;
//virtual void registerCallback(CallBackInterface _cb);
"voidsetA(int)",
"voidsetB(float)",
"voidsetC(string)",
- "sumArray(string[])",
+ //"sumArray(string[])",
+ "sumArray(int[])",
"intsetAndGetA(int)",
"intsetACAndGetA(string,int)",
"intcallBack()",
void* paramObj[] = { ¶m1 };
rmiObj->getMethodParams(paramCls, numParam, paramObj);
tc->setC(param1);
- } else if (methodSign.compare("sumArray(string[])") == 0) {
+ /*} else if (methodSign.compare("sumArray(string[])") == 0) {
string paramCls[] = { "string[]" };
int numParam = 1;
vector<string> param1;
rmiObj->getMethodParams(paramCls, numParam, paramObj);
string retVal = tc->sumArray(param1);
void* retObj = &retVal;
- rmiObj->sendReturnObj(retObj, "string");
+ rmiObj->sendReturnObj(retObj, "string");*/
+ } else if (methodSign.compare("sumArray(int[])") == 0) {
+ string paramCls[] = { "int[]" };
+ int numParam = 1;
+ vector<int> param1;
+ void* paramObj[] = { ¶m1 };
+ rmiObj->getMethodParams(paramCls, numParam, paramObj);
+ int64_t retVal = tc->sumArray(param1);
+ void* retObj = &retVal;
+ rmiObj->sendReturnObj(retObj, "long");
} else if (methodSign.compare("intsetAndGetA(int)") == 0) {
string paramCls[] = { "int" };
int numParam = 1;
TestClassInterface *tcStub = new TestClass_Stub(port, address, rev, &bResult);
cout << "Return value: " << tcStub->setAndGetA(123) << endl;
cout << "Return value: " << tcStub->setACAndGetA("string", 123) << endl;
- vector<string> input;
+ /*vector<string> input;
input.push_back("123");
input.push_back("456");
- input.push_back("987");
+ input.push_back("987");*/
+ vector<int> input;
+ input.push_back(123);
+ input.push_back(456);
+ input.push_back(987);
cout << "Return value: " << tcStub->sumArray(input) << endl;
void setA(int _int);
void setB(float _float);
void setC(string _string);
- string sumArray(vector<string> newA);
+ //string sumArray(vector<string> newA);
+ int64_t sumArray(vector<int> newA);
int setAndGetA(int newA);
int setACAndGetA(string newC, int newA);
//void registerCallback(CallBackInterface _cb);
}
-string TestClass_Stub::sumArray(vector<string> newA) {
+/*string TestClass_Stub::sumArray(vector<string> newA) {
int numParam = 1;
string sign = "sumArray(string[])";
void* retObj = &retVal;
rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
return retVal;
+}*/
+
+
+int64_t TestClass_Stub::sumArray(vector<int> newA) {
+
+ int numParam = 1;
+ string sign = "sumArray(int[])";
+ string retType = "long";
+ string paramCls[] = { "int[]" };
+ void* paramObj[] = { &newA };
+ int64_t retVal = 0;
+ void* retObj = &retVal;
+ rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+ return retVal;
}
+
int TestClass_Stub::setAndGetA(int newA) {
int numParam = 1;