Testing complex callbacks invocation; fixing subtle bugs
authorrtrimana <rtrimana@uci.edu>
Wed, 7 Dec 2016 19:51:07 +0000 (11:51 -0800)
committerrtrimana <rtrimana@uci.edu>
Wed, 7 Dec 2016 19:51:07 +0000 (11:51 -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/C++/basics/TestClass_Debug.cpp [deleted file]
iotjava/iotrmi/Java/basics/TestClass.java
iotjava/iotrmi/Java/basics/TestClassAdvanced_Stub.java
iotjava/iotrmi/Java/basics/TestClass_Debug.java [deleted file]

index c5fcfd27c26538ed25096d60fe63c94230042927..ad432795ae6dc44c62f2978d0ffb374ae85c9088 100644 (file)
@@ -15,6 +15,7 @@ public interface TestClassInterface {
        public void registerCallback(CallBackInterface _cb);
        public void registerCallbackArray(CallBackInterface _cb[]);
        public void registerCallbackList(List<CallBackInterface> _cb);
        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();
 
        capability EnumsStructs {
        public int callBack();
 
        capability EnumsStructs {
@@ -39,6 +40,7 @@ public interface TestClassInterface {
                method = "registerCallback(CallBackInterface _cb)";
                method = "registerCallbackArray(CallBackInterface _cb[])";
                method = "registerCallbackList(List<CallBackInterface> _cb)";
                method = "registerCallback(CallBackInterface _cb)";
                method = "registerCallbackArray(CallBackInterface _cb[])";
                method = "registerCallbackList(List<CallBackInterface> _cb)";
+               method = "registerCallbackComplex(int in, List<CallBackInterface> _cb, double db)";
                method = "callBack()";
        }
 
                method = "callBack()";
        }
 
index 9eafffbef295bb01b287b4d6075600f2863f0d92..8242bfc0d99fa2094705b960d2935e3fb09f1749 100644 (file)
@@ -1363,7 +1363,6 @@ public class IoTCompiler {
                for (int i = 0; i < methParams.size(); i++) {
                        String paramType = methPrmTypes.get(i);
                        String param = methParams.get(i);
                for (int i = 0; i < methParams.size(); i++) {
                        String paramType = methPrmTypes.get(i);
                        String param = methParams.get(i);
-                       //if (callbackType.equals(paramType)) {
                        if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
                                println("try {");
                                String exchParamType = checkAndGetParamClass(getGenericType(paramType));
                        if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
                                println("try {");
                                String exchParamType = checkAndGetParamClass(getGenericType(paramType));
@@ -1674,8 +1673,9 @@ public class IoTCompiler {
 
                checkAndWriteEnumTypeJavaSkeleton(methParams, methPrmTypes);
                Map<Integer,String> mapStubParam = null;
 
                checkAndWriteEnumTypeJavaSkeleton(methParams, methPrmTypes);
                Map<Integer,String> mapStubParam = null;
-               if (isCallbackMethod)
+               if (isCallbackMethod) {
                        mapStubParam = writeCallbackJavaStubGeneration(methParams, methPrmTypes, callbackType);
                        mapStubParam = writeCallbackJavaStubGeneration(methParams, methPrmTypes, callbackType);
+               }
                // Check if this is "void"
                String retType = intDecl.getMethodType(method);
                if (retType.equals("void")) {
                // Check if this is "void"
                String retType = intDecl.getMethodType(method);
                if (retType.equals("void")) {
@@ -1689,14 +1689,15 @@ public class IoTCompiler {
                }
                for (int i = 0; i < methParams.size(); i++) {
 
                }
                for (int i = 0; i < methParams.size(); i++) {
 
-                       if (isCallbackMethod) {
+                       String paramType = methPrmTypes.get(i);
+                       if (isCallbackMethod && checkCallbackType(paramType, callbackType)) {
                                print(mapStubParam.get(i));     // Get the callback parameter
                                print(mapStubParam.get(i));     // Get the callback parameter
-                       } else if (isEnumClass(getGenericType(methPrmTypes.get(i)))) { // Enum class
-                               print(getEnumParam(methPrmTypes.get(i), methParams.get(i), i));
-                       } else if (isStructClass(getGenericType(methPrmTypes.get(i)))) {
+                       } else if (isEnumClass(getGenericType(paramType))) { // Enum class
+                               print(getEnumParam(paramType, methParams.get(i), i));
+                       } else if (isStructClass(getGenericType(paramType))) {
                                print("paramStruct" + i);
                        } else {
                                print("paramStruct" + i);
                        } else {
-                               String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
+                               String prmType = checkAndGetArray(paramType, methParams.get(i));
                                if (isStructMethod)
                                        print("(" + prmType + ") paramObj[offset" + i + "]");
                                else
                                if (isStructMethod)
                                        print("(" + prmType + ") paramObj[offset" + i + "]");
                                else
@@ -2676,7 +2677,7 @@ public class IoTCompiler {
                        if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
                                print("&___paramCB");
                        } else
                        if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
                                print("&___paramCB");
                        } else
-                               print(getSimpleIdentifier(methParams.get(i)));
+                               print("&" + getSimpleIdentifier(methParams.get(i)));
                        if (i != methParams.size() - 1)
                                print(", ");
                }
                        if (i != methParams.size() - 1)
                                print(", ");
                }
index 9c466445c85e5bee65f81e71129a70b5c3235c25..fa9b877e3df4c6bc3995992a6c092a2053c6bd11 100644 (file)
@@ -42,6 +42,7 @@ class TestClass : public TestClassInterface {
                void                            registerCallback(CallBackInterfaceWithCallBack* _cb);
                void                            registerCallbackArray(vector<CallBackInterfaceWithCallBack*> _cb);
                void                            registerCallbackList(vector<CallBackInterfaceWithCallBack*> _cb);
                void                            registerCallback(CallBackInterfaceWithCallBack* _cb);
                void                            registerCallbackArray(vector<CallBackInterfaceWithCallBack*> _cb);
                void                            registerCallbackList(vector<CallBackInterfaceWithCallBack*> _cb);
+               void                            registerCallbackComplex(int in, vector<CallBackInterfaceWithCallBack*> _cb, double db);
                int                                     callBack();
 
                // Enum
                int                                     callBack();
 
                // Enum
@@ -117,6 +118,18 @@ void TestClass::registerCallbackList(vector<CallBackInterfaceWithCallBack*> _cb)
 }
 
 
 }
 
 
+void TestClass::registerCallbackComplex(int in, vector<CallBackInterfaceWithCallBack*> _cb, double db) {
+
+       for (CallBackInterfaceWithCallBack* cb : _cb) {
+               cbvec.push_back(cb);
+               cout << "Registering callback object in list!" << endl;
+       }
+
+       cout << "Integer: " << in << endl;
+       cout << "Double: " << db << endl;
+}
+
+
 int TestClass::callBack() {
 
        int sum = 0;
 int TestClass::callBack() {
 
        int sum = 0;
index f70573e4e5f894098332919310b6c55de23fdcad..2d824781cf89ee3d2c573d48e2257b2b4ee5632e 100644 (file)
@@ -43,7 +43,7 @@ int main(int argc, char *argv[])
        }*/
 
 
        }*/
 
 
-       cout << "==== STRUCT ====" << endl;
+/*     cout << "==== STRUCT ====" << endl;
        Struct str;
        str.name = "Rahmadi";
        str.value = 0.123;
        Struct str;
        str.name = "Rahmadi";
        str.value = 0.123;
@@ -63,7 +63,7 @@ int main(int argc, char *argv[])
        vector<Struct> vecStr;
        vecStr.push_back(str);
        vecStr.push_back(str2);
        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;
        for (Struct st : vecRetStr) {
                cout << "Name: " << st.name << endl;
                cout << "Value:" << st.value << endl;
@@ -74,16 +74,16 @@ int main(int argc, char *argv[])
                cout << "Name: " << st.name << endl;
                cout << "Value:" << st.value << endl;
                cout << "Year" << st.year << endl;
                cout << "Name: " << st.name << endl;
                cout << "Value:" << st.value << endl;
                cout << "Year" << st.year << endl;
-       }*/
+       }
        vector<Struct> vecRetStr3 = tcStub->handleStructComplex2(23, 'c', vecStr);
        for (Struct st : vecRetStr3) {
                cout << "Name: " << st.name << endl;
                cout << "Value:" << st.value << endl;
                cout << "Year" << st.year << endl;
        vector<Struct> vecRetStr3 = tcStub->handleStructComplex2(23, 'c', vecStr);
        for (Struct st : vecRetStr3) {
                cout << "Name: " << st.name << endl;
                cout << "Value:" << st.value << endl;
                cout << "Year" << st.year << 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);
        tcStub->registerCallback(cbSingle);
        cout << "Return value from callback: " << tcStub->callBack() << endl;
        CallBackInterface *cb1 = new CallBack(23);
@@ -94,7 +94,7 @@ int main(int argc, char *argv[])
        cb.push_back(cb2);
        cb.push_back(cb3);
        tcStub->registerCallbackArray(cb);
        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 *cb4 = new CallBack(53);
        CallBackInterface *cb5 = new CallBack(63);
        CallBackInterface *cb6 = new CallBack(73);
@@ -102,19 +102,10 @@ int main(int argc, char *argv[])
        cblist.push_back(cb4);
        cblist.push_back(cb5);
        cblist.push_back(cb6);
        cblist.push_back(cb4);
        cblist.push_back(cb5);
        cblist.push_back(cb6);
-       tcStub->registerCallbackList(cblist);
+//     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;
 
        cout << "Return value from callback: " << tcStub->callBack() << endl;
 
-       cout << "==== OTHERS ====" << endl;
-       cout << "Return value: " << tcStub->getA() << endl;
-       cout << "Return value: " << tcStub->setAndGetA(123) << endl;
-       cout << "Return value: " << tcStub->setACAndGetA("string", 123) << endl;
-       vector<string> input;
-       input.push_back("123");
-       input.push_back("456");
-       input.push_back("987");
-
-       cout << "Return value: " << tcStub->sumArray(input) << endl;
-*/     
        return 0;
 }
        return 0;
 }
diff --git a/iotjava/iotrmi/C++/basics/TestClass_Debug.cpp b/iotjava/iotrmi/C++/basics/TestClass_Debug.cpp
deleted file mode 100644 (file)
index 8771d55..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <iostream>
-#include <string>
-#include "TestClassComplete_Stub.hpp"
-#include "CallBack.hpp"
-#include "IoTRMICall.hpp"
-
-using namespace std;
-
-int main(int argc, char *argv[])
-{
-
-       int _port = 50044;
-       const char* _address = "localhost";
-       //const char* address = "128.195.136.170";      // dc-9.calit2.uci.edu
-       int _rev = 0;
-       bool bResult = false;
-
-       IoTRMICall *rmiCall = new IoTRMICall(_port, _address, _rev, &bResult);
-       cout << "Successfully connecting!" << endl << endl;
-       delete rmiCall;
-       
-       return 0;
-}
index 42e53c2cdefdde17047629f3e3eb9a98514f6ca1..89baf94602f6d9372c4c45f5d24fbcd392cd2a0b 100644 (file)
@@ -61,6 +61,18 @@ public class TestClass implements TestClassInterface {
        }
 
 
        }
 
 
+       public void registerCallbackComplex(int in, List<CallBackInterfaceWithCallBack> _cb, double db) {
+
+               for (CallBackInterfaceWithCallBack cb : _cb) {
+                       cblist.add(cb);
+                       System.out.println("Registering callback objects in list!");
+               }
+
+               System.out.println("Integer: " + in);
+               System.out.println("Double: " + db);
+       }
+
+
        public int callBack() {
 
                int sum = 0;
        public int callBack() {
 
                int sum = 0;
index 826122532569e53dfcb8a120247f10c85d29897c..46143fa160f499d16b98e7bd04825305b7eb7bd1 100644 (file)
@@ -17,8 +17,8 @@ public class TestClassAdvanced_Stub {
                int rev = 0;
 
                TestClassComplete_Stub tcstub = new TestClassComplete_Stub(port, address, rev, ports);
                int rev = 0;
 
                TestClassComplete_Stub tcstub = new TestClassComplete_Stub(port, address, rev, ports);
-               System.out.println("==== ENUM ====");
-/*             Enum en = Enum.APPLE;
+/*             System.out.println("==== ENUM ====");
+               Enum en = Enum.APPLE;
                Enum res = tcstub.handleEnum(en);
                System.out.println("Enum member: " + res);
                Enum resComp = tcstub.handleEnumComplex(en, 23, 'c');
                Enum res = tcstub.handleEnum(en);
                System.out.println("Enum member: " + res);
                Enum resComp = tcstub.handleEnumComplex(en, 23, 'c');
@@ -34,25 +34,25 @@ public class TestClassAdvanced_Stub {
                System.out.println("Enum members: " + Arrays.toString(resArr3));*/
                
 
                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 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("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 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);
                for(Struct st : arrRet) {
                        System.out.println("Name: " + st.name);
                        System.out.println("Value: " + st.value);
@@ -64,16 +64,16 @@ public class TestClassAdvanced_Stub {
                        System.out.println("Name: " + st.name);
                        System.out.println("Value: " + st.value);
                        System.out.println("Year: " + st.year);
                        System.out.println("Name: " + st.name);
                        System.out.println("Value: " + st.value);
                        System.out.println("Year: " + st.year);
-               }*/
+               }
                List<Struct> stRetList2 = tcstub.handleStructComplex2(23, 'c', arrStr);
                for(Struct st : stRetList2) {
                        System.out.println("Name: " + st.name);
                        System.out.println("Value: " + st.value);
                        System.out.println("Year: " + st.year);
                List<Struct> stRetList2 = tcstub.handleStructComplex2(23, 'c', arrStr);
                for(Struct st : stRetList2) {
                        System.out.println("Name: " + st.name);
                        System.out.println("Value: " + st.value);
                        System.out.println("Year: " + st.year);
-               }
+               }*/
 
 
-               /*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);
                tcstub.registerCallback(cbSingle);
                System.out.println("Return value from callback: " + tcstub.callBack());
                CallBackInterface cb1 = new CallBack(23);
@@ -81,13 +81,16 @@ public class TestClassAdvanced_Stub {
                CallBackInterface cb3 = new CallBack(43);
                CallBackInterface[] cb = { cb1, cb2, cb3 };
                tcstub.registerCallbackArray(cb);
                CallBackInterface cb3 = new CallBack(43);
                CallBackInterface[] cb = { cb1, cb2, cb3 };
                tcstub.registerCallbackArray(cb);
-               System.out.println("Return value from callback: " + tcstub.callBack());
+               System.out.println("Return value from callback: " + tcstub.callBack());*/
                List<CallBackInterface> cblist = new ArrayList<CallBackInterface>();
                CallBackInterface cb4 = new CallBack(53); cblist.add(cb4);
                CallBackInterface cb5 = new CallBack(63); cblist.add(cb5);
                CallBackInterface cb6 = new CallBack(73); cblist.add(cb6);
                List<CallBackInterface> cblist = new ArrayList<CallBackInterface>();
                CallBackInterface cb4 = new CallBack(53); cblist.add(cb4);
                CallBackInterface cb5 = new CallBack(63); cblist.add(cb5);
                CallBackInterface cb6 = new CallBack(73); cblist.add(cb6);
-               tcstub.registerCallbackList(cblist);
-               System.out.println("Return value from callback: " + tcstub.callBack());*/
+//             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());
 
        }
 }
 
        }
 }
diff --git a/iotjava/iotrmi/Java/basics/TestClass_Debug.java b/iotjava/iotrmi/Java/basics/TestClass_Debug.java
deleted file mode 100644 (file)
index 6ab13ea..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-import java.util.Arrays;
-import java.util.List;
-import java.util.ArrayList;
-import iotrmi.Java.IoTRMICall;
-import iotruntime.master.CommunicationHandler;
-
-public class TestClass_Debug {
-
-       public static void main(String[] args) throws Exception {
-
-               CommunicationHandler comHan = new CommunicationHandler(true);
-               int numOfPorts = 1;
-               int[] ports = comHan.getCallbackPorts(numOfPorts);
-
-               int _port = 56205;
-               String _address = "localhost";
-               //String address = "128.195.136.170";   // dc-9.calit2.uci.edu
-               int _rev = 0;
-
-               IoTRMICall rmiCall = new IoTRMICall(_port, _address, _rev);
-               System.out.println("Creating a new connection!!!");
-       }
-}