From 7b3e56c92613a88e1c54e65ba35d5dba9c41f2e8 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Tue, 29 Nov 2016 14:06:15 -0800 Subject: [PATCH] Adding permission insertion for struct (will be tested later) --- iotjava/iotpolicy/IoTCompiler.java | 78 +++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index e48df35..ab19e6a 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -1214,10 +1214,39 @@ public class IoTCompiler { } + /** + * HELPER: writeStructPermissionJavaSkeleton() writes permission for struct helper + */ + private void writeStructPermissionJavaSkeleton(Collection methods, InterfaceDecl intDecl, String intface) { + + // Use this set to handle two same methodIds + for (String method : methods) { + List methParams = intDecl.getMethodParams(method); + List 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> mapNewIntMethods = mapInt2NewInts.get(intface); + for (Map.Entry> 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 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 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 methods, InterfaceDecl intDecl, String intface) { + + // Use this set to handle two same methodIds + for (String method : methods) { + List methParams = intDecl.getMethodParams(method); + List 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> mapNewIntMethods = mapInt2NewInts.get(intface); + for (Map.Entry> 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 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 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 -- 2.34.1