Fixing bugs for multiple callback inputs; adding more testcases
authorrtrimana <rtrimana@uci.edu>
Tue, 7 Feb 2017 21:42:29 +0000 (13:42 -0800)
committerrtrimana <rtrimana@uci.edu>
Tue, 7 Feb 2017 21:42:29 +0000 (13:42 -0800)
iotjava/iotpolicy/IoTCompiler.java
iotjava/iotrmi/Java/IoTRMICommClient.java
localconfig/iotpolicy/development/testclasspolicy_callbacks.pol

index 0a8e5dd0f2e125f2d173af297aa2c4e352d0660e..8848d2cea5edbe280da395bec052e26a5fff6b0c 100644 (file)
@@ -479,7 +479,12 @@ public class IoTCompiler {
        private void writeConstructorJavaStub(String intface, String newStubClass, Set<String> methods, InterfaceDecl intDecl) {
 
                println("public " + newStubClass + "(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {");
+               println("if (_localPortSend != 0 && _localPortRecv != 0) {");
                println("rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);");
+               println("} else");
+               println("{");
+               println("rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);");
+               println("}");
                // Register the AtomicBoolean variables
                for (String method : methods) {
                        // Generate AtomicBooleans for methods that have return values
@@ -769,15 +774,8 @@ public class IoTCompiler {
                        if (isStructClass(simpleType)) {
                                writeStructMembersJavaStub(simpleType, paramType, param);
                        } else if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
-                               println("paramCls[pos] = int.class;");
-                               print("paramObj[pos++] = ");
-                               if (isArray(methParams.get(i)))
-                                       print(getSimpleIdentifier(methParams.get(i)) + ".length");
-                               else if (isList(methPrmTypes.get(i)))
-                                       print(getSimpleIdentifier(methParams.get(i)) + ".size()");
-                               else
-                                       print("new Integer(1)");
-                               println(";");
+                               println("paramCls[pos] = int[].class;");
+                               println("paramObj[pos++] = objIdSent" + i + ";");
                        } else {
                                String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
                                println("paramCls[pos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
@@ -927,7 +925,7 @@ public class IoTCompiler {
                        for (int i = 0; i < methParams.size(); i++) {
                                String paramType = methPrmTypes.get(i);
                                if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
-                                       print("objIdSent");
+                                       print("objIdSent" + i);
                                } else
                                        print(getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i));
                                // Check if this is the last element (don't print a comma)
@@ -997,17 +995,17 @@ public class IoTCompiler {
                println("if (!IoTRMIUtil.mapSkel.containsKey(" + paramIdent + ")) {");
                println("int newObjIdSent = rmiComm.getObjectIdCounter();");
                if (isMultipleCallbacks)
-                       println("objIdSent[i++] = newObjIdSent;");
+                       println("objIdSent" + counter + "[cnt" + counter + "++] = newObjIdSent;");
                else
-                       println("objIdSent[0] = newObjIdSent;");
+                       println("objIdSent" + counter + "[0] = newObjIdSent;");
                println("rmiComm.decrementObjectIdCounter();");
                println(callbackType + "_Skeleton skel" + counter + " = new " + callbackType + "_Skeleton(" + paramIdent + ", rmiComm, newObjIdSent);");
-               println("IoTRMIUtil.mapSkel.put(" + paramIdent + ", skel0);");
+               println("IoTRMIUtil.mapSkel.put(" + paramIdent + ", skel" + counter + ");");
                println("IoTRMIUtil.mapSkelId.put(" + paramIdent + ", newObjIdSent);");
                println("Thread thread = new Thread() {");
                println("public void run() {");
                println("try {");
-               println("skel0.___waitRequestInvokeMethod();");
+               println("skel" + counter + ".___waitRequestInvokeMethod();");
                println("} catch (Exception ex) {");
                println("ex.printStackTrace();");
                println("throw new Error(\"Exception when trying to run ___waitRequestInvokeMethod() for " + 
@@ -1022,9 +1020,9 @@ public class IoTCompiler {
                println("{");
                println("int newObjIdSent = IoTRMIUtil.mapSkelId.get(" + paramIdent + ");");
                if (isMultipleCallbacks)
-                       println("objIdSent[i++] = newObjIdSent;");
+                       println("objIdSent" + counter + "[cnt" + counter + "++] = newObjIdSent;");
                else
-                       println("objIdSent[0] = newObjIdSent;");
+                       println("objIdSent" + counter + "[0] = newObjIdSent;");
                println("}");
        }
 
@@ -1036,10 +1034,10 @@ public class IoTCompiler {
                        List<String> methPrmTypes, String method, String callbackType) {
 
                // Determine callback object counter type (List vs. single variable)
-               print("int[] objIdSent = ");
                for (int i = 0; i < methParams.size(); i++) {
                        String paramType = methPrmTypes.get(i);
                        if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
+                               print("int[] objIdSent" + i + " = ");
                                String param = methParams.get(i);
                                if (isArray(methParams.get(i)))
                                        println("new int[" + getSimpleIdentifier(methParams.get(i)) + ".length];");
@@ -1056,7 +1054,7 @@ public class IoTCompiler {
                        if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
                                String param = methParams.get(i);
                                if (isArrayOrList(paramType, param)) {  // Generate loop
-                                       println("int i = 0;");
+                                       println("int cnt" + i + " = 0;");
                                        println("for (" + getGenericType(paramType) + " cb : " + getSimpleIdentifier(param) + ") {");
                                        writeCallbackInstantiationMethodBodyJavaStub("cb", callbackType, i, true);
                                } else
@@ -2641,20 +2639,21 @@ public class IoTCompiler {
                println("auto it = IoTRMIUtil::mapSkel->find(" + paramIdent + ");");
                println("if (it == IoTRMIUtil::mapSkel->end()) {");
                println("int newObjIdSent = rmiComm->getObjectIdCounter();");
-               println("objIdSent.push_back(newObjIdSent);");
+               println("objIdSent" + counter + ".push_back(newObjIdSent);");
                println("rmiComm->decrementObjectIdCounter();");
                println(callbackType + "_Skeleton* skel" + counter + " = new " + callbackType + "_Skeleton(" + paramIdent + ", rmiComm, newObjIdSent);");
-               println("vecCallbackObj.push_back(skel0);");
-               println("IoTRMIUtil::mapSkel->insert(make_pair(" + paramIdent + ", skel0));");
+               println("vecCallbackObj.push_back(skel" + counter + ");");
+               println("IoTRMIUtil::mapSkel->insert(make_pair(" + paramIdent + ", skel" + counter + "));");
                println("IoTRMIUtil::mapSkelId->insert(make_pair(" + paramIdent + ", newObjIdSent));");
-               println("thread th0 (&" + callbackType + "_Skeleton::___waitRequestInvokeMethod, std::ref(skel0), std::ref(skel0));");
-               println("th0.detach();");
+               println("thread th" + counter + " (&" + callbackType + "_Skeleton::___waitRequestInvokeMethod, std::ref(skel" + counter + 
+                       "), std::ref(skel" + counter +"));");
+               println("th" + counter + ".detach();");
                println("while(!skel" + counter + "->didInitWaitInvoke());");
                println("}");
                println("else");
                println("{");
                println("auto itId = IoTRMIUtil::mapSkelId->find(" + paramIdent + ");");
-               println("objIdSent.push_back(itId->second);");
+               println("objIdSent" + counter + ".push_back(itId->second);");
                println("}");
        }
 
@@ -2668,11 +2667,10 @@ public class IoTCompiler {
                // Check if this is single object, array, or list of objects
                boolean isArrayOrList = false;
                String callbackParam = null;
-               println("vector<int> objIdSent;");
                for (int i = 0; i < methParams.size(); i++) {
-
                        String paramType = methPrmTypes.get(i);
                        if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
+                               println("vector<int> objIdSent" + i + ";");
                                String param = methParams.get(i);
                                if (isArrayOrList(paramType, param)) {  // Generate loop                                
                                        println("for (" + getGenericType(paramType) + "* cb : " + getSimpleIdentifier(param) + ") {");
@@ -2684,7 +2682,7 @@ public class IoTCompiler {
                                }
                                if (isArrayOrList)
                                        println("}");
-                               println("vector<int> ___paramCB" + i + " = objIdSent;");
+                               println("vector<int> ___paramCB" + i + " = objIdSent" + i + ";");
                        }
                }
        }
@@ -3151,12 +3149,14 @@ public class IoTCompiler {
                println("}");
                if (callbackExist) {
                // We assume that each class only has one callback interface for now
-                       Iterator it = callbackClasses.iterator();
-                       String callbackType = (String) it.next();
-                       println("for(" + callbackType + "* cb : vecCallbackObj) {");
-                       println("delete cb;");
-                       println("cb = NULL;");
-                       println("}");
+                       //Iterator it = callbackClasses.iterator();
+                       //String callbackType = (String) it.next();
+                       for (String callbackType : callbackClasses) {
+                               println("for(" + callbackType + "* cb : vecCallbackObj) {");
+                               println("delete cb;");
+                               println("cb = NULL;");
+                               println("}");
+                       }
                }
                println("}");
                println("");
@@ -3452,13 +3452,15 @@ public class IoTCompiler {
                println("}");
                if (callbackExist) {
                // We assume that each class only has one callback interface for now
-                       Iterator it = callbackClasses.iterator();
-                       String callbackType = (String) it.next();
-                       String exchangeType = checkAndGetParamClass(callbackType);
-                       println("for(" + exchangeType + "* cb : vecCallbackObj) {");
-                       println("delete cb;");
-                       println("cb = NULL;");
-                       println("}");
+                       //Iterator it = callbackClasses.iterator();
+                       //String callbackType = (String) it.next();
+                       for (String callbackType : callbackClasses) {
+                               String exchangeType = checkAndGetParamClass(callbackType);
+                               println("for(" + exchangeType + "* cb : vecCallbackObj) {");
+                               println("delete cb;");
+                               println("cb = NULL;");
+                               println("}");
+                       }
                }
                println("}");
                println("");
index 99d0af92095d71b22a2f5b9832ce1a09c18a65e1..bf2f7c16d0d572d46d6d24b45d0d8c7d6db75c55 100644 (file)
@@ -45,6 +45,20 @@ public class IoTRMICommClient extends IoTRMIComm {
        }
 
 
+       /**
+        * Constructor (for stub) - only destination port numbers
+        */
+       public IoTRMICommClient(int _portSend, int _portRecv, String _address, int _rev) throws  
+               ClassNotFoundException, InstantiationException, 
+                       IllegalAccessException, IOException {
+
+               super();
+               rmiClientRecv = new IoTSocketClient(_portSend, _address, _rev);
+               rmiClientSend = new IoTSocketClient(_portRecv, _address, _rev);
+               waitForPacketsOnClient();
+       }
+
+
        /**
         * waitForPacketsOnClient() starts a thread that waits for packet bytes on client side
         */
index a045faffcd268b99c402b88bad3439617b1c3a21..5d6d0d9d4fb811ceb5812263985fc985befd8403 100644 (file)
@@ -7,6 +7,9 @@ public interface TestClassInterface {
        public Struct[] handleStructArray(Struct str[]);
        public void registerCallbackArray(CallBackInterface _cb[]);
        public void registerCallbackList(List<CallBackInterface> _cb);
+       public Enum[] handleAll(Enum en[], List<Struct> str, char c, List<CallBackInterface> _cb);
+       public Enum[] handleCallbackEnum(Enum en[], char c, List<CallBackInterface> _cb);
+       public Enum[] handleAllTwo(Enum en1[], Enum en2[], List<Struct> str1, List<Struct> str2, char c, List<CallBackInterface> _cb1, List<CallBackInterface> _cb2);
 
        capability Callbacks {
                description = "All the set-and-get methods";
@@ -17,6 +20,9 @@ public interface TestClassInterface {
                method = "handleStructArray(Struct str[])";
                method = "registerCallbackArray(CallBackInterface _cb[])";
                method = "registerCallbackList(List<CallBackInterface> _cb)";
+               method = "handleAll(Enum en[], List<Struct> str, char c, List<CallBackInterface> _cb)";
+               method = "handleCallbackEnum(Enum en[], char c, List<CallBackInterface> _cb)";
+               method = "handleAllTwo(Enum en1[], Enum en2[], List<Struct> str1, List<Struct> str2, char c, List<CallBackInterface> _cb1, List<CallBackInterface> _cb2)";
        }
        
        enum Enum {