Testing struct (single object); fixing small bugs, etc.
authorrtrimana <rtrimana@uci.edu>
Thu, 1 Dec 2016 21:40:47 +0000 (13:40 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 1 Dec 2016 21:40:47 +0000 (13:40 -0800)
config/iotpolicy/testclasspolicy.pol
iotjava/iotpolicy/IoTCompiler.java
iotjava/iotrmi/C++/IoTRMIObject.hpp
iotjava/iotrmi/C++/basics/TestClass.hpp
iotjava/iotrmi/C++/basics/TestClass_Stub.cpp
iotjava/iotrmi/Java/basics/TestClass.java
iotjava/iotrmi/Java/basics/TestClass_Stub.java

index ddd86d8..3c03d53 100644 (file)
@@ -28,6 +28,8 @@ public interface TestClassInterface {
        public Enum[] handleEnumArray(Enum en[]);
        public List<Enum> handleEnumList(List<Enum> en);
 
+       public Struct handleStruct(Struct str);
+
        public int getA();
        public void setA(int _int);
        public void setB(float _float);
@@ -63,6 +65,9 @@ public interface TestClassInterface {
                method = "handleEnum(Enum en)";
                method = "handleEnumArray(Enum en[])";
                method = "handleEnumList(List<Enum> en)";
+
+               method = "handleStruct(Struct str)";
+
                method = "getA()";
                method = "setA(int _int)";
                method = "setB(float _float)";
index c28aeea..6555f9d 100644 (file)
@@ -1232,12 +1232,14 @@ public class IoTCompiler {
                                String simpleType = getSimpleType(paramType);
                                if (isStructClass(simpleType)) {
                                        int methodNumId = intDecl.getMethodNumId(method);
+                                       String helperMethod = methodNumId + "struct" + i;
+                                       int methodHelperNumId = intDecl.getHelperMethodNumId(helperMethod);
                                        // Iterate over interfaces to give permissions to
                                        Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
                                        for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
                                                String newIntface = intMeth.getKey();
                                                int newObjectId = getNewIntfaceObjectId(newIntface);
-                                               println("set" + newObjectId + "Allowed.add(" + methodNumId + ");");
+                                               println("set" + newObjectId + "Allowed.add(" + methodHelperNumId + ");");
                                        }
                                }
                        }
@@ -2166,7 +2168,6 @@ public class IoTCompiler {
                println("public " + newSkelClass + "(" + intface + " _mainObj, int _objectId) throws Exception {");
                println("mainObj = _mainObj;");
                println("objectId = _objectId;");
-               writeStructPermissionJavaSkeleton(methods, intDecl, intface);
                println("}\n");
        }
 
@@ -2442,6 +2443,7 @@ public class IoTCompiler {
                                // Write file headers
                                println("#ifndef _" + stType.toUpperCase() + "_HPP__");
                                println("#define _" + stType.toUpperCase() + "_HPP__");
+                               println("using namespace std;");
                                println("struct " + stType + " {");
                                List<String> structMemberTypes = structDecl.getMemberTypes(stType);
                                List<String> structMembers = structDecl.getMembers(stType);
@@ -2801,9 +2803,8 @@ public class IoTCompiler {
                }
                if (isArrayOrList(param, paramType)) {  // An array or list
                        for (int i = 0; i < members.size(); i++) {
-                               String prmTypeC = checkAndGetCplusType(memTypes.get(i));
-                               String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
-                               println("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+                               println("paramCls[pos] = \"" + prmTypeC + "\";");
                                print("paramObj[pos++] = &" + param + "[i].");
                                print(getSimpleIdentifier(members.get(i)));
                                println(";");
@@ -2811,9 +2812,8 @@ public class IoTCompiler {
                        println("}");
                } 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("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+                               println("paramCls[pos] = \"" + prmTypeC + "\";");
                                print("paramObj[pos++] = &" + param + ".");
                                print(getSimpleIdentifier(members.get(i)));
                                println(";");
@@ -2841,9 +2841,8 @@ public class IoTCompiler {
                        if (isStructClass(simpleType)) {
                                writeStructMembersCplusStub(simpleType, paramType, param);
                        } else {
-                               String prmTypeC = checkAndGetCplusType(methPrmTypes.get(i));
-                               String prmType = checkAndGetCplusArrayType(prmTypeC, methParams.get(i));
-                               println("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               String prmTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
+                               println("paramCls[pos] = \"" + prmTypeC + "\";");
                                print("paramObj[pos++] = &");
                                print(getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i));
                                println(";");
@@ -2919,17 +2918,15 @@ public class IoTCompiler {
                if (isArrayOrList(retType, retType)) {  // An array or list
                        println("for(int i = 0; i < retLen; i++) {");
                        for (int i = 0; i < members.size(); i++) {
-                               String prmTypeC = checkAndGetCplusType(memTypes.get(i));
-                               String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
-                               println("retCls[retPos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+                               println("retCls[retPos] = \"" + prmTypeC + "\";");
                                println("retObj[retPos++] = &retParam" + i + "[i];");
                        }
                        println("}");
                } 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("retCls[retPos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+                               println("retCls[retPos] = \"" + prmTypeC + "\";");
                                println("retObj[retPos++] = &retParam" + i + ";");
                        }
                }
@@ -3409,12 +3406,14 @@ public class IoTCompiler {
                                String simpleType = getSimpleType(paramType);
                                if (isStructClass(simpleType)) {
                                        int methodNumId = intDecl.getMethodNumId(method);
+                                       String helperMethod = methodNumId + "struct" + i;
+                                       int helperMethodNumId = intDecl.getHelperMethodNumId(helperMethod);
                                        // Iterate over interfaces to give permissions to
                                        Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
                                        for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
                                                String newIntface = intMeth.getKey();
                                                int newObjectId = getNewIntfaceObjectId(newIntface);
-                                               println("set" + newObjectId + "Allowed.insert(" + methodNumId + ");");
+                                               println("set" + newObjectId + "Allowed.insert(" + helperMethodNumId + ");");
                                        }
                                }
                        }
@@ -3636,7 +3635,7 @@ public class IoTCompiler {
                String pureType = getSimpleArrayType(getGenericType(retType));
                // Take the inner type of generic
                if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
-                       pureType = getTypeOfGeneric(retType)[0];
+                       pureType = getGenericType(retType);
                if (isEnumClass(pureType)) {
                // Check if this is enum type
                        // Enum decoder
@@ -3818,17 +3817,15 @@ public class IoTCompiler {
                if (isArrayOrList(param, paramType)) {  // An array or list
                        println("for(int i = 0; i < retLen; i++) {");
                        for (int i = 0; i < members.size(); i++) {
-                               String prmTypeC = checkAndGetCplusType(memTypes.get(i));
-                               String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
-                               println("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+                               println("paramCls[pos] = \"" + prmTypeC + "\";");
                                println("paramObj[pos++] = &param" + i + "[i];");
                        }
                        println("}");
                } 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("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+                               println("paramCls[pos] = \"" + prmTypeC + "\";");
                                println("paramObj[pos++] = &param" + i + ";");
                        }
                }
@@ -3899,9 +3896,8 @@ public class IoTCompiler {
                if (isArrayOrList(retType, retType)) {  // An array or list
                        println("for(int i = 0; i < retLen; i++) {");
                        for (int i = 0; i < members.size(); i++) {
-                               String paramTypeC = checkAndGetCplusType(memTypes.get(i));
-                               String prmType = checkAndGetCplusArrayType(paramTypeC, members.get(i));
-                               println("retCls[retPos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+                               println("retCls[retPos] = \"" + prmTypeC + "\";");
                                print("retObj[retPos++] = &retStruct[i].");
                                print(getEnumParam(memTypes.get(i), getSimpleIdentifier(members.get(i)), i));
                                println(";");
@@ -3909,9 +3905,8 @@ public class IoTCompiler {
                        println("}");
                } else {        // Just one struct element
                        for (int i = 0; i < members.size(); i++) {
-                               String paramTypeC = checkAndGetCplusType(memTypes.get(i));
-                               String prmType = checkAndGetCplusArrayType(paramTypeC, members.get(i));
-                               println("retCls[retPos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+                               println("retCls[retPos] = \"" + prmTypeC + "\";");
                                print("retObj[retPos++] = &retStruct.");
                                print(getEnumParam(memTypes.get(i), getSimpleIdentifier(members.get(i)), i));
                                println(";");
@@ -3952,14 +3947,14 @@ public class IoTCompiler {
                                        println("paramObj[pos++] = &numStubs" + i + ";");
                                } else {        // Generate normal classes if it's not a callback object
                                        String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i));
-                                       String prmTypeC = checkAndGetCplusArrayType(paramTypeC, methParams.get(i));
                                        if (isEnumClass(getGenericType(paramTypeC))) {  // Check if this is enum type
                                                println("vector<int> paramEnumInt" + i + ";");
                                        } else {
                                                String methParamComplete = checkAndGetCplusArray(paramTypeC, methParams.get(i));
                                                println(methParamComplete + ";");
                                        }
-                                       println("paramCls[pos] = \"" + getEnumType(prmTypeC) + "\";");
+                                       String prmTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
+                                       println("paramCls[pos] = \"" + prmTypeC + "\";");
                                        if (isEnumClass(getGenericType(paramType)))     // Check if this is enum type
                                                println("paramObj[pos++] = &paramEnumInt" + i);
                                        else
@@ -4257,7 +4252,6 @@ public class IoTCompiler {
                println(newSkelClass + "(" + intface + " *_mainObj, int _objectId) {");
                println("mainObj = _mainObj;");
                println("objectId = _objectId;");
-               writeStructPermissionCplusSkeleton(methods, intDecl, intface);
                println("}\n");
        }
 
index 8e688a3..f7b9642 100644 (file)
@@ -113,7 +113,6 @@ void IoTRMIObject::sendReturnObj(void* retObj[], string type[], int numRet) {
        // Need object bytes variable
        char retObjBytes[retLen];
        returnToBytes(retObj, type, retObjBytes, numRet);
-       IoTRMIUtil::printBytes(retObjBytes, retLen, false);
        rmiServer->sendBytes(retObjBytes, retLen);
 }
 
index 4dd11ff..1892ca0 100644 (file)
@@ -48,6 +48,9 @@ class TestClass : public TestClassInterface {
                vector<Enum>            handleEnumArray(vector<Enum> vecEn);
                vector<Enum>            handleEnumList(vector<Enum> vecEn);
 
+               // Struct
+               Struct                          handleStruct(Struct str);
+
                int                                     getA();
                void                            setA(int _int);
                void                            setB(float _float);
@@ -290,6 +293,41 @@ vector<Enum> TestClass::handleEnumList(vector<Enum> vecEn) {
 }
 
 
+// Struct
+Struct TestClass::handleStruct(Struct str) {
+
+       cout << "Name: " << str.name << endl;
+       cout << "Value: " << str.value << endl;
+       cout << "Year: " << str.year << endl;
+
+       Struct test;
+       test.name = "Anonymous";
+       test.value = 1.33;
+       test.year = 2016;
+       str = test;
+
+       return str;
+}
+
+
+/*vector<Struct> TestClass::handleStruct(vector<Struct> vecStr) {
+
+       for (Struct str : vecStr) {
+
+               cout << "Name: " << str.name << endl;
+               cout << "Value: " << str.value << endl;
+               cout << "Year: " << str.year << endl;
+       }
+       Struct test;
+       test.name = "Anonymous";
+       test.value = 1.33;
+       test.year = 2016;
+       vecStr.push_back(test);
+
+       return vecStr;
+}*/
+
+
 string TestClass::sumArray(vector<string> newA) {
 
        string sum = "";
index 01b0a90..c65cd64 100644 (file)
@@ -100,6 +100,15 @@ int main(int argc, char *argv[])
        for (Enum en : vecRes2) {
                cout << "Enum value: " << en << endl;
        }
+       cout << "==== STRUCT ====" << endl;
+       Struct str;
+       str.name = "Rahmadi";
+       str.value = 0.123;
+       str.year = 2016;
+       Struct resStr = tcStub->handleStruct(str);
+       cout << "Name: " << resStr.name << endl;
+       cout << "Value:" << resStr.value << endl;
+       cout << "Year" << resStr.year << endl;
 
        cout << "==== OTHERS ====" << endl;
        cout << "Return value: " << tcStub->getA() << endl;
index a7453a4..8844ffb 100644 (file)
@@ -242,6 +242,44 @@ public class TestClass implements TestClassInterface {
        }
 
 
+       // Struct
+       public Struct handleStruct(Struct str) {
+
+               System.out.println("Name: " + str.name);
+               System.out.println("Value: " + str.value);
+               System.out.println("Year: " + str.year);
+
+
+               Struct test = new Struct();
+               test.name = "Anonymous";
+               test.value = 1.33f;
+               test.year = 2016;
+
+               str = test;
+
+               return str;
+       }
+
+
+       /*public Struct[] handleStruct(Struct[] data) {
+
+               for (Struct str : data) {
+                       System.out.println("Name: " + str.name);
+                       System.out.println("Value: " + str.value);
+                       System.out.println("Year: " + str.year);
+               }
+
+               Struct test = new Struct();
+               test.name = "Anonymous";
+               test.value = 1.33f;
+               test.year = 2016;
+
+               data[0] = test;
+
+               return data;
+       }*/
+
+
        // Getters
        public String sumArray(String[] newA) {
 
index 63c3fff..6f99992 100644 (file)
@@ -71,6 +71,16 @@ public class TestClass_Stub {
                List<Enum> resArr2 = tcstub.handleEnumList(enArr2);
                System.out.println("Enum members: " + resArr2.toString());
 
+               System.out.println("==== STRUCT ====");
+               Struct str = new Struct();
+               str.name = "Rahmadi";
+               str.value = 0.123f;
+               str.year = 2016;
+               Struct strRes = tcstub.handleStruct(str);
+               System.out.println("Name: " + strRes.name);
+               System.out.println("Value: " + strRes.value);
+               System.out.println("Year: " + strRes.year);
+
                System.out.println("==== OTHERS ====");
                System.out.println("Return value: " + tcstub.getA());
                System.out.println("Return value: " + tcstub.setAndGetA(123));