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 ad43279..aa269fa 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 8242bfc..5c3ab92 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 fa9b877..f33dbf2 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 2d82478..4906167 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 89baf94..51aed4c 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 46143fa..b8b7e24 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));
        }
 }