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);
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);
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);
}
}
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);
import iotrmi.Java.IoTRMICommServer;
import iotrmi.Java.IoTRMIUtil;
-import iotcode.interfaces.LightBulbSmart;
+import iotcode.interfaces.*;
public class LightBulbSmart_Stub implements LightBulbSmart {
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);
public class CameraSmartCallback_Stub implements CameraSmartCallback {
- private int objectId = 0;
+ private int objectId = 3;
private IoTRMIComm rmiComm;
// Synchronization variables
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);
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);
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);
}
}
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);
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);
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);
}
}
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);
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);
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);
}
}
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/
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;
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++);
}
*/
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++);
}
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;
}
- /**
- * 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
*/
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;");
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);");
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;");
}
}
}
- /**
- * 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)
*/
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");