Adding permission inclusion for callback helper function; some testcases on enum...
authorrtrimana <rtrimana@uci.edu>
Tue, 29 Nov 2016 20:59:57 +0000 (12:59 -0800)
committerrtrimana <rtrimana@uci.edu>
Tue, 29 Nov 2016 20:59:57 +0000 (12:59 -0800)
config/iotpolicy/testclasspolicy.pol
iotjava/Makefile
iotjava/iotpolicy/IoTCompiler.java
iotjava/iotrmi/C++/basics/TestClass.hpp
iotjava/iotrmi/C++/basics/TestClass_Stub.cpp
iotjava/iotrmi/Java/basics/TestClass.java
iotjava/iotrmi/Java/basics/TestClass_Stub.java

index ebe25337afd9187c0c51ec324e75eb913585cecd..481a284c815ca65f6068b2d680b5ede69c864d01 100644 (file)
@@ -27,6 +27,8 @@ public interface TestClassInterface {
        public void registerCallback(CallBackInterface _cb);
        public int callBack();
 
+       public Enum handleEnum(Enum en);
+
        public int getA();
        public void setA(int _int);
        public void setB(float _float);
@@ -60,6 +62,7 @@ public interface TestClassInterface {
                method = "getCharList(List<Character> in)";
                method = "registerCallback(CallBackInterface _cb)";
                method = "callBack()";
+               method = "handleEnum(Enum en)";
                method = "getA()";
                method = "setA(int _int)";
                method = "setB(float _float)";
@@ -73,12 +76,19 @@ public interface TestClassInterface {
                method = "setACAndGetA(String newC, int newA)";
        }
 
-       struct StructJ {
+       enum Enum {
+
+               APPLE,
+               ORANGE,
+               GRAPE
+       }
+
+       struct Struct {
 
                string  name;
                float   value;
                int     year;
-       } 
+       }
 }
 
 
index c00b34de6ead60fd9959467c7e025fe88d5fc27a..e1cd73152e2f362e76828616fb70d95ba49c5e5a 100644 (file)
@@ -66,6 +66,7 @@ clean:
        cd $(BIN_DIR)/iotpolicy/output_files; rm -rf *.class *.gch
        cd $(BIN_DIR)/iotpolicy/output_files/Java; rm -rf *.class
        cd $(BIN_DIR)/iotpolicy/output_files/Cplus; rm -rf *.gch
+       cd $(BIN_DIR)/iotpolicy/output_files/Cplus; rm -rf *.out
 
 # RMI compilation and run
 PHONY += rmi
index 857199833799691896a5153f3e01c368d18319ec..f2d8397ec03a917c84905e303605b0be7a7fc64a 100644 (file)
@@ -403,7 +403,7 @@ public class IoTCompiler {
                                i++;
                        }
                        println(" };");
-                       println("private List<Integer> set" + newObjectId + "Allowed;");
+                       println("private static List<Integer> set" + newObjectId + "Allowed;");
                }
        }
 
@@ -490,6 +490,20 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: writeJavaCallbackPermission() writes the permission for callback
+        */
+       private void writeJavaCallbackPermission(String intface, int methodNumId) {
+
+               Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+               for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                       String newIntface = intMeth.getKey();
+                       int newObjectId = getNewIntfaceObjectId(newIntface);
+                       println("set" + newObjectId + "Allowed.add(" + methodNumId + ");");
+               }
+       }
+
+
        /**
         * HELPER: writeInitCallbackJavaStub() writes callback initialization in stub
         */
@@ -523,7 +537,9 @@ public class IoTCompiler {
                println("thread.start();\n");
                // Generate info sending part
                String method = "___initCallBack()";
-               println("int methodId = " + intDecl.getHelperMethodNumId(method) + ";");
+               int methodNumId = intDecl.getHelperMethodNumId(method);
+               println("int methodId = " + methodNumId + ";");
+               writeJavaCallbackPermission(intface, methodNumId);
                println("Class<?> retType = void.class;");
                println("Class<?>[] paramCls = new Class<?>[] { int.class, String.class, int.class };");
                println("Object[] paramObj = new Object[] { ports[0], address, 0 };");
@@ -2497,7 +2513,7 @@ public class IoTCompiler {
        /**
         * HELPER: writeMethodCplusStub() writes the methods of the stub
         */
-       private void writeMethodCplusStub(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
+       private void writeMethodCplusStub(String intface, Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
 
                for (String method : methods) {
 
@@ -2536,7 +2552,7 @@ public class IoTCompiler {
                        // Write the init callback helper method
                        if (isCallbackMethod) {
                                writeInitCallbackCplusStub(callbackType, intDecl);
-                               writeInitCallbackSendInfoCplusStub(intDecl);
+                               writeInitCallbackSendInfoCplusStub(intface, intDecl);
                        }
                }
        }
@@ -2585,7 +2601,7 @@ public class IoTCompiler {
                                //String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
                                //String prmType = getSimpleType(getEnumType(paramTypeC));
                                String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
-                               String prmType = getEnumType(paramTypeC);
+                               String prmType = getEnumCplusClsType(paramTypeC);
                                print("\"" + prmType + "\"");
                        }
                        if (i != methParams.size() - 1) // Check if this is the last element
@@ -2919,7 +2935,7 @@ public class IoTCompiler {
                                //String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
                                //String prmType = getSimpleType(getEnumType(paramTypeC));
                                String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
-                               String prmType = getEnumType(paramTypeC);
+                               String prmType = getEnumCplusClsType(paramTypeC);
                                print("\"" + prmType + "\"");
                                // Check if this is the last element (don't print a comma)
                                if (i != methParams.size() - 1) {
@@ -2977,7 +2993,7 @@ public class IoTCompiler {
                        String newIntface = intMeth.getKey();
                        int newObjectId = getNewIntfaceObjectId(newIntface);
                        println("const static int object" + newObjectId + "Id = " + newObjectId + ";\t//" + newIntface);
-                       println("const static set<int> set" + newObjectId + "Allowed;");
+                       println("static set<int> set" + newObjectId + "Allowed;");
                }
        }       
 
@@ -3105,16 +3121,32 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: writeCplusCallbackPermission() writes the permission for callback
+        */
+       private void writeCplusCallbackPermission(String intface, int methodNumId) {
+
+               Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+               for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                       String newIntface = intMeth.getKey();
+                       int newObjectId = getNewIntfaceObjectId(newIntface);
+                       println("set" + newObjectId + "Allowed.insert(" + methodNumId + ");");
+               }
+       }
+
+
        /**
         * HELPER: writeInitCallbackSendInfoCplusStub() writes the initialization (send info part) of callback
         */
-       private void writeInitCallbackSendInfoCplusStub(InterfaceDecl intDecl) {
+       private void writeInitCallbackSendInfoCplusStub(String intface, InterfaceDecl intDecl) {
 
                // Generate info sending part
                println("void ___regCB() {");
                println("int numParam = 3;");
                String method = "___initCallBack()";
-               println("int methodId = " + intDecl.getHelperMethodNumId(method) + ";");
+               int methodNumId = intDecl.getHelperMethodNumId(method);
+               println("int methodId = " + methodNumId + ";");
+               writeCplusCallbackPermission(intface, methodNumId);
                println("string retType = \"void\";");
                println("string paramCls[] = { \"int\", \"string\", \"int\" };");
                println("int rev = 0;");
@@ -3164,7 +3196,7 @@ public class IoTCompiler {
                                writeConstructorCplusStub(newStubClass, callbackExist, callbackClasses);
                                writeDeconstructorCplusStub(newStubClass, callbackExist, callbackClasses);
                                // Write methods
-                               writeMethodCplusStub(methods, intDecl, callbackClasses);
+                               writeMethodCplusStub(intface, methods, intDecl, callbackClasses);
                                print("}"); println(";");
                                if (callbackExist)
                                        writePermissionInitializationCplus(intface, newStubClass, intDecl);
@@ -3260,7 +3292,7 @@ public class IoTCompiler {
                                writeConstructorCplusCallbackStub(newStubClass, callbackExist, callbackClasses);
                                writeDeconstructorCplusStub(newStubClass, callbackExist, callbackClasses);
                                // Write methods
-                               writeMethodCplusStub(methods, intDecl, callbackClasses);
+                               writeMethodCplusStub(intface, methods, intDecl, callbackClasses);
                                println("};");
                                if (callbackExist)
                                        writePermissionInitializationCplus(intface, newStubClass, intDecl);
@@ -3316,7 +3348,7 @@ public class IoTCompiler {
                for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
                        String newIntface = intMeth.getKey();
                        int newObjectId = getNewIntfaceObjectId(newIntface);
-                       print("const set<int> " + newSkelClass + "::set" + newObjectId + "Allowed {");
+                       print("set<int> " + newSkelClass + "::set" + newObjectId + "Allowed {");
                        Set<String> methodIds = intMeth.getValue();
                        int i = 0;
                        for (String methodId : methodIds) {
@@ -3650,7 +3682,7 @@ public class IoTCompiler {
                                //String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
                                //String prmType = getSimpleType(getEnumType(paramTypeC));
                                String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
-                               String prmType = getEnumType(paramTypeC);
+                               String prmType = getEnumCplusClsType(paramTypeC);
                                print("\"" + prmType + "\"");
                        }
                        if (i != methParams.size() - 1) {
@@ -4725,6 +4757,21 @@ public class IoTCompiler {
                        return type;
        }
 
+       // Handle and return the correct enum declaration translate into int* for C
+       private String getEnumCplusClsType(String type) {
+
+               // Strips off array "[]" for return type
+               String pureType = getSimpleArrayType(type);
+               // Take the inner type of generic
+               if (getParamCategory(type) == ParamCategory.NONPRIMITIVES)
+                       pureType = getTypeOfGeneric(type)[0];
+               if (isEnumClass(pureType)) {
+                       String enumType = "int*";
+                       return enumType;
+               } else
+                       return type;
+       }
+
 
        // Handle and return the correct struct declaration
        private String getStructType(String type) {
index 492d3d996dc59fa26d4f780bab6706d3b8fc3983..63507122e15909461a191243413fdcc5114026fd 100644 (file)
@@ -43,6 +43,9 @@ class TestClass : public TestClassInterface {
                //void                          registerCallback(vector<CallBackInterfaceWithCallBack*> _cb);
                int                                     callBack();
 
+               // Enum
+               Enum                            handleEnum(Enum en);
+
                int                                     getA();
                void                            setA(int _int);
                void                            setB(float _float);
@@ -256,6 +259,25 @@ void TestClass::setC(string _string) {
 }
 
 
+// Enum
+Enum TestClass::handleEnum(Enum en) {
+
+       cout << "Enum: " << en << endl;
+       
+       return en;
+}
+
+
+/*vector<EnumC> TestClass::handleEnum(vector<EnumC> vecEn) {
+
+       for (EnumC en : vecEn) {
+               cout << "Enum: " << en << endl;
+       }
+       
+       return vecEn;
+}*/
+
+
 string TestClass::sumArray(vector<string> newA) {
 
        string sum = "";
index bac2b0e7b60ae35ec13d13cb223e1ff2260f56d1..a1c35c0718e251ae3997b6a30d9d01bbb4882cdf 100644 (file)
@@ -82,6 +82,12 @@ int main(int argc, char *argv[])
        inl7.push_back('c');
        inl7.push_back('e');
        cout << "Return value: " << tcStub->getCharList(inl7)[0] << ", "  << tcStub->getCharList(inl7)[1] << endl;
+       cout << "==== ENUM ====" << endl;
+       Enum en;
+       en = APPLE;
+       Enum res = tcStub->handleEnum(en);
+       cout << "Return value: " << res << endl;
+
        cout << "==== OTHERS ====" << endl;
        cout << "Return value: " << tcStub->getA() << endl;
        cout << "Return value: " << tcStub->setAndGetA(123) << endl;
index 2de5bb7df02a47541035e88171e8db8573878fec..01924a5951d6394b3290cac2e795da0805d4a7cf 100644 (file)
@@ -213,6 +213,25 @@ public class TestClass implements TestClassInterface {
        }
 
 
+       public Enum handleEnum(Enum en) {
+
+               System.out.println("Enum: " + en);
+                               
+               return en;
+       }
+
+
+       // Enum
+       /*public EnumJ[] handleEnum(EnumJ[] en) {
+
+               for (EnumJ e : en) {
+                       System.out.println("Enum: " + e);
+               }
+               
+               return en;
+       }*/
+
+
        // Getters
        public String sumArray(String[] newA) {
 
index 67b69dc476892adeed4dc8fb56236d5c0a60808f..26ecd4347e64e1749e76272c06ef49ed17a8d7d2 100644 (file)
@@ -60,6 +60,11 @@ public class TestClass_Stub {
                List<Character> inl7 = Arrays.asList(new Character[] { 'c', 'e' });
                System.out.println("Return value: " + tcstub.getCharList(inl7));
 
+               System.out.println("==== ENUM ====");
+               Enum en = Enum.APPLE;
+               Enum res = tcstub.handleEnum(en);
+               System.out.println("Enum member: " + res);
+
                System.out.println("==== OTHERS ====");
                System.out.println("Return value: " + tcstub.getA());
                System.out.println("Return value: " + tcstub.setAndGetA(123));