Adding object ID tracking for simultaneous generation of stubs/skeletons (e.g. for...
authorrtrimana <rtrimana@uci.edu>
Wed, 22 Feb 2017 18:35:57 +0000 (10:35 -0800)
committerrtrimana <rtrimana@uci.edu>
Wed, 22 Feb 2017 18:35:57 +0000 (10:35 -0800)
benchmarks/Java/SmartLightsController/CameraCallback_Skeleton.java
benchmarks/Java/SmartLightsController/CameraSmart_Stub.java
benchmarks/Java/SmartLightsController/LightBulbSmart_Stub.java
benchmarks/Java/SmartLightsController/RoomSmart_Stub.java
benchmarks/drivers/Java/AmcrestCamera/CameraSmartCallback_Stub.java
benchmarks/drivers/Java/AmcrestCamera/Camera_Skeleton.java
benchmarks/drivers/Java/LabRoom/Room_Skeleton.java
benchmarks/drivers/Java/LifxLightBulb/LightBulb_Skeleton.java
iotjava/Makefile
iotjava/iotpolicy/IoTCompiler.java

index 74103684ee37dbf06fca49e33f43a5510207ab06..0ee1c4fbc06dae5622acf8c68fae2b7ddee3f359 100644 (file)
@@ -17,22 +17,21 @@ import iotcode.interfaces.*;
 public class CameraCallback_Skeleton implements CameraCallback {
 
        private CameraCallback mainObj;
-       private int objectId = 0;
+       private int objectId = 3;
        // Communications and synchronizations
        private IoTRMIComm rmiComm;
        private AtomicBoolean didAlreadyInitWaitInvoke;
        private AtomicBoolean methodReceived;
        private byte[] methodBytes = null;
        // Permissions
-       private final static int object0Id = 0; //CameraSmartCallback
-       private static Integer[] object0Permission = { 0 };
-       private static List<Integer> set0Allowed;
+       private static Integer[] object3Permission = { 0 };
+       private static List<Integer> set3Allowed;
        
 
        public CameraCallback_Skeleton(CameraCallback _mainObj, int _portSend, int _portRecv) throws Exception {
                mainObj = _mainObj;
                rmiComm = new IoTRMICommServer(_portSend, _portRecv);
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
                IoTRMIUtil.mapSkel.put(_mainObj, this);
                IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
                didAlreadyInitWaitInvoke = new AtomicBoolean(false);
@@ -56,7 +55,7 @@ public class CameraCallback_Skeleton implements CameraCallback {
                mainObj = _mainObj;
                rmiComm = _rmiComm;
                objectId = _objectId;
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
                didAlreadyInitWaitInvoke = new AtomicBoolean(false);
                methodReceived = new AtomicBoolean(false);
                rmiComm.registerSkeleton(objectId, methodReceived);
@@ -88,7 +87,7 @@ public class CameraCallback_Skeleton implements CameraCallback {
                        int _objectId = IoTRMIComm.getObjectId(methodBytes);
                        int methodId = IoTRMIComm.getMethodId(methodBytes);
                        if (_objectId == objectId) {
-                               if (!set0Allowed.contains(methodId)) {
+                               if (!set3Allowed.contains(methodId)) {
                                        throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
                                }
                        }
index 48fe2f9012cda551c9615d38078a559ace65d1bb..788b4e148d85f86352e9db8e8a7e23801e7abb34 100644 (file)
@@ -16,7 +16,7 @@ import iotcode.interfaces.*;
 
 public class CameraSmart_Stub implements CameraSmart {
 
-       private int objectId = 0;
+       private int objectId = 2;
        private IoTRMIComm rmiComm;
        // Synchronization variables
        private AtomicBoolean retValueReceived8 = new AtomicBoolean(false);
index ef0c4bcb57c02c9ec0a00514b4a46f7a8ea879ae..978710fe012b5d6499b5fe63f9c8e831f7907305 100644 (file)
@@ -12,7 +12,7 @@ import iotrmi.Java.IoTRMICommClient;
 import iotrmi.Java.IoTRMICommServer;
 import iotrmi.Java.IoTRMIUtil;
 
-import iotcode.interfaces.LightBulbSmart;
+import iotcode.interfaces.*;
 
 public class LightBulbSmart_Stub implements LightBulbSmart {
 
index b1e7b410de57462d151657d65ee0dbbcb13c0b04..4a6f8298653c53c6b91f310eebf5213a0d33c59d 100644 (file)
@@ -12,11 +12,11 @@ import iotrmi.Java.IoTRMICommClient;
 import iotrmi.Java.IoTRMICommServer;
 import iotrmi.Java.IoTRMIUtil;
 
-import iotcode.interfaces.RoomSmart;
+import iotcode.interfaces.*;
 
 public class RoomSmart_Stub implements RoomSmart {
 
-       private int objectId = 2;
+       private int objectId = 4;
        private IoTRMIComm rmiComm;
        // Synchronization variables
        private AtomicBoolean retValueReceived0 = new AtomicBoolean(false);
index 0610f84c98d85ffa40eca060d20c690dae47c6ba..923737c91358ec1f16f8d4b83d2776c7d7ed1f40 100644 (file)
@@ -16,7 +16,7 @@ import iotcode.interfaces.*;
 
 public class CameraSmartCallback_Stub implements CameraSmartCallback {
 
-       private int objectId = 0;
+       private int objectId = 3;
        private IoTRMIComm rmiComm;
        // Synchronization variables
        
index cbb98bf0bcaa09911de0cd96ebb0caf39bb2cf1a..ccaf7a3f1952ef39c2b94bdbe28cf91d85e1e9c6 100644 (file)
@@ -17,22 +17,21 @@ import iotcode.interfaces.*;
 public class Camera_Skeleton implements Camera {
 
        private Camera mainObj;
-       private int objectId = 0;
+       private int objectId = 2;
        // Communications and synchronizations
        private IoTRMIComm rmiComm;
        private AtomicBoolean didAlreadyInitWaitInvoke;
        private AtomicBoolean methodReceived;
        private byte[] methodBytes = null;
        // Permissions
-       private final static int object0Id = 0; //CameraSmart
-       private static Integer[] object0Permission = { 8, 7, 9, 6, 2, 1, 4, 3, 0, 10, 5 };
-       private static List<Integer> set0Allowed;
+       private static Integer[] object2Permission = { 8, 7, 9, 6, 2, 1, 4, 3, 0, 10, 5 };
+       private static List<Integer> set2Allowed;
        
 
        public Camera_Skeleton(Camera _mainObj, int _portSend, int _portRecv) throws Exception {
                mainObj = _mainObj;
                rmiComm = new IoTRMICommServer(_portSend, _portRecv);
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
                IoTRMIUtil.mapSkel.put(_mainObj, this);
                IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
                didAlreadyInitWaitInvoke = new AtomicBoolean(false);
@@ -56,7 +55,7 @@ public class Camera_Skeleton implements Camera {
                mainObj = _mainObj;
                rmiComm = _rmiComm;
                objectId = _objectId;
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
                didAlreadyInitWaitInvoke = new AtomicBoolean(false);
                methodReceived = new AtomicBoolean(false);
                rmiComm.registerSkeleton(objectId, methodReceived);
@@ -232,7 +231,7 @@ public class Camera_Skeleton implements Camera {
                        int _objectId = IoTRMIComm.getObjectId(methodBytes);
                        int methodId = IoTRMIComm.getMethodId(methodBytes);
                        if (_objectId == objectId) {
-                               if (!set0Allowed.contains(methodId)) {
+                               if (!set2Allowed.contains(methodId)) {
                                        throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
                                }
                        }
index 015af4a3ae44fc3fa58bc67c6fea922cf86c2df3..222c0df24f5fcca33e5bb15fb000581bd41040d5 100644 (file)
@@ -17,22 +17,21 @@ import iotcode.interfaces.Room;
 public class Room_Skeleton implements Room {
 
        private Room mainObj;
-       private int objectId = 2;
+       private int objectId = 4;
        // Communications and synchronizations
        private IoTRMIComm rmiComm;
        private AtomicBoolean didAlreadyInitWaitInvoke;
        private AtomicBoolean methodReceived;
        private byte[] methodBytes = null;
        // Permissions
-       private final static int object0Id = 0; //RoomSmart
-       private static Integer[] object0Permission = { 0 };
-       private static List<Integer> set0Allowed;
+       private static Integer[] object4Permission = { 0 };
+       private static List<Integer> set4Allowed;
        
 
        public Room_Skeleton(Room _mainObj, int _portSend, int _portRecv) throws Exception {
                mainObj = _mainObj;
                rmiComm = new IoTRMICommServer(_portSend, _portRecv);
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
                IoTRMIUtil.mapSkel.put(_mainObj, this);
                IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
                didAlreadyInitWaitInvoke = new AtomicBoolean(false);
@@ -56,7 +55,7 @@ public class Room_Skeleton implements Room {
                mainObj = _mainObj;
                rmiComm = _rmiComm;
                objectId = _objectId;
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
                didAlreadyInitWaitInvoke = new AtomicBoolean(false);
                methodReceived = new AtomicBoolean(false);
                rmiComm.registerSkeleton(objectId, methodReceived);
@@ -89,7 +88,7 @@ public class Room_Skeleton implements Room {
                        int _objectId = IoTRMIComm.getObjectId(methodBytes);
                        int methodId = IoTRMIComm.getMethodId(methodBytes);
                        if (_objectId == objectId) {
-                               if (!set0Allowed.contains(methodId)) {
+                               if (!set4Allowed.contains(methodId)) {
                                        throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
                                }
                        }
index af9d8170997cd449536fa4eb703a86eb60006391..3b808fa327808ea32ac1f479029bf0ad50f24e34 100644 (file)
@@ -24,15 +24,14 @@ public class LightBulb_Skeleton implements LightBulb {
        private AtomicBoolean methodReceived;
        private byte[] methodBytes = null;
        // Permissions
-       private final static int object0Id = 0; //LightBulbSmart
-       private static Integer[] object0Permission = { 2, 10, 1, 3, 11, 8, 12, 7, 13, 9, 6, 16, 17, 4, 0, 14, 15, 5 };
-       private static List<Integer> set0Allowed;
+       private static Integer[] object1Permission = { 2, 10, 1, 3, 11, 8, 12, 7, 13, 9, 6, 16, 17, 4, 0, 14, 15, 5 };
+       private static List<Integer> set1Allowed;
        
 
        public LightBulb_Skeleton(LightBulb _mainObj, int _portSend, int _portRecv) throws Exception {
                mainObj = _mainObj;
                rmiComm = new IoTRMICommServer(_portSend, _portRecv);
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
                IoTRMIUtil.mapSkel.put(_mainObj, this);
                IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
                didAlreadyInitWaitInvoke = new AtomicBoolean(false);
@@ -56,7 +55,7 @@ public class LightBulb_Skeleton implements LightBulb {
                mainObj = _mainObj;
                rmiComm = _rmiComm;
                objectId = _objectId;
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
                didAlreadyInitWaitInvoke = new AtomicBoolean(false);
                methodReceived = new AtomicBoolean(false);
                rmiComm.registerSkeleton(objectId, methodReceived);
@@ -288,7 +287,7 @@ public class LightBulb_Skeleton implements LightBulb {
                        int _objectId = IoTRMIComm.getObjectId(methodBytes);
                        int methodId = IoTRMIComm.getMethodId(methodBytes);
                        if (_objectId == objectId) {
-                               if (!set0Allowed.contains(methodId)) {
+                               if (!set1Allowed.contains(methodId)) {
                                        throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
                                }
                        }
index 40c2436c622e12099744cb4d011c44e669e3588f..93ba52ce3497eef22ef1d6c2a53822c250b32711 100644 (file)
@@ -28,6 +28,12 @@ run-compiler-dev:
        cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler testclasspolicy_callbacks.pol testclassrequires_callbacks.pol callbackpolicy.pol callbackrequires.pol -cplus Cplus -java Java
        #cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler testclasspolicy_callbacks_three.pol testclassrequires_callbacks_three.pol callbackpolicy.pol callbackrequires.pol callbackpolicy_two.pol callbackrequires_two.pol -cplus Cplus -java Java
 
+PHONY += run-compiler-smartlight
+run-compiler-smartlight:
+       cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler lifxlightbulb.pol smartlightsbulb.req amcrestcamera.pol smartlightscam.req motiondetection.pol motiondetection.req room.pol roomsmart.req -java Java
+       
 PHONY += run-compiler-lbtest
 run-compiler-lbtest:
        cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
index 425eebce3774cda14dd01b0d189d535e48e7d465..a1144919e47a8f3e8e62be71e4fb692d9fe7c4f5 100644 (file)
@@ -61,6 +61,7 @@ public class IoTCompiler {
        private String subdir;
        private Map<String,Integer> mapPortCount;       // Counter for ports
        private static int portCount = 0;
+       private static int countObjId = 1;                      // Always increment object Id for a new stub/skeleton
        private String mainClass;
 
 
@@ -143,7 +144,7 @@ public class IoTCompiler {
                mapIntfacePTH.put(origInt, ptHandler);
                mapIntDeclHand.put(origInt, decHandler);
                // Set object Id counter to 0 for each interface
-               mapIntfaceObjId.put(origInt, new Integer(0));
+               mapIntfaceObjId.put(origInt, countObjId++);
        }
 
 
@@ -363,9 +364,9 @@ public class IoTCompiler {
         */
        private void updateIntfaceObjIdMap(String intface, String newIntface) {
 
+               // We are assuming that we only generate one stub per one skeleton at this point @Feb 2017
                Integer objId = mapIntfaceObjId.get(intface);
                mapNewIntfaceObjId.put(newIntface, objId);
-               mapIntfaceObjId.put(intface, objId++);
        }
 
 
@@ -416,8 +417,8 @@ public class IoTCompiler {
                for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
                        String newIntface = intMeth.getKey();
                        int newObjectId = getNewIntfaceObjectId(newIntface);
-                       println("private final static int object" + newObjectId + "Id = " + 
-                               newObjectId + ";\t//" + newIntface);
+                       //println("private final static int object" + newObjectId + "Id = " + 
+                       //      newObjectId + ";\t//" + newIntface);
                        Set<String> methodIds = intMeth.getValue();
                        print("private static Integer[] object" + newObjectId + "Permission = { ");
                        int i = 0;
@@ -520,42 +521,6 @@ public class IoTCompiler {
        }
 
 
-       /**
-        * HELPER: writeJavaMethodCallbackPermission() writes permission checks in stub for callbacks
-        */
-       private void writeJavaMethodCallbackPermission(String intface) {
-
-               println("int methodId = IoTRMIObject.getMethodId(method);");
-               // Get all the different stubs
-               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("if (!set" + newObjectId + "Allowed.contains(methodId)) {");
-                       println("throw new Error(\"Callback object for " + intface + " is not allowed to access method: \" + methodId);");
-                       println("}");
-               }
-       }
-
-
-       /**
-        * HELPER: writeJavaInitCallbackPermission() writes the permission for callback
-        */
-       private void writeJavaInitCallbackPermission(String intface, InterfaceDecl intDecl, boolean callbackExist) {
-
-               if (callbackExist) {
-                       String method = "___initCallBack()";
-                       int methodNumId = intDecl.getHelperMethodNumId(method);
-                       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: getPortCount() gets port count for different stubs and skeletons
         */
@@ -1191,7 +1156,9 @@ public class IoTCompiler {
        private void writePropertiesJavaSkeleton(String intface, InterfaceDecl intDecl) {
 
                println("private " + intface + " mainObj;");
-               println("private int objectId = 0;");
+               //println("private int objectId = 0;");
+               Integer objId = mapIntfaceObjId.get(intface);
+               println("private int objectId = " + objId + ";");
                println("// Communications and synchronizations");
                println("private IoTRMIComm rmiComm;");
                println("private AtomicBoolean didAlreadyInitWaitInvoke;");
@@ -1245,7 +1212,6 @@ public class IoTCompiler {
                println("rmiComm = new IoTRMICommServer(_portSend, _portRecv);");
                // Generate permission control initialization
                writeConstructorJavaPermission(intface);
-               //writeJavaInitCallbackPermission(intface, intDecl, callbackExist);
                writeStructPermissionJavaSkeleton(methods, intDecl, intface);
                println("IoTRMIUtil.mapSkel.put(_mainObj, this);");
                println("IoTRMIUtil.mapSkelId.put(_mainObj, objectId);");
@@ -3065,7 +3031,6 @@ public class IoTCompiler {
                for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
                        String newIntface = intMeth.getKey();
                        int newObjectId = getNewIntfaceObjectId(newIntface);
-                       println("int objectId = " + newObjectId + ";");
                        println("static set<int> set" + newObjectId + "Allowed;");
                }
        }       
@@ -3153,25 +3118,6 @@ public class IoTCompiler {
        }
 
 
-       /**
-        * HELPER: writeCplusMethodCallbackPermission() writes permission checks in stub for callbacks
-        */
-       private void writeCplusMethodCallbackPermission(String intface) {
-
-               println("int methodId = IoTRMIObject::getMethodId(method);");
-               // Get all the different stubs
-               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("if (set" + newObjectId + "Allowed.find(methodId) == set" + newObjectId + "Allowed.end()) {");
-                       println("cerr << \"Callback object for " + intface + " is not allowed to access method: \" << methodId;");
-                       println("return;");
-                       println("}");
-               }
-       }
-
-
        /**
         * generateCPlusStubClassesHpp() generate stubs based on the methods list in C++ (.hpp file)
         */
@@ -3310,6 +3256,8 @@ public class IoTCompiler {
                println("IoTRMIComm *rmiComm;");
                println("char* methodBytes;");
                println("int methodLen;");
+               Integer objId = mapIntfaceObjId.get(intface);
+               println("int objectId = " + objId + ";");
                // Keep track of object Ids of all stubs registered to this interface
                writePropertiesCplusPermission(intface);
                println("// Synchronization variables");