Integrating enum and struct in one method call; fixing minor bugs
authorrtrimana <rtrimana@uci.edu>
Thu, 8 Dec 2016 17:06:24 +0000 (09:06 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 8 Dec 2016 17:06:24 +0000 (09:06 -0800)
config/iotpolicy/testclasspolicy_advanced.pol
iotjava/iotpolicy/IoTCompiler.java
iotjava/iotrmi/C++/basics/TestClass.hpp
iotjava/iotrmi/C++/basics/TestClassAdvanced_Stub.cpp
iotjava/iotrmi/Java/basics/TestClass.java
iotjava/iotrmi/Java/basics/TestClassAdvanced_Stub.java

index ad432795ae6dc44c62f2978d0ffb374ae85c9088..aa269faacd5af5fb924c19c72ac818a88b43569a 100644 (file)
@@ -12,12 +12,16 @@ public interface TestClassInterface {
        public Struct handleStructComplex(int in, char c, Struct str);
        public List<Struct> handleStructComplex2(int in, char c, Struct str[]);
 
+       public Enum[] handleEnumStruct(Enum en[], List<Struct> str, char c);
+
        public void registerCallback(CallBackInterface _cb);
        public void registerCallbackArray(CallBackInterface _cb[]);
        public void registerCallbackList(List<CallBackInterface> _cb);
        public void registerCallbackComplex(int in, List<CallBackInterface> _cb, double db);
        public int callBack();
 
+       public Enum[] handleAll(Enum en[], List<Struct> str, char c, List<CallBackInterface> _cb);
+
        capability EnumsStructs {
                description = "All the set methods";
 
@@ -32,6 +36,9 @@ public interface TestClassInterface {
                method = "handleStructList(List<Struct> str)";
                method = "handleStructComplex(int in, char c, Struct str)";
                method = "handleStructComplex2(int in, char c, Struct str[])";
+
+               method = "handleEnumStruct(Enum en[], List<Struct> str, char c)";
+               method = "handleAll(Enum en[], List<Struct> str, char c, List<CallBackInterface> _cb)";
        }
 
        capability Callbacks {
index 8242bfc0d99fa2094705b960d2935e3fb09f1749..5c3ab9226913c2a771b8cea644078b4ff9d5911d 100644 (file)
@@ -2974,6 +2974,7 @@ public class IoTCompiler {
                println("int methodId = " + intDecl.getMethodNumId(method) + ";");
                String retType = intDecl.getMethodType(method);
                println("string retType = \"" + checkAndGetCplusRetClsType(getStructType(getEnumType(retType))) + "\";");
+               checkAndWriteEnumTypeCplusStub(methParams, methPrmTypes);
                // Generate array of parameter types
                if (isStructPresent(methParams, methPrmTypes)) {
                        writeStructParamClassCplusStub(methParams, methPrmTypes);
@@ -2994,7 +2995,6 @@ public class IoTCompiler {
                                }
                        }
                        println(" };");
-                       checkAndWriteEnumTypeCplusStub(methParams, methPrmTypes);
                        // Generate array of parameter objects
                        print("void* paramObj[] = { ");
                        for (int i = 0; i < methParams.size(); i++) {
@@ -3997,7 +3997,7 @@ public class IoTCompiler {
                                        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);
+                                               println("paramObj[pos++] = &paramEnumInt" + i + ";");
                                        else
                                                println("paramObj[pos++] = &" + getSimpleIdentifier(methParams.get(i)) + ";");
                                }
index fa9b877e3df4c6bc3995992a6c092a2053c6bd11..f33dbf28b97c95294af1ad4d9e8632d4ede57d85 100644 (file)
@@ -59,6 +59,9 @@ class TestClass : public TestClassInterface {
                Struct                          handleStructComplex(int in, char c, Struct str);
                vector<Struct>          handleStructComplex2(int in, char c, vector<Struct> vecStr);
 
+               vector<Enum>            handleEnumStruct(vector<Enum> en, vector<Struct> str, char c);
+               vector<Enum>            handleAll(vector<Enum> en, vector<Struct> str, char c, vector<CallBackInterfaceWithCallBack*> _cb);
+
                int                                     getA();
                void                            setA(int _int);
                void                            setB(float _float);
@@ -432,6 +435,39 @@ vector<Struct> TestClass::handleStructComplex2(int in, char c, vector<Struct> ve
 }
 
 
+vector<Enum> TestClass::handleEnumStruct(vector<Enum> en, vector<Struct> str, char c) {
+
+       for (Struct st : str) {
+               cout << "Name: " << st.name << endl;
+               cout << "Value: " << st.value << endl;
+               cout << "Year: " << st.year << endl;
+       }
+
+       cout << "Char: " << c << endl;
+
+       return en;
+}
+
+
+vector<Enum> TestClass::handleAll(vector<Enum> en, vector<Struct> str, char c, vector<CallBackInterfaceWithCallBack*> _cb) {
+
+       for (CallBackInterfaceWithCallBack* cb : _cb) {
+               cbvec.push_back(cb);
+               cout << "Registering callback object in array!" << endl;
+       }
+
+       for (Struct st : str) {
+               cout << "Name: " << st.name << endl;
+               cout << "Value: " << st.value << endl;
+               cout << "Year: " << st.year << endl;
+       }
+
+       cout << "Char: " << c << endl;
+
+       return en;
+}
+
+
 string TestClass::sumArray(vector<string> newA) {
 
        string sum = "";
index 2d824781cf89ee3d2c573d48e2257b2b4ee5632e..4906167eab242ae94c12a6f949ec87c9944f0308 100644 (file)
@@ -23,13 +23,13 @@ int main(int argc, char *argv[])
        Enum res = tcStub->handleEnum(en);
        cout << "Return value: " << res << endl;
        Enum resComp = tcStub->handleEnumComplex(en, 23, 'c');
-       cout << "Return value: " << resComp << endl;
+       cout << "Return value: " << resComp << endl;*/
        vector<Enum> vecEn;
        vecEn.push_back(APPLE);
        vecEn.push_back(ORANGE);
        vecEn.push_back(APPLE);
        vecEn.push_back(GRAPE);
-       vector<Enum> vecRes = tcStub->handleEnumArray(vecEn);
+/*     vector<Enum> vecRes = tcStub->handleEnumArray(vecEn);
        for (Enum en : vecRes) {
                cout << "Enum value: " << en << endl;
        }
@@ -43,19 +43,19 @@ int main(int argc, char *argv[])
        }*/
 
 
-/*     cout << "==== STRUCT ====" << endl;
+       cout << "==== STRUCT ====" << endl;
        Struct str;
        str.name = "Rahmadi";
        str.value = 0.123;
        str.year = 2016;
-       Struct resStr = tcStub->handleStruct(str);
+/*     Struct resStr = tcStub->handleStruct(str);
        cout << "Name: " << resStr.name << endl;
        cout << "Value:" << resStr.value << endl;
        cout << "Year" << resStr.year << endl;
        Struct resStr2 = tcStub->handleStructComplex(23, 'c', str);
        cout << "Name: " << resStr2.name << endl;
        cout << "Value:" << resStr2.value << endl;
-       cout << "Year" << resStr2.year << endl;
+       cout << "Year" << resStr2.year << endl;*/
        Struct str2;
        str2.name = "Trimananda";
        str2.value = 0.124;
@@ -63,7 +63,7 @@ int main(int argc, char *argv[])
        vector<Struct> vecStr;
        vecStr.push_back(str);
        vecStr.push_back(str2);
-       vector<Struct> vecRetStr = tcStub->handleStructArray(vecStr);
+/*     vector<Struct> vecRetStr = tcStub->handleStructArray(vecStr);
        for (Struct st : vecRetStr) {
                cout << "Name: " << st.name << endl;
                cout << "Value:" << st.value << endl;
@@ -81,9 +81,13 @@ int main(int argc, char *argv[])
                cout << "Value:" << st.value << endl;
                cout << "Year" << st.year << endl;
        }*/
+       vector<Enum> vecRes4 = tcStub->handleEnumStruct(vecEn, vecStr, 'c');
+       for (Enum en : vecRes4) {
+               cout << "Enum value: " << en << endl;
+       }
 
-       cout << "==== CALLBACK ====" << endl;
-/*     CallBackInterface *cbSingle = new CallBack(2354);
+/*     cout << "==== CALLBACK ====" << endl;
+       CallBackInterface *cbSingle = new CallBack(2354);
        tcStub->registerCallback(cbSingle);
        cout << "Return value from callback: " << tcStub->callBack() << endl;
        CallBackInterface *cb1 = new CallBack(23);
@@ -94,18 +98,22 @@ int main(int argc, char *argv[])
        cb.push_back(cb2);
        cb.push_back(cb3);
        tcStub->registerCallbackArray(cb);
-       cout << "Return value from callback: " << tcStub->callBack() << endl;*/
+       cout << "Return value from callback: " << tcStub->callBack() << endl;
        CallBackInterface *cb4 = new CallBack(53);
        CallBackInterface *cb5 = new CallBack(63);
-       CallBackInterface *cb6 = new CallBack(73);
+       CallBackInterface *cb6 = new CallBack(73);*/
        vector<CallBackInterface*> cblist;
        cblist.push_back(cb4);
        cblist.push_back(cb5);
        cblist.push_back(cb6);
 //     tcStub->registerCallbackList(cblist);
 //     cout << "Return value from callback: " << tcStub->callBack() << endl;
-       tcStub->registerCallbackComplex(23, cblist, 0.1234);
-       cout << "Return value from callback: " << tcStub->callBack() << endl;
+/*     tcStub->registerCallbackComplex(23, cblist, 0.1234);
+       cout << "Return value from callback: " << tcStub->callBack() << endl;*/
+       vector<Enum> vecRes5 = tcStub->handleEnumStruct(vecEn, vecStr, 'c', cblist);
+       for (Enum en : vecRes5) {
+               cout << "Enum value: " << en << endl;
+       }
 
        return 0;
 }
index 89baf94602f6d9372c4c45f5d24fbcd392cd2a0b..51aed4ca505908fe0e7abec17890015221b113c4 100644 (file)
@@ -380,6 +380,39 @@ public class TestClass implements TestClassInterface {
        }
 
 
+       public Enum[] handleEnumStruct(Enum en[], List<Struct> str, char c) {
+
+               for (Struct st : str) {
+                       System.out.println("Name: " + st.name);
+                       System.out.println("Value: " + st.value);
+                       System.out.println("Year: " + st.year);
+               }
+
+               System.out.println("Char: " + c);
+
+               return en;
+       }
+
+
+       public Enum[] handleAll(Enum en[], List<Struct> str, char c, List<CallBackInterfaceWithCallBack> _cb) {
+
+               for (CallBackInterfaceWithCallBack cb : _cb) {
+                       cblist.add(cb);
+                       System.out.println("Registering callback objects in list!");
+               }
+
+               for (Struct st : str) {
+                       System.out.println("Name: " + st.name);
+                       System.out.println("Value: " + st.value);
+                       System.out.println("Year: " + st.year);
+               }
+
+               System.out.println("Char: " + c);
+
+               return en;
+       }
+
+
        // Getters
        public String sumArray(String[] newA) {
 
index 46143fa160f499d16b98e7bd04825305b7eb7bd1..b8b7e24eca90fd115f7b5515a5d3014bd5e4abbc 100644 (file)
@@ -22,10 +22,10 @@ public class TestClassAdvanced_Stub {
                Enum res = tcstub.handleEnum(en);
                System.out.println("Enum member: " + res);
                Enum resComp = tcstub.handleEnumComplex(en, 23, 'c');
-               System.out.println("Enum member: " + resComp);
+               System.out.println("Enum member: " + resComp);*/
 
                Enum[] enArr = { Enum.APPLE, Enum.ORANGE, Enum.APPLE, Enum.GRAPE };
-               Enum[] resArr = tcstub.handleEnumArray(enArr);
+/*             Enum[] resArr = tcstub.handleEnumArray(enArr);
                System.out.println("Enum members: " + Arrays.toString(resArr));
                List<Enum> enArr2 = new ArrayList(Arrays.asList(enArr));
                List<Enum> resArr2 = tcstub.handleEnumList(enArr2);
@@ -34,32 +34,32 @@ public class TestClassAdvanced_Stub {
                System.out.println("Enum members: " + Arrays.toString(resArr3));*/
                
 
-/*             System.out.println("==== STRUCT ====");
+               System.out.println("==== STRUCT ====");
                Struct str = new Struct();
                str.name = "Rahmadi";
                str.value = 0.123f;
                str.year = 2016;
-               Struct strRes = tcstub.handleStruct(str);
+/*             Struct strRes = tcstub.handleStruct(str);
                System.out.println("Name: " + strRes.name);
                System.out.println("Value: " + strRes.value);
                System.out.println("Year: " + strRes.year);
                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<Struct> stList = new ArrayList(Arrays.asList(arrStr));
-               List<Struct> stRetList = tcstub.handleStructList(stList);
+/*             List<Struct> stRetList = tcstub.handleStructList(stList);
                for(Struct st : stRetList) {
                        System.out.println("Name: " + st.name);
                        System.out.println("Value: " + st.value);
@@ -70,10 +70,12 @@ public class TestClassAdvanced_Stub {
                        System.out.println("Name: " + st.name);
                        System.out.println("Value: " + st.value);
                        System.out.println("Year: " + st.year);
-               }*/
+               }
+               Enum[] resArr3 = tcstub.handleEnumStruct(enArr, stList, 'c');
+               System.out.println("Enum members: " + Arrays.toString(resArr3));*/
 
-               System.out.println("==== CALLBACKS ====");
-/*             CallBackInterface cbSingle = new CallBack(2354);
+/*             System.out.println("==== CALLBACKS ====");
+               CallBackInterface cbSingle = new CallBack(2354);
                tcstub.registerCallback(cbSingle);
                System.out.println("Return value from callback: " + tcstub.callBack());
                CallBackInterface cb1 = new CallBack(23);
@@ -89,8 +91,9 @@ public class TestClassAdvanced_Stub {
 //             tcstub.registerCallbackList(cblist);
 //             System.out.println("Return value from callback: " + tcstub.callBack());
 
-               tcstub.registerCallbackComplex(23, cblist, 0.1234);
-               System.out.println("Return value from callback: " + tcstub.callBack());
-
+/*             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));
        }
 }