Adding permission insertion for struct (will be tested later)
authorrtrimana <rtrimana@uci.edu>
Tue, 29 Nov 2016 22:06:15 +0000 (14:06 -0800)
committerrtrimana <rtrimana@uci.edu>
Tue, 29 Nov 2016 22:06:15 +0000 (14:06 -0800)
iotjava/iotpolicy/IoTCompiler.java

index e48df3571b7067050977bac980eb22640939c70c..ab19e6a313c69d1a29e29b124c07146dadcc8304 100644 (file)
@@ -1214,10 +1214,39 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: writeStructPermissionJavaSkeleton() writes permission for struct helper
+        */
+       private void writeStructPermissionJavaSkeleton(Collection<String> methods, InterfaceDecl intDecl, String intface) {
+
+               // Use this set to handle two same methodIds
+               for (String method : methods) {
+                       List<String> methParams = intDecl.getMethodParams(method);
+                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                       // Check for params with structs
+                       for (int i = 0; i < methParams.size(); i++) {
+                               String paramType = methPrmTypes.get(i);
+                               String param = methParams.get(i);
+                               String simpleType = getSimpleType(paramType);
+                               if (isStructClass(simpleType)) {
+                                       int methodNumId = intDecl.getMethodNumId(method);
+                                       // Iterate over interfaces to give permissions to
+                                       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: writeConstructorJavaSkeleton() writes the constructor of the skeleton class
         */
-       private void writeConstructorJavaSkeleton(String newSkelClass, String intface, InterfaceDecl intDecl) {
+       private void writeConstructorJavaSkeleton(String newSkelClass, String intface, InterfaceDecl intDecl, Collection<String> methods) {
 
                println("public " + newSkelClass + "(" + intface + " _mainObj, int _port) throws Exception {");
                println("mainObj = _mainObj;");
@@ -1225,6 +1254,7 @@ public class IoTCompiler {
                // Generate permission control initialization
                writeConstructorJavaPermission(intface);
                writeJavaInitCallbackPermission(intface, intDecl);
+               writeStructPermissionJavaSkeleton(methods, intDecl, intface);
                println("___waitRequestInvokeMethod();");
                println("}\n");
        }
@@ -2094,7 +2124,7 @@ public class IoTCompiler {
                        // Write properties
                        writePropertiesJavaSkeleton(intface, callbackExist, intDecl);
                        // Write constructor
-                       writeConstructorJavaSkeleton(newSkelClass, intface, intDecl);
+                       writeConstructorJavaSkeleton(newSkelClass, intface, intDecl, methods);
                        // Write methods
                        writeMethodJavaSkeleton(methods, intDecl, callbackClasses, false);
                        // Write method helper
@@ -2128,11 +2158,12 @@ public class IoTCompiler {
        /**
         * HELPER: writeConstructorJavaCallbackSkeleton() writes the constructor of the skeleton class
         */
-       private void writeConstructorJavaCallbackSkeleton(String newSkelClass, String intface) {
+       private void writeConstructorJavaCallbackSkeleton(String newSkelClass, String intface, InterfaceDecl intDecl, Collection<String> methods) {
 
                println("public " + newSkelClass + "(" + intface + " _mainObj, int _objectId) throws Exception {");
                println("mainObj = _mainObj;");
                println("objectId = _objectId;");
+               writeStructPermissionJavaSkeleton(methods, intDecl, intface);
                println("}\n");
        }
 
@@ -2275,7 +2306,7 @@ public class IoTCompiler {
                        // Write properties
                        writePropertiesJavaCallbackSkeleton(intface, callbackExist);
                        // Write constructor
-                       writeConstructorJavaCallbackSkeleton(newSkelClass, intface);
+                       writeConstructorJavaCallbackSkeleton(newSkelClass, intface, intDecl, methods);
                        // Write methods
                        writeMethodJavaSkeleton(methods, intDecl, callbackClasses, true);
                        // Write method helper
@@ -3369,16 +3400,46 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: writeStructPermissionCplusSkeleton() writes permission for struct helper
+        */
+       private void writeStructPermissionCplusSkeleton(Collection<String> methods, InterfaceDecl intDecl, String intface) {
+
+               // Use this set to handle two same methodIds
+               for (String method : methods) {
+                       List<String> methParams = intDecl.getMethodParams(method);
+                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                       // Check for params with structs
+                       for (int i = 0; i < methParams.size(); i++) {
+                               String paramType = methPrmTypes.get(i);
+                               String param = methParams.get(i);
+                               String simpleType = getSimpleType(paramType);
+                               if (isStructClass(simpleType)) {
+                                       int methodNumId = intDecl.getMethodNumId(method);
+                                       // Iterate over interfaces to give permissions to
+                                       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: writeConstructorCplusSkeleton() writes the constructor of the skeleton class
         */
-       private void writeConstructorCplusSkeleton(String newSkelClass, String intface, boolean callbackExist, InterfaceDecl intDecl) {
+       private void writeConstructorCplusSkeleton(String newSkelClass, String intface, boolean callbackExist, InterfaceDecl intDecl, Collection<String> methods) {
 
                println(newSkelClass + "(" + intface + " *_mainObj, int _port) {");
                println("bool _bResult = false;");
                println("mainObj = _mainObj;");
                println("rmiObj = new IoTRMIObject(_port, &_bResult);");
                writeCplusInitCallbackPermission(intface, intDecl);
+               writeStructPermissionCplusSkeleton(methods, intDecl, intface);
                println("___waitRequestInvokeMethod();");
                println("}\n");
        }
@@ -4155,7 +4216,7 @@ public class IoTCompiler {
                        writePropertiesCplusSkeleton(intface, callbackExist, callbackClasses);
                        println("public:\n");
                        // Write constructor
-                       writeConstructorCplusSkeleton(newSkelClass, intface, callbackExist, intDecl);
+                       writeConstructorCplusSkeleton(newSkelClass, intface, callbackExist, intDecl, methods);
                        // Write deconstructor
                        writeDeconstructorCplusSkeleton(newSkelClass, callbackExist, callbackClasses);
                        // Write methods
@@ -4199,11 +4260,12 @@ public class IoTCompiler {
        /**
         * HELPER: writeConstructorCplusCallbackSkeleton() writes the constructor of the skeleton class
         */
-       private void writeConstructorCplusCallbackSkeleton(String newSkelClass, String intface, boolean callbackExist) {
+       private void writeConstructorCplusCallbackSkeleton(String newSkelClass, String intface, boolean callbackExist, InterfaceDecl intDecl, Collection<String> methods) {
 
                println(newSkelClass + "(" + intface + " *_mainObj, int _objectId) {");
                println("mainObj = _mainObj;");
                println("objectId = _objectId;");
+               writeStructPermissionCplusSkeleton(methods, intDecl, intface);
                println("}\n");
        }
 
@@ -4375,7 +4437,7 @@ public class IoTCompiler {
                        writePropertiesCplusCallbackSkeleton(intface, callbackExist, callbackClasses);
                        println("public:\n");
                        // Write constructor
-                       writeConstructorCplusCallbackSkeleton(newSkelClass, intface, callbackExist);
+                       writeConstructorCplusCallbackSkeleton(newSkelClass, intface, callbackExist, intDecl, methods);
                        // Write deconstructor
                        writeDeconstructorCplusCallbackSkeleton(newSkelClass, callbackExist, callbackClasses);
                        // Write methods