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(newStubClass + "* obj = (" + newStubClass + "*) t;");
println("delete obj;");
println("}\n");
- //println("extern \"C\" void init" + newStubClass + "(void* t) {");
+ println("extern \"C\" void init" + newStubClass + "(void* t) {");
//println(newStubClass + "* obj = (" + newStubClass + "*) t;");
//println("obj->init();");
//println("while(true);");
- //println("}\n");
+ println("}\n");
}
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");
println("extern \"C\" void* create" + newSkelClass + "(void** params) {");
println("// Args: *_mainObj, int _portSend, int _portRecv");
- println("return new " + newSkelClass + "((" + intface + "*) params[0], *((int*) params[0]), *((int*) params[1]));");
+ println("return new " + newSkelClass + "((" + intface + "*) params[0], *((int*) params[1]), *((int*) params[2]));");
println("}\n");
println("extern \"C\" void destroy" + newSkelClass + "(void* t) {");
println(newSkelClass + "* obj = (" + newSkelClass + "*) t;");
println("delete obj;");
println("}\n");
- //println("extern \"C\" void init" + newSkelClass + "(void* t) {");
+ println("extern \"C\" void init" + newSkelClass + "(void* t) {");
//println(newSkelClass + "* obj = (" + newSkelClass + "*) t;");
//println("obj->init();");
//println("while(true);");
- //println("}\n");
+ println("}\n");
}