From ae77f0f97f70a6d3bef0faee0b7db27fb5e2849f Mon Sep 17 00:00:00 2001 From: rtrimana Date: Fri, 9 Dec 2016 09:40:46 -0800 Subject: [PATCH] Fixing a bug in C++ socket server-client: message length was represented just in 1 byte - this is not enough for sending longer messages (just enough to represent up to ~126 bytes/8-bit representation) - now it's changed to 4 bytes (integer size) --- config/iotpolicy/testclasspolicy_advanced.pol | 11 + iotjava/iotpolicy/IoTCompiler.java | 217 ++++-------------- iotjava/iotrmi/C++/IoTRMICall.hpp | 2 + iotjava/iotrmi/C++/IoTRMIObject.hpp | 2 +- iotjava/iotrmi/C++/IoTSocket.hpp | 13 +- iotjava/iotrmi/C++/basics/TestClass.hpp | 78 +++++++ .../C++/basics/TestClassAdvanced_Stub.cpp | 31 ++- iotjava/iotrmi/Java/basics/TestClass.java | 69 ++++++ .../Java/basics/TestClassAdvanced_Stub.java | 29 ++- 9 files changed, 268 insertions(+), 184 deletions(-) diff --git a/config/iotpolicy/testclasspolicy_advanced.pol b/config/iotpolicy/testclasspolicy_advanced.pol index 9867b23..b7899df 100644 --- a/config/iotpolicy/testclasspolicy_advanced.pol +++ b/config/iotpolicy/testclasspolicy_advanced.pol @@ -5,11 +5,14 @@ public interface TestClassInterface { public List handleEnumList(List en); public Enum handleEnumComplex(Enum en, int i, char c); public Enum[] handleEnumComplex2(Enum en[], int in, char c); + public Enum[] handleEnumTwo(Enum en1[], Enum en2[]); public Struct handleStruct(Struct str); public Struct[] handleStructArray(Struct str[]); public List handleStructList(List str); public Struct handleStructComplex(int in, char c, Struct str); + public List handleStructTwo(List str1, List str2); + public List handleStructThree(List str1, List str2, List str3); public List handleStructComplex2(int in, char c, Struct str[]); public Enum[] handleEnumStruct(Enum en[], List str, char c); @@ -21,7 +24,10 @@ public interface TestClassInterface { public int callBack(); public Enum[] handleCallbackEnum(Enum en[], char c, List _cb); + public Enum[] handleAll(Enum en[], List str, char c, List _cb); + public Enum[] handleAllTwo(Enum en1[], Enum en2[], List str1, List str2, char c, List _cb1, List _cb2); + public Enum[] handleEnumThree(Enum en1[], Enum en2[], List str1, List str2); capability EnumsStructs { description = "All the set methods"; @@ -31,16 +37,21 @@ public interface TestClassInterface { method = "handleEnumList(List en)"; method = "handleEnumComplex(Enum en, int i, char c)"; method = "handleEnumComplex2(Enum en[], int in, char c)"; + method = "handleEnumTwo(Enum en1[], Enum en2[])"; + method = "handleEnumThree(Enum en1[], Enum en2[], List str1, List str2)"; method = "handleStruct(Struct str)"; method = "handleStructArray(Struct str[])"; method = "handleStructList(List str)"; method = "handleStructComplex(int in, char c, Struct str)"; method = "handleStructComplex2(int in, char c, Struct str[])"; + method = "handleStructTwo(List str1, List str2)"; + method = "handleStructThree(List str1, List str2, List str3)"; method = "handleEnumStruct(Enum en[], List str, char c)"; method = "handleCallbackEnum(Enum en[], char c, List _cb)"; method = "handleAll(Enum en[], List str, char c, List _cb)"; + method = "handleAllTwo(Enum en1[], Enum en2[], List str1, List str2, char c, List _cb1, List _cb2)"; } capability Callbacks { diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index 1bd90c6..3187637 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -943,66 +943,6 @@ public class IoTCompiler { } - /*private void writeStdMethodBodyJavaStub(InterfaceDecl intDecl, List methParams, - List methPrmTypes, String method) { - - checkAndWriteStructSetupJavaStub(methParams, methPrmTypes, intDecl, method); - println("int methodId = " + intDecl.getMethodNumId(method) + ";"); - String retType = intDecl.getMethodType(method); - println("Class retType = " + getSimpleType(getStructType(getEnumType(retType))) + ".class;"); - checkAndWriteEnumTypeJavaStub(methParams, methPrmTypes); - // Generate array of parameter types - if (isStructPresent(methParams, methPrmTypes)) { - writeStructParamClassJavaStub(methParams, methPrmTypes); - } else { - print("Class[] paramCls = new Class[] { "); - for (int i = 0; i < methParams.size(); i++) { - String paramType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i)); - print(getSimpleType(getEnumType(paramType)) + ".class"); - // Check if this is the last element (don't print a comma) - if (i != methParams.size() - 1) { - print(", "); - } - } - println(" };"); - // Generate array of parameter objects - print("Object[] paramObj = new Object[] { "); - for (int i = 0; i < methParams.size(); i++) { - print(getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i)); - // Check if this is the last element (don't print a comma) - if (i != methParams.size() - 1) { - print(", "); - } - } - println(" };"); - } - // Check if this is "void" - if (retType.equals("void")) { - println("rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);"); - } else { // We do have a return value - // Generate array of parameter types - if (isStructClass(getGenericType(getSimpleArrayType(retType)))) { - writeStructReturnJavaStub(getGenericType(getSimpleArrayType(retType)), retType); - } else { - // This is an enum type - if (getParamCategory(getGenericType(getSimpleArrayType(retType))) == ParamCategory.ENUM) { - println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);"); - checkAndWriteEnumRetTypeJavaStub(retType); - } else if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES) { - // Check if the return value NONPRIMITIVES - String retGenValType = getGenericType(retType); - println("Class retGenValType = " + retGenValType + ".class;"); - println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, retGenValType, paramCls, paramObj);"); - println("return (" + retType + ")retObj;"); - } else { - println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);"); - println("return (" + retType + ")retObj;"); - } - } - } - }*/ - - /** * HELPER: returnGenericCallbackType() returns the callback type */ @@ -1483,7 +1423,6 @@ public class IoTCompiler { String paramType = methPrmTypes.get(i); String param = methParams.get(i); if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object - println("try {"); String exchParamType = checkAndGetParamClass(getGenericType(paramType)); // Print array if this is array or list if this is a list of callback objects if (isArray(param)) { @@ -1521,17 +1460,24 @@ public class IoTCompiler { /** * HELPER: checkAndWriteEnumTypeJavaSkeleton() writes the enum type (convert from enum to int) */ - private void checkAndWriteEnumTypeJavaSkeleton(List methParams, List methPrmTypes) { + private void checkAndWriteEnumTypeJavaSkeleton(List methParams, List methPrmTypes, boolean isStructMethod) { + String offsetPfx = ""; + if (isStructMethod) + offsetPfx = "offset"; // Iterate and find enum declarations + boolean printed = false; for (int i = 0; i < methParams.size(); i++) { String paramType = methPrmTypes.get(i); String param = methParams.get(i); String simpleType = getGenericType(paramType); if (isEnumClass(simpleType)) { // Check if this is enum type - println("int paramInt" + i + "[] = (int[]) paramObj[" + i + "];"); - println(simpleType + "[] enumVals = " + simpleType + ".values();"); + println("int paramInt" + i + "[] = (int[]) paramObj[" + offsetPfx + i + "];"); + if (!printed) { + println(simpleType + "[] enumVals = " + simpleType + ".values();"); + printed = true; + } if (isArray(param)) { // An array println("int len" + i + " = paramInt" + i + ".length;"); println(simpleType + "[] paramEnum" + i + " = new " + simpleType + "[len" + i + "];"); @@ -1790,9 +1736,10 @@ public class IoTCompiler { List methPrmTypes, String method, boolean isCallbackMethod, String callbackType, boolean isStructMethod) { - checkAndWriteEnumTypeJavaSkeleton(methParams, methPrmTypes); + checkAndWriteEnumTypeJavaSkeleton(methParams, methPrmTypes, isStructMethod); Map mapStubParam = null; if (isCallbackMethod) { + println("try {"); mapStubParam = writeCallbackJavaStubGeneration(methParams, methPrmTypes, callbackType, isStructMethod); } // Check if this is "void" @@ -1965,9 +1912,10 @@ public class IoTCompiler { String param = methParams.get(i); String simpleType = getGenericType(paramType); if (isStructClass(simpleType)) { - if (!begin) { // Generate comma for not the beginning variable - print(", "); begin = false; - } + if (!begin) // Generate comma for not the beginning variable + print(", "); + else + begin = false; int methodNumId = intDecl.getMethodNumId(method); print("int struct" + methodNumId + "Size" + i); } @@ -2097,17 +2045,18 @@ public class IoTCompiler { List methParams = intDecl.getMethodParams(method); List methPrmTypes = intDecl.getMethodParamTypes(method); boolean structExist = false; + boolean begin = true; // Check for params with structs for (int i = 0; i < methParams.size(); i++) { String paramType = methPrmTypes.get(i); String param = methParams.get(i); String simpleType = getGenericType(paramType); - boolean begin = true; if (isStructClass(simpleType)) { structExist = true; - if (!begin) { - print(", "); begin = false; - } + if (!begin) + print(", "); + else + begin = false; int methodNumId = intDecl.getMethodNumId(method); print("struct" + methodNumId + "Size" + i); } @@ -2341,9 +2290,10 @@ public class IoTCompiler { String param = methParams.get(i); String simpleType = getGenericType(paramType); if (isStructClass(simpleType)) { - if (!begin) { // Generate comma for not the beginning variable - print(", "); begin = false; - } + if (!begin) // Generate comma for not the beginning variable + print(", "); + else + begin = false; int methodNumId = intDecl.getMethodNumId(method); print("int struct" + methodNumId + "Size" + i); } @@ -2724,7 +2674,6 @@ public class IoTCompiler { println(") { "); if (isCallbackMethod) writeCallbackMethodBodyCplusStub(intDecl, methParams, methPrmTypes, method, callbackType); - //else writeStdMethodBodyCplusStub(intDecl, methParams, methPrmTypes, method, callbackType, isCallbackMethod); println("}\n"); // Write the init callback helper method @@ -2762,90 +2711,14 @@ public class IoTCompiler { println("vecCallbackObj.push_back(skel" + i + ");"); if (isArrayOrList) println("}"); - } - } - print("int ___paramCB = "); - if (isArrayOrList) - println(callbackParam + ".size();"); - else - println("1;"); - } - -/* private void writeCallbackMethodBodyCplusStub(InterfaceDecl intDecl, List methParams, - List methPrmTypes, String method, String callbackType) { - - // Check if this is single object, array, or list of objects - boolean isArrayOrList = false; - String callbackParam = null; - for (int i = 0; i < methParams.size(); i++) { - - String paramType = methPrmTypes.get(i); - if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object - String param = methParams.get(i); - if (isArrayOrList(paramType, param)) { // Generate loop - println("for (" + getGenericType(paramType) + "* cb : " + getSimpleIdentifier(param) + ") {"); - println(callbackType + "_CallbackSkeleton* skel = new " + callbackType + "_CallbackSkeleton(cb, objIdCnt++);"); - isArrayOrList = true; - callbackParam = getSimpleIdentifier(param); - } else - println(callbackType + "_CallbackSkeleton* skel = new " + callbackType + "_CallbackSkeleton(" + - getSimpleIdentifier(param) + ", objIdCnt++);"); - println("vecCallbackObj.push_back(skel);"); + print("int ___paramCB" + i + " = "); if (isArrayOrList) - println("}"); - } - } - println("int numParam = " + methParams.size() + ";"); - println("int methodId = " + intDecl.getMethodNumId(method) + ";"); - String retType = intDecl.getMethodType(method); - //String retTypeC = checkAndGetCplusType(retType); - //println("string retType = \"" + checkAndGetCplusArrayType(getStructType(getEnumType(retTypeC))) + "\";"); - println("string retType = \"" + checkAndGetCplusRetClsType(getStructType(getEnumType(retType))) + "\";"); - // Generate array of parameter types - print("string paramCls[] = { "); - for (int i = 0; i < methParams.size(); i++) { - String paramType = methPrmTypes.get(i); - if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object - print("\"int\""); - } else { // Generate normal classes if it's not a callback object - String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i)); - print("\"" + paramTypeC + "\""); + println(callbackParam + ".size();"); + else + println("1;"); } - if (i != methParams.size() - 1) // Check if this is the last element - print(", "); } - println(" };"); - print("int ___paramCB = "); - if (isArrayOrList) - println(callbackParam + ".size();"); - else - println("1;"); - // Generate array of parameter objects - print("void* paramObj[] = { "); - for (int i = 0; i < methParams.size(); i++) { - String paramType = methPrmTypes.get(i); - if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object - print("&___paramCB"); - } else - print("&" + getSimpleIdentifier(methParams.get(i))); - if (i != methParams.size() - 1) - print(", "); - } - println(" };"); - // Check if this is "void" - if (retType.equals("void")) { - println("void* retObj = NULL;"); - println("rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);"); - } else { // We do have a return value - if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES) - println(checkAndGetCplusType(retType) + " retVal;"); - else - println(checkAndGetCplusType(retType) + " retVal = " + generateCplusInitializer(retType) + ";"); - println("void* retObj = &retVal;"); - println("rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);"); - println("return retVal;"); - } - }*/ + } /** @@ -3017,7 +2890,7 @@ public class IoTCompiler { writeStructMembersCplusStub(simpleType, paramType, param); } else if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object println("paramCls[pos] = \"int\";"); - println("paramObj[pos++] = &___paramCB;"); + println("paramObj[pos++] = &___paramCB" + i + ";"); } else { String prmTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i)); println("paramCls[pos] = \"" + prmTypeC + "\";"); @@ -3153,7 +3026,7 @@ public class IoTCompiler { for (int i = 0; i < methParams.size(); i++) { String paramType = returnGenericCallbackType(methPrmTypes.get(i)); if (checkCallbackType(paramType, callbackType)) // Check if this has callback object - print("&___paramCB"); + print("&___paramCB" + i); else print("&" + getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i)); // Check if this is the last element (don't print a comma) @@ -4000,13 +3873,13 @@ public class IoTCompiler { for (int i = 0; i < members.size(); i++) { String prmTypeC = checkAndGetCplusType(memTypes.get(i)); String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i)); - println(getSimpleType(getEnumType(prmType)) + " param" + i + "[" + counter + "];"); + println(getSimpleType(getEnumType(prmType)) + " param" + iVar + i + "[" + counter + "];"); } } else { // Just one struct element for (int i = 0; i < members.size(); i++) { String prmTypeC = checkAndGetCplusType(memTypes.get(i)); String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i)); - println(getSimpleType(getEnumType(prmType)) + " param" + i + ";"); + println(getSimpleType(getEnumType(prmType)) + " param" + iVar + i + ";"); } } if (isArrayOrList(paramType, param)) { // An array or list @@ -4016,14 +3889,14 @@ public class IoTCompiler { for (int i = 0; i < members.size(); i++) { String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i)); println("paramCls[pos] = \"" + prmTypeC + "\";"); - println("paramObj[pos++] = ¶m" + i + "[i];"); + println("paramObj[pos++] = ¶m" + iVar + i + "[i];"); } println("}"); } else { // Just one struct element for (int i = 0; i < members.size(); i++) { String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i)); println("paramCls[pos] = \"" + prmTypeC + "\";"); - println("paramObj[pos++] = ¶m" + i + ";"); + println("paramObj[pos++] = ¶m" + iVar + i + ";"); } } } @@ -4055,13 +3928,13 @@ public class IoTCompiler { println("for(int i = 0; i < " + counter + "; i++) {"); for (int j = 0; j < members.size(); j++) { print("paramStruct" + i + "[i]." + getSimpleIdentifier(members.get(j))); - println(" = param" + j + "[i];"); + println(" = param" + i + j + "[i];"); } println("}"); } else { // Just one struct element for (int j = 0; j < members.size(); j++) { print("paramStruct" + i + "." + getSimpleIdentifier(members.get(j))); - println(" = param" + j + ";"); + println(" = param" + i + j + ";"); } } } @@ -4193,9 +4066,10 @@ public class IoTCompiler { String param = methParams.get(i); String simpleType = getGenericType(paramType); if (isStructClass(simpleType)) { - if (!begin) { // Generate comma for not the beginning variable - print(", "); begin = false; - } + if (!begin) // Generate comma for not the beginning variable + print(", "); + else + begin = false; int methodNumId = intDecl.getMethodNumId(method); print("int struct" + methodNumId + "Size" + i); } @@ -4508,9 +4382,10 @@ public class IoTCompiler { String param = methParams.get(i); String simpleType = getGenericType(paramType); if (isStructClass(simpleType)) { - if (!begin) { // Generate comma for not the beginning variable - print(", "); begin = false; - } + if (!begin) // Generate comma for not the beginning variable + print(", "); + else + begin = false; int methodNumId = intDecl.getMethodNumId(method); print("int struct" + methodNumId + "Size" + i); } diff --git a/iotjava/iotrmi/C++/IoTRMICall.hpp b/iotjava/iotrmi/C++/IoTRMICall.hpp index a630798..99dd56d 100644 --- a/iotjava/iotrmi/C++/IoTRMICall.hpp +++ b/iotjava/iotrmi/C++/IoTRMICall.hpp @@ -91,6 +91,8 @@ void* IoTRMICall::remoteCall(int objectId, int methodId, string retType, string methodToBytes(objectId, methodId, paramCls, paramObj, method, numParam); // Send bytes fflush(NULL); + cout << "Length: " << len << endl; + IoTRMIUtil::printBytes(method, len, false); rmiClient->sendBytes(method, len); fflush(NULL); // Receive return value and return it to caller diff --git a/iotjava/iotrmi/C++/IoTRMIObject.hpp b/iotjava/iotrmi/C++/IoTRMIObject.hpp index f7b9642..1dd3d57 100644 --- a/iotjava/iotrmi/C++/IoTRMIObject.hpp +++ b/iotjava/iotrmi/C++/IoTRMIObject.hpp @@ -121,7 +121,7 @@ void IoTRMIObject::sendReturnObj(void* retObj[], string type[], int numRet) { char* IoTRMIObject::getMethodBytes() { // Get method in bytes and update method length - //fflush(NULL); + fflush(NULL); methodBytes = rmiServer->receiveBytes(methodBytes, &methodLen); fflush(NULL); return methodBytes; diff --git a/iotjava/iotrmi/C++/IoTSocket.hpp b/iotjava/iotrmi/C++/IoTSocket.hpp index 642882f..cf62ec1 100644 --- a/iotjava/iotrmi/C++/IoTSocket.hpp +++ b/iotjava/iotrmi/C++/IoTSocket.hpp @@ -17,6 +17,9 @@ #define DEBUG_ACK static const int SOCKET_BUFF_SIZE = 64000; +// Before, it was too short as we were just using 1 byte to receive the length +// Now, we allocate 4 bytes (a size of integer) to receive the message length +static const int MSG_LEN_SIZE = 4; #include #include @@ -92,7 +95,7 @@ bool IoTSocket::sendBytes(char* pVals, int _iLen) { int iLen = _iLen; size[0] = iLen; - if (send(m_iSock, size, 1, 0) == -1) { + if (send(m_iSock, size, MSG_LEN_SIZE, 0) == -1) { perror("IoTSocket: Send size error!"); return false; } @@ -125,16 +128,18 @@ char* IoTSocket::receiveBytes(char* pVals, int* len) int iTotal = 0; int iResult = 0; - char size[1]; + int size[1]; + while ((iTotal < 1) && (iResult != -1)) { - iResult = recv(m_iSock, size, 1, 0); + iResult = recv(m_iSock, size, MSG_LEN_SIZE, 0); iTotal += iResult; } if (iResult == -1) { perror("IoTSocket: Receive size error!"); return NULL; } - int iLen = (int) size[0]; + int iLen = size[0]; + // To be returned from this method... *len = iLen; pVals = new char[iLen]; diff --git a/iotjava/iotrmi/C++/basics/TestClass.hpp b/iotjava/iotrmi/C++/basics/TestClass.hpp index a052c0d..573ff64 100644 --- a/iotjava/iotrmi/C++/basics/TestClass.hpp +++ b/iotjava/iotrmi/C++/basics/TestClass.hpp @@ -52,6 +52,8 @@ class TestClass : public TestClassInterface { vector handleEnumList(vector vecEn); Enum handleEnumComplex(Enum en, int i, char c); vector handleEnumComplex2(vector en, int i, char c); + vector handleEnumTwo(vector en1, vector en2); + vector handleEnumThree(vector en1, vector en2, vector str1, vector str2); // Struct Struct handleStruct(Struct str); @@ -59,9 +61,13 @@ class TestClass : public TestClassInterface { vector handleStructList(vector vecStr); Struct handleStructComplex(int in, char c, Struct str); vector handleStructComplex2(int in, char c, vector vecStr); + vector handleStructTwo(vector str1, vector str2); + vector handleStructThree(vector str1, vector str2, vector str3); vector handleEnumStruct(vector en, vector str, char c); vector handleAll(vector en, vector str, char c, vector _cb); + vector handleAllTwo(vector en1, vector en2, vector str1, vector str2, char c, + vector _cb1, vector _cb2); int getA(); void setA(int _int); @@ -348,6 +354,32 @@ vector TestClass::handleEnumComplex2(vector vecEn, int in, char c) { } +vector TestClass::handleEnumTwo(vector en1, vector en2) { + + for (Enum en : en1) { + cout << "Enum1: " << en << endl; + } + for (Enum en : en2) { + cout << "Enum2: " << en << endl; + } + + return en1; +} + + +vector TestClass::handleEnumThree(vector en1, vector en2, vector str1, vector str2) { + + for (Enum en : en1) { + cout << "Enum1: " << en << endl; + } + for (Enum en : en2) { + cout << "Enum2: " << en << endl; + } + + return en1; +} + + // Struct Struct TestClass::handleStruct(Struct str) { @@ -402,6 +434,32 @@ vector TestClass::handleStructList(vector vecStr) { } +vector TestClass::handleStructTwo(vector str1, vector str2) { + + for (Struct str : str1) { + + cout << "Name: " << str.name << endl; + cout << "Value: " << str.value << endl; + cout << "Year: " << str.year << endl; + } + + return str2; +} + + +vector TestClass::handleStructThree(vector str1, vector str2, vector str3) { + + for (Struct str : str1) { + + cout << "Name: " << str.name << endl; + cout << "Value: " << str.value << endl; + cout << "Year: " << str.year << endl; + } + + return str2; +} + + Struct TestClass::handleStructComplex(int in, char c, Struct str) { cout << "Name: " << str.name << endl; @@ -469,6 +527,26 @@ vector TestClass::handleAll(vector en, vector str, char c, v } +vector TestClass::handleAllTwo(vector en1, vector en2, vector str1, vector str2, char c, + vector _cb1, vector _cb2) { + + for (CallBackInterfaceWithCallBack* cb : _cb1) { + cbvec.push_back(cb); + cout << "Registering callback object in array!" << endl; + } + + for (Struct st : str1) { + cout << "Name: " << st.name << endl; + cout << "Value: " << st.value << endl; + cout << "Year: " << st.year << endl; + } + + cout << "Char: " << c << endl; + + return en1; +} + + vector TestClass::handleCallbackEnum(vector en, char c, vector _cb) { for (CallBackInterfaceWithCallBack* cb : _cb) { diff --git a/iotjava/iotrmi/C++/basics/TestClassAdvanced_Stub.cpp b/iotjava/iotrmi/C++/basics/TestClassAdvanced_Stub.cpp index 8e23210..e224bca 100644 --- a/iotjava/iotrmi/C++/basics/TestClassAdvanced_Stub.cpp +++ b/iotjava/iotrmi/C++/basics/TestClassAdvanced_Stub.cpp @@ -80,11 +80,11 @@ int main(int argc, char *argv[]) cout << "Name: " << st.name << endl; cout << "Value:" << st.value << endl; cout << "Year" << st.year << endl; - }*/ + } vector vecRes4 = tcStub->handleEnumStruct(vecEn, vecStr, 'c'); for (Enum en : vecRes4) { cout << "Enum value: " << en << endl; - } + }*/ /* cout << "==== CALLBACK ====" << endl; CallBackInterface *cbSingle = new CallBack(2354); @@ -113,11 +113,36 @@ int main(int argc, char *argv[]) vector vecRes5 = tcStub->handleAll(vecEn, vecStr, 'c', cblist); for (Enum en : vecRes5) { cout << "Enum value: " << en << endl; - }*/ + } vector vecRes6 = tcStub->handleCallbackEnum(vecEn, 'c', cblist); for (Enum en : vecRes6) { cout << "Enum value: " << en << endl; + }*/ + //vector vecRes7 = tcStub->handleAllTwo(vecEn, vecStr, vecStr, vecEn, 'c', cblist, cblist); + /*vector vecRes7 = tcStub->handleAllTwo(vecEn, vecEn, vecStr, vecStr, 'c', cblist, cblist); + for (Enum en : vecRes7) { + cout << "Enum value: " << en << endl; + } + vector vecRes8 = tcStub->handleEnumTwo(vecEn, vecEn); + for (Enum en : vecRes8) { + cout << "Enum value: " << en << endl; + } + vector vecRes9 = tcStub->handleEnumThree(vecEn, vecEn, vecStr, vecStr); + for (Enum en : vecRes9) { + cout << "Enum value: " << en << endl; + } + vector vecRetStr2 = tcStub->handleStructTwo(vecStr, vecStr); + for (Struct st : vecRetStr2) { + cout << "Name: " << st.name << endl; + cout << "Value:" << st.value << endl; + cout << "Year" << st.year << endl; + }*/ + vector vecRetStr3 = tcStub->handleStructThree(vecStr, vecStr, vecStr); + for (Struct st : vecRetStr3) { + cout << "Name: " << st.name << endl; + cout << "Value:" << st.value << endl; + cout << "Year" << st.year << endl; } return 0; diff --git a/iotjava/iotrmi/Java/basics/TestClass.java b/iotjava/iotrmi/Java/basics/TestClass.java index 411e7db..1bfe8e2 100644 --- a/iotjava/iotrmi/Java/basics/TestClass.java +++ b/iotjava/iotrmi/Java/basics/TestClass.java @@ -288,6 +288,32 @@ public class TestClass implements TestClassInterface { } + public Enum[] handleEnumTwo(Enum en1[], Enum en2[]) { + + for (Enum e : en1) { + System.out.println("Enum1: " + e); + } + for (Enum e : en2) { + System.out.println("Enum2: " + e); + } + + return en1; + } + + + public Enum[] handleEnumThree(Enum en1[], Enum en2[], List str1, List str2) { + + for (Enum e : en1) { + System.out.println("Enum1: " + e); + } + for (Enum e : en2) { + System.out.println("Enum2: " + e); + } + + return en1; + } + + // Struct public Struct handleStruct(Struct str) { @@ -394,6 +420,30 @@ public class TestClass implements TestClassInterface { } + public List handleStructTwo(List str1, List str2) { + + for (Struct st : str1) { + System.out.println("Name: " + st.name); + System.out.println("Value: " + st.value); + System.out.println("Year: " + st.year); + } + + return str1; + } + + + public List handleStructThree(List str1, List str2, List str3) { + + for (Struct st : str1) { + System.out.println("Name: " + st.name); + System.out.println("Value: " + st.value); + System.out.println("Year: " + st.year); + } + + return str2; + } + + public Enum[] handleAll(Enum en[], List str, char c, List _cb) { for (CallBackInterfaceWithCallBack cb : _cb) { @@ -426,6 +476,25 @@ public class TestClass implements TestClassInterface { } + public Enum[] handleAllTwo(Enum en1[], Enum en2[], List str1, List str2, char c, List _cb1, List _cb2) { + + for (CallBackInterfaceWithCallBack cb : _cb1) { + cblist.add(cb); + System.out.println("Registering callback objects in list!"); + } + + for (Struct st : str1) { + System.out.println("Name: " + st.name); + System.out.println("Value: " + st.value); + System.out.println("Year: " + st.year); + } + + System.out.println("Char: " + c); + + return en1; + } + + // Getters public String sumArray(String[] newA) { diff --git a/iotjava/iotrmi/Java/basics/TestClassAdvanced_Stub.java b/iotjava/iotrmi/Java/basics/TestClassAdvanced_Stub.java index 759d3a6..d40bda6 100644 --- a/iotjava/iotrmi/Java/basics/TestClassAdvanced_Stub.java +++ b/iotjava/iotrmi/Java/basics/TestClassAdvanced_Stub.java @@ -46,20 +46,20 @@ public class TestClassAdvanced_Stub { Struct strRes2 = tcstub.handleStructComplex(23, 'c', str); System.out.println("Name: " + strRes2.name); System.out.println("Value: " + strRes2.value); - System.out.println("Year: " + strRes2.year); + System.out.println("Year: " + strRes2.year);*/ Struct str2 = new Struct(); str2.name = "Trimananda"; str2.value = 0.124f; str2.year = 2017; Struct[] arrStr = { str, str2 }; - Struct[] arrRet = tcstub.handleStructArray(arrStr); +/* Struct[] arrRet = tcstub.handleStructArray(arrStr); for(Struct st : arrRet) { System.out.println("Name: " + st.name); System.out.println("Value: " + st.value); System.out.println("Year: " + st.year); - } + }*/ List stList = new ArrayList(Arrays.asList(arrStr)); - List stRetList = tcstub.handleStructList(stList); +/* List stRetList = tcstub.handleStructList(stList); for(Struct st : stRetList) { System.out.println("Name: " + st.name); System.out.println("Value: " + st.value); @@ -94,9 +94,28 @@ public class TestClassAdvanced_Stub { /* tcstub.registerCallbackComplex(23, cblist, 0.1234); System.out.println("Return value from callback: " + tcstub.callBack()); Enum[] resArr4 = tcstub.handleAll(enArr, stList, 'c', cblist); - System.out.println("Enum members: " + Arrays.toString(resArr4));*/ + System.out.println("Enum members: " + Arrays.toString(resArr4)); Enum[] resArr5 = tcstub.handleCallbackEnum(enArr, 'c', cblist); System.out.println("Enum members: " + Arrays.toString(resArr5)); + //Enum[] resArr6 = tcstub.handleAllTwo(enArr, stList, stList, enArr, 'c', cblist, cblist); +// Enum[] resArr6 = tcstub.handleAllTwo(enArr, enArr, stList, stList, 'c', cblist, cblist); +// System.out.println("Enum members: " + Arrays.toString(resArr6)); + Enum[] resArr7 = tcstub.handleEnumTwo(enArr, enArr); + System.out.println("Enum members: " + Arrays.toString(resArr7)); + Enum[] resArr8 = tcstub.handleEnumThree(enArr, enArr, stList, stList); + System.out.println("Enum members: " + Arrays.toString(resArr8)); + List stRetList2 = tcstub.handleStructTwo(stList, stList); + for(Struct st : stRetList2) { + System.out.println("Name: " + st.name); + System.out.println("Value: " + st.value); + System.out.println("Year: " + st.year); + }*/ + List stRetList3 = tcstub.handleStructThree(stList, stList, stList); + for(Struct st : stRetList3) { + System.out.println("Name: " + st.name); + System.out.println("Value: " + st.value); + System.out.println("Year: " + st.year); + } } } -- 2.34.1