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 c5fcfd2..ad43279 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 registerCallbackComplex(int in, List<CallBackInterface> _cb, double db);
        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 = "registerCallbackComplex(int in, List<CallBackInterface> _cb, double db)";
                method = "callBack()";
        }
 
index 9eafffb..8242bfc 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);
-                       //if (callbackType.equals(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;
-               if (isCallbackMethod)
+               if (isCallbackMethod) {
                        mapStubParam = writeCallbackJavaStubGeneration(methParams, methPrmTypes, callbackType);
+               }
                // 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++) {
 
-                       if (isCallbackMethod) {
+                       String paramType = methPrmTypes.get(i);
+                       if (isCallbackMethod && checkCallbackType(paramType, callbackType)) {
                                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 {
-                               String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
+                               String prmType = checkAndGetArray(paramType, methParams.get(i));
                                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
-                               print(getSimpleIdentifier(methParams.get(i)));
+                               print("&" + getSimpleIdentifier(methParams.get(i)));
                        if (i != methParams.size() - 1)
                                print(", ");
                }
index 9c46644..fa9b877 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                            registerCallbackComplex(int in, vector<CallBackInterfaceWithCallBack*> _cb, double db);
                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;
index f70573e..2d82478 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;
@@ -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;
@@ -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;
-       }*/
+       }
        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);
@@ -94,7 +94,7 @@ 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);
@@ -102,19 +102,10 @@ int main(int argc, char *argv[])
        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 << "==== 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;
 }
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 42e53c2..89baf94 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;
index 8261225..46143fa 100644 (file)
@@ -17,8 +17,8 @@ public class TestClassAdvanced_Stub {
                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');
@@ -34,25 +34,25 @@ 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);
@@ -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);
-               }*/
+               }
                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);
@@ -81,13 +81,16 @@ public class TestClassAdvanced_Stub {
                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);
-               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!!!");
-       }
-}