private Map<String,ParseTreeHandler> mapIntfacePTH;
private Map<String,DeclarationHandler> mapIntDeclHand;
private Map<String,Map<String,Set<String>>> mapInt2NewInts;
+ private Map<String,String> mapInt2NewIntName;
// Data structure to store our types (primitives and non-primitives) for compilation
private Map<String,String> mapPrimitives;
private Map<String,String> mapNonPrimitivesJava;
private PrintWriter pw;
private String dir;
private String subdir;
+ private Map<String,Integer> mapPortCount; // Counter for ports
+ private static int portCount = 0;
/**
mapIntfacePTH = new HashMap<String,ParseTreeHandler>();
mapIntDeclHand = new HashMap<String,DeclarationHandler>();
mapInt2NewInts = new HashMap<String,Map<String,Set<String>>>();
+ mapInt2NewIntName = new HashMap<String,String>();
mapIntfaceObjId = new HashMap<String,Integer>();
mapNewIntfaceObjId = new HashMap<String,Integer>();
mapPrimitives = new HashMap<String,String>();
arraysToMap(mapNonPrimitivesJava, IoTRMITypes.nonPrimitivesJava, IoTRMITypes.nonPrimitiveJavaLibs);
mapNonPrimitivesCplus = new HashMap<String,String>();
arraysToMap(mapNonPrimitivesCplus, IoTRMITypes.nonPrimitivesJava, IoTRMITypes.nonPrimitivesCplus);
+ mapPortCount = new HashMap<String,Integer>();
pw = null;
dir = OUTPUT_DIRECTORY;
subdir = null;
}
// Add interface and methods information into map
mapNewIntMethods.put(strInt, setMethods);
+ // Map new interface method name to the original interface
+ // TODO: perhaps need to check in the future if we have more than 1 stub interface for one original interface
+ mapInt2NewIntName.put(origInt, strInt);
}
// Map the map of interface-methods to the original interface
mapInt2NewInts.put(origInt, mapNewIntMethods);
}
+ /**
+ * HELPER: updateIntfaceObjIdMap() updates the mapping between new interface and object Id
+ */
+ private void updateIntfaceObjIdMap(String intface, String newIntface) {
+
+ Integer objId = mapIntfaceObjId.get(intface);
+ mapNewIntfaceObjId.put(newIntface, objId);
+ mapIntfaceObjId.put(intface, objId++);
+ }
+
+
/**
* generateJavaInterfaces() generate stub interfaces based on the methods list in Java
*/
DeclarationHandler decHandler = mapIntDeclHand.get(intface);
InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(intface);
// Pass in set of methods and get import classes
- List<String> methods = intDecl.getMethods();
+ Set<String> methods = intMeth.getValue();
Set<String> importClasses = getImportClasses(methods, intDecl);
List<String> stdImportClasses = getStandardJavaIntfaceImportClasses();
List<String> allImportClasses = getAllLibClasses(stdImportClasses, importClasses);
// Write interface header
println("");
println("public interface " + newIntface + " {\n");
+ updateIntfaceObjIdMap(intface, newIntface);
// Write methods
writeMethodJavaInterface(methods, intDecl);
println("}");
// Get the object Id
Integer objId = mapIntfaceObjId.get(intface);
println("private final static int objectId = " + objId + ";");
- mapNewIntfaceObjId.put(newIntface, objId);
- mapIntfaceObjId.put(intface, objId++);
+ //mapNewIntfaceObjId.put(newIntface, objId);
+ //mapIntfaceObjId.put(intface, objId++);
if (callbackExist) {
// We assume that each class only has one callback interface for now
Iterator it = callbackClasses.iterator();
println("// Callback properties");
println("private IoTRMIObject rmiObj;");
println("List<" + callbackType + "> listCallbackObj;");
- println("private static int objIdCnt = 0;");
+ println("private int objIdCnt = 0;");
// Generate permission stuff for callback stubs
DeclarationHandler decHandler = mapIntDeclHand.get(callbackType);
InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType);
if (callbackExist) {
Iterator it = callbackClasses.iterator();
String callbackType = (String) it.next();
- writeConstructorJavaPermission(intface);
+ writeConstructorJavaPermission(callbackType);
println("listCallbackObj = new ArrayList<" + callbackType + ">();");
+ DeclarationHandler decHandler = mapIntDeclHand.get(callbackType);
+ InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType);
+ writeJavaInitCallbackPermission(callbackType, intDecl, callbackExist);
println("___initCallBack();");
}
println("}\n");
}
+ /**
+ * HELPER: getPortCount() gets port count for different stubs and skeletons
+ */
+ private int getPortCount(String intface) {
+
+ if (!mapPortCount.containsKey(intface))
+ mapPortCount.put(intface, portCount++);
+ return mapPortCount.get(intface);
+ }
+
+
/**
* HELPER: writeInitCallbackJavaStub() writes callback initialization in stub
*/
- private void writeInitCallbackJavaStub(String intface, InterfaceDecl intDecl) {
+ private void writeInitCallbackJavaStub(String intface, InterfaceDecl intDecl, String newStubClass) {
println("public void ___initCallBack() {");
// Generate main thread for callbacks
println("Thread thread = new Thread() {");
println("public void run() {");
println("try {");
- println("rmiObj = new IoTRMIObject(ports[0]);");
+ int port = getPortCount(newStubClass);
+ println("rmiObj = new IoTRMIObject(ports[" + port + "]);");
println("while (true) {");
println("byte[] method = rmiObj.getMethodBytes();");
- writeJavaMethodCallbackPermission(intface);
println("int objId = IoTRMIObject.getObjectId(method);");
println(intface + "_CallbackSkeleton skel = (" + intface + "_CallbackSkeleton) listCallbackObj.get(objId);");
println("if (skel != null) {");
+ writeJavaMethodCallbackPermission(intface);
println("skel.invokeMethod(rmiObj);");
print("}");
println(" else {");
int methodNumId = intDecl.getHelperMethodNumId(method);
println("int methodId = " + methodNumId + ";");
println("Class<?> retType = void.class;");
- println("Class<?>[] paramCls = new Class<?>[] { int.class, String.class, int.class };");
- println("Object[] paramObj = new Object[] { ports[0], callbackAddress, 0 };");
+ println("Class<?>[] paramCls = new Class<?>[] { int[].class, String.class, int.class };");
+ println("Object[] paramObj = new Object[] { ports, callbackAddress, 0 };");
println("rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
println("}\n");
}
String param = methParams.get(i);
if (isArrayOrList(paramType, param)) { // Generate loop
println("for (" + getGenericType(paramType) + " cb : " + getSimpleIdentifier(param) + ") {");
- println(callbackType + "_CallbackSkeleton skel" + i + " = new " + callbackType + "_CallbackSkeleton(cb, objIdCnt++);");
+ println(callbackType + "_CallbackSkeleton skel" + i + " = new " + callbackType + "_CallbackSkeleton(cb, callbackAddress, objIdCnt++);");
} else
println(callbackType + "_CallbackSkeleton skel" + i + " = new " + callbackType + "_CallbackSkeleton(" +
- getSimpleIdentifier(param) + ", objIdCnt++);");
+ getSimpleIdentifier(param) + ", callbackAddress, objIdCnt++);");
println("listCallbackObj.add(skel" + i + ");");
if (isArrayOrList(paramType, param))
println("}");
/**
* HELPER: writeMethodJavaStub() writes the methods of the stub class
*/
- private void writeMethodJavaStub(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
+ private void writeMethodJavaStub(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses, String newStubClass) {
boolean isDefined = false;
for (String method : methods) {
println("}\n");
// Write the init callback helper method
if (isCallbackMethod && !isDefined) {
- writeInitCallbackJavaStub(callbackType, intDecl);
+ writeInitCallbackJavaStub(callbackType, intDecl, newStubClass);
isDefined = true;
}
}
}
+ /**
+ * HELPER: getStubInterface() gets stub interface name based on original interface
+ */
+ public String getStubInterface(String intface) {
+
+ return mapInt2NewIntName.get(intface);
+ }
+
+
/**
* generateJavaStubClasses() generate stubs based on the methods list in Java
*/
// Write constructor
writeConstructorJavaStub(intface, newStubClass, callbackExist, callbackClasses);
// Write methods
- writeMethodJavaStub(intMeth.getValue(), intDecl, callbackClasses);
+ writeMethodJavaStub(intMeth.getValue(), intDecl, callbackClasses, newStubClass);
println("}");
pw.close();
System.out.println("IoTCompiler: Generated stub class " + newStubClass + ".java...");
private void writePropertiesJavaCallbackStub(String intface, String newIntface, boolean callbackExist, Set<String> callbackClasses) {
println("private IoTRMICall rmiCall;");
- println("private String address;");
+ println("private String callbackAddress;");
println("private int[] ports;\n");
// Get the object Id
println("private int objectId = 0;");
println("// Callback properties");
println("private IoTRMIObject rmiObj;");
println("List<" + callbackType + "> listCallbackObj;");
- println("private static int objIdCnt = 0;");
+ println("private int objIdCnt = 0;");
// Generate permission stuff for callback stubs
DeclarationHandler decHandler = mapIntDeclHand.get(callbackType);
InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType);
private void writeConstructorJavaCallbackStub(String intface, String newStubClass, boolean callbackExist, Set<String> callbackClasses) {
// TODO: If we want callback in callback, then we need to add address and port initializations
- println("public " + newStubClass + "(IoTRMICall _rmiCall, int _objectId) throws Exception {");
+ println("public " + newStubClass + "(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {");
+ println("callbackAddress = _callbackAddress;");
println("objectId = _objectId;");
println("rmiCall = _rmiCall;");
+ println("ports = _ports;");
if (callbackExist) {
Iterator it = callbackClasses.iterator();
String callbackType = (String) it.next();
- writeConstructorJavaPermission(intface);
+ writeConstructorJavaPermission(callbackType);
println("listCallbackObj = new ArrayList<" + callbackType + ">();");
+ DeclarationHandler decHandler = mapIntDeclHand.get(callbackType);
+ InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType);
+ writeJavaInitCallbackPermission(callbackType, intDecl, callbackExist);
println("___initCallBack();");
- println("// TODO: Add address and port initialization here if we want callback in callback!");
}
println("}\n");
}
writeConstructorJavaCallbackStub(intface, newStubClass, callbackExist, callbackClasses);
// Write methods
// TODO: perhaps need to generate callback for callback
- writeMethodJavaStub(intMeth.getValue(), intDecl, callbackClasses);
+ writeMethodJavaStub(intMeth.getValue(), intDecl, callbackClasses, newStubClass);
println("}");
pw.close();
System.out.println("IoTCompiler: Generated callback stub class " + newStubClass + ".java...");
println("private " + intface + " mainObj;");
//println("private int ports;");
println("private IoTRMIObject rmiObj;\n");
+ println("private String callbackAddress;");
// Callback
if (callbackExist) {
- println("private static int objIdCnt = 0;");
+ println("private int objIdCnt = 0;");
println("private IoTRMICall rmiCall;");
+ println("private int[] ports;\n");
}
writePropertiesJavaPermission(intface, intDecl);
println("\n");
*/
private void writeConstructorJavaSkeleton(String newSkelClass, String intface, InterfaceDecl intDecl, Collection<String> methods, boolean callbackExist) {
- println("public " + newSkelClass + "(" + intface + " _mainObj, int _port) throws Exception {");
+ println("public " + newSkelClass + "(" + intface + " _mainObj, String _callbackAddress, int _port) throws Exception {");
println("mainObj = _mainObj;");
+ println("callbackAddress = _callbackAddress;");
println("rmiObj = new IoTRMIObject(_port);");
// Generate permission control initialization
writeConstructorJavaPermission(intface);
/**
* HELPER: writeInitCallbackJavaSkeleton() writes the init callback method for skeleton class
*/
- private void writeInitCallbackJavaSkeleton(boolean callbackSkeleton) {
+ private void writeInitCallbackJavaSkeleton(boolean callbackSkeleton, String intface) {
// This is a callback skeleton generation
if (callbackSkeleton)
println("public void ___regCB(IoTRMIObject rmiObj) throws IOException {");
else
println("public void ___regCB() throws IOException {");
- print("Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class },");
+ print("Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class, String.class, int.class },");
println("new Class<?>[] { null, null, null });");
- println("rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], (int) paramObj[2]);");
+ println("ports = (int[]) paramObj[0];");
+ String stubInt = null;
+ if (callbackSkeleton)
+ stubInt = getStubInterface(intface) + "_CallbackStub";
+ else
+ stubInt = getStubInterface(intface) + "_Stub";
+ int port = getPortCount(stubInt);
+ println("rmiCall = new IoTRMICall(ports[" + port + "], (String) paramObj[1], (int) paramObj[2]);");
println("}\n");
}
* HELPER: writeMethodJavaSkeleton() writes the method of the skeleton class
*/
private void writeMethodJavaSkeleton(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses,
- boolean callbackSkeleton) {
+ boolean callbackSkeleton, String intface) {
boolean isDefined = false;
for (String method : methods) {
writeStdMethodBodyJavaSkeleton(methParams, methodId, intDecl.getMethodType(method));
println("}\n");
if (isCallbackMethod && !isDefined) { // Make sure that this function is only defined once!
- writeInitCallbackJavaSkeleton(callbackSkeleton);
+ writeInitCallbackJavaSkeleton(callbackSkeleton, intface);
isDefined = true;
}
}
println("int numStubs" + i + " = (int) paramObj[" + offsetPfx + i + "];");
println("List<" + exchParamType + "> stub" + i + " = new ArrayList<" + exchParamType + ">();");
} else {
- println(exchParamType + " stub" + i + " = new " + exchParamType + "_CallbackStub(rmiCall, objIdCnt);");
+ println(exchParamType + " stub" + i + " = new " + exchParamType + "_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);");
println("objIdCnt++;");
}
}
String exchParamType = checkAndGetParamClass(getGenericType(paramType));
if (isArray(param)) {
println("for (int objId = 0; objId < numStubs" + i + "; objId++) {");
- println("stub" + i + "[objId] = new " + exchParamType + "_CallbackStub(rmiCall, objIdCnt);");
+ println("stub" + i + "[objId] = new " + exchParamType + "_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);");
println("objIdCnt++;");
println("}");
} else if (isList(paramType)) {
println("for (int objId = 0; objId < numStubs" + i + "; objId++) {");
- println("stub" + i + ".add(new " + exchParamType + "_CallbackStub(rmiCall, objIdCnt));");
+ println("stub" + i + ".add(new " + exchParamType + "_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports));");
println("objIdCnt++;");
println("}");
}
// Write constructor
writeConstructorJavaSkeleton(newSkelClass, intface, intDecl, methods, callbackExist);
// Write methods
- writeMethodJavaSkeleton(methods, intDecl, callbackClasses, false);
+ writeMethodJavaSkeleton(methods, intDecl, callbackClasses, false, intface);
// Write method helper
writeMethodHelperJavaSkeleton(methods, intDecl, callbackClasses);
// Write waitRequestInvokeMethod() - main loop
println("private " + intface + " mainObj;");
// For callback skeletons, this is its own object Id
println("private int objectId = 0;");
+ println("private String callbackAddress;");
// Callback
if (callbackExist) {
- println("private static int objIdCnt = 0;");
+
+ println("private int objIdCnt = 0;");
println("private IoTRMICall rmiCall;");
+ println("private int[] ports;\n");
}
println("\n");
}
*/
private void writeConstructorJavaCallbackSkeleton(String newSkelClass, String intface, InterfaceDecl intDecl, Collection<String> methods) {
- println("public " + newSkelClass + "(" + intface + " _mainObj, int _objectId) throws Exception {");
+ println("public " + newSkelClass + "(" + intface + " _mainObj, String _callbackAddress, int _objectId) throws Exception {");
+ println("callbackAddress = _callbackAddress;");
println("mainObj = _mainObj;");
println("objectId = _objectId;");
println("}\n");
// Write constructor
writeConstructorJavaCallbackSkeleton(newSkelClass, intface, intDecl, methods);
// Write methods
- writeMethodJavaSkeleton(methods, intDecl, callbackClasses, true);
+ writeMethodJavaSkeleton(methods, intDecl, callbackClasses, true, intface);
// Write method helper
writeMethodHelperJavaCallbackSkeleton(methods, intDecl, callbackClasses);
// Write waitRequestInvokeMethod() - main loop
println("#ifndef _" + newIntface.toUpperCase() + "_HPP__");
println("#define _" + newIntface.toUpperCase() + "_HPP__");
println("#include <iostream>");
+ updateIntfaceObjIdMap(intface, newIntface);
// Pass in set of methods and get import classes
- Set<String> includeClasses = getIncludeClasses(intMeth.getValue(), intDecl, intface, false);
+ Set<String> methods = intMeth.getValue();
+ Set<String> includeClasses = getIncludeClasses(methods, intDecl, intface, false);
List<String> stdIncludeClasses = getStandardCplusIncludeClasses();
List<String> allIncludeClasses = getAllLibClasses(stdIncludeClasses, includeClasses);
printIncludeStatements(allIncludeClasses); println("");
println("{");
println("public:");
// Write methods
- writeMethodCplusInterface(intMeth.getValue(), intDecl);
+ writeMethodCplusInterface(methods, intDecl);
println("};");
println("#endif");
pw.close();
/**
* HELPER: writeMethodCplusStub() writes the methods of the stub
*/
- private void writeMethodCplusStub(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
+ private void writeMethodCplusStub(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses, String newStubClass) {
boolean isDefined = false;
for (String method : methods) {
println("}\n");
// Write the init callback helper method
if (isCallbackMethod && !isDefined) {
- writeInitCallbackCplusStub(callbackType, intDecl);
+ writeInitCallbackCplusStub(callbackType, intDecl, newStubClass);
writeInitCallbackSendInfoCplusStub(intDecl);
isDefined = true;
}
String param = methParams.get(i);
if (isArrayOrList(paramType, param)) { // Generate loop
println("for (" + getGenericType(paramType) + "* cb : " + getSimpleIdentifier(param) + ") {");
- println(callbackType + "_CallbackSkeleton* skel" + i + " = new " + callbackType + "_CallbackSkeleton(cb, objIdCnt++);");
+ println(callbackType + "_CallbackSkeleton* skel" + i + " = new " + callbackType + "_CallbackSkeleton(cb, callbackAddress, objIdCnt++);");
isArrayOrList = true;
callbackParam = getSimpleIdentifier(param);
} else
println(callbackType + "_CallbackSkeleton* skel" + i + " = new " + callbackType + "_CallbackSkeleton(" +
- getSimpleIdentifier(param) + ", objIdCnt++);");
+ getSimpleIdentifier(param) + ", callbackAddress, objIdCnt++);");
println("vecCallbackObj.push_back(skel" + i + ");");
if (isArrayOrList)
println("}");
// Get the object Id
Integer objId = mapIntfaceObjId.get(intface);
println("const static int objectId = " + objId + ";");
- mapNewIntfaceObjId.put(newIntface, objId);
- mapIntfaceObjId.put(intface, objId++);
if (callbackExist) {
// We assume that each class only has one callback interface for now
Iterator it = callbackClasses.iterator();
private void writeConstructorCplusStub(String newStubClass, boolean callbackExist, Set<String> callbackClasses) {
println(newStubClass +
- "(int _port, const char* _skeletonAddress, const char* _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {");
+ "(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {");
println("callbackAddress = _callbackAddress;");
println("ports = _ports;");
println("rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev, _bResult);");
if (callbackExist) {
Iterator it = callbackClasses.iterator();
String callbackType = (String) it.next();
+ DeclarationHandler decHandler = mapIntDeclHand.get(callbackType);
+ InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType);
+ writeCplusInitCallbackPermission(callbackType, intDecl, callbackExist);
println("thread th1 (&" + newStubClass + "::___initCallBack, this);");
println("th1.detach();");
println("___regCB();");
/**
* HELPER: writeInitCallbackCplusStub() writes the initialization of callback
*/
- private void writeInitCallbackCplusStub(String intface, InterfaceDecl intDecl) {
+ private void writeInitCallbackCplusStub(String intface, InterfaceDecl intDecl, String newStubClass) {
println("void ___initCallBack() {");
println("bool bResult = false;");
- println("rmiObj = new IoTRMIObject(ports[0], &bResult);");
+ int port = getPortCount(newStubClass);
+ println("rmiObj = new IoTRMIObject(ports[" + port + "], &bResult);");
println("while (true) {");
println("char* method = rmiObj->getMethodBytes();");
- writeCplusMethodCallbackPermission(intface);
+ //writeCplusMethodCallbackPermission(intface);
println("int objId = IoTRMIObject::getObjectId(method);");
println("if (objId < vecCallbackObj.size()) { // Check if still within range");
println(intface + "_CallbackSkeleton* skel = dynamic_cast<" + intface +
"_CallbackSkeleton*> (vecCallbackObj.at(objId));");
+ writeCplusMethodCallbackPermission(intface);
println("skel->invokeMethod(rmiObj);");
print("}");
println(" else {");
int methodNumId = intDecl.getHelperMethodNumId(method);
println("int methodId = " + methodNumId + ";");
println("string retType = \"void\";");
- println("string paramCls[] = { \"int\", \"String\", \"int\" };");
+ println("string paramCls[] = { \"int*\", \"String\", \"int\" };");
println("int rev = 0;");
- println("void* paramObj[] = { &ports[0], &callbackAddress, &rev };");
+ println("void* paramObj[] = { &ports, &callbackAddress, &rev };");
println("void* retObj = NULL;");
println("rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);");
println("}\n");
writeConstructorCplusStub(newStubClass, callbackExist, callbackClasses);
writeDeconstructorCplusStub(newStubClass, callbackExist, callbackClasses);
// Write methods
- writeMethodCplusStub(methods, intDecl, callbackClasses);
+ writeMethodCplusStub(methods, intDecl, callbackClasses, newStubClass);
print("}"); println(";");
if (callbackExist) {
Iterator it = callbackClasses.iterator();
println("IoTRMICall *rmiCall;");
// Get the object Id
println("int objectId;");
+ println("vector<int> ports;\n");
+ println("string callbackAddress;");
if (callbackExist) {
// We assume that each class only has one callback interface for now
Iterator it = callbackClasses.iterator();
println("vector<" + callbackType + "*> vecCallbackObj;");
println("static int objIdCnt;");
// TODO: Need to initialize address and ports if we want to have callback-in-callback
- println("string address;");
- println("vector<int> ports;\n");
writePropertiesCplusPermission(callbackType);
}
println("\n");
*/
private void writeConstructorCplusCallbackStub(String newStubClass, boolean callbackExist, Set<String> callbackClasses) {
- println(newStubClass + "(IoTRMICall* _rmiCall, int _objectId) {");
+ println(newStubClass + "(IoTRMICall* _rmiCall, string _callbackAddress, int _objectId, vector<int> _ports) {");
println("objectId = _objectId;");
+ println("callbackAddress = _callbackAddress;");
println("rmiCall = _rmiCall;");
+ println("ports = _ports;");
if (callbackExist) {
Iterator it = callbackClasses.iterator();
String callbackType = (String) it.next();
+ DeclarationHandler decHandler = mapIntDeclHand.get(callbackType);
+ InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType);
+ writeCplusInitCallbackPermission(callbackType, intDecl, callbackExist);
println("thread th1 (&" + newStubClass + "::___initCallBack, this);");
println("th1.detach();");
println("___regCB();");
writeConstructorCplusCallbackStub(newStubClass, callbackExist, callbackClasses);
writeDeconstructorCplusStub(newStubClass, callbackExist, callbackClasses);
// Write methods
- writeMethodCplusStub(methods, intDecl, callbackClasses);
+ writeMethodCplusStub(methods, intDecl, callbackClasses, newStubClass);
println("};");
if (callbackExist) {
Iterator it = callbackClasses.iterator();
private void writePropertiesCplusSkeleton(String intface, boolean callbackExist, Set<String> callbackClasses) {
println(intface + " *mainObj;");
+ println("vector<int> ports;");
+ println("string callbackAddress;");
// Callback
if (callbackExist) {
Iterator it = callbackClasses.iterator();
*/
private void writeConstructorCplusSkeleton(String newSkelClass, String intface, boolean callbackExist, InterfaceDecl intDecl, Collection<String> methods) {
- println(newSkelClass + "(" + intface + " *_mainObj, int _port) {");
+ println(newSkelClass + "(" + intface + " *_mainObj, string _callbackAddress, int _port) {");
println("bool _bResult = false;");
println("mainObj = _mainObj;");
+ println("callbackAddress = _callbackAddress;");
println("rmiObj = new IoTRMIObject(_port, &_bResult);");
writeCplusInitCallbackPermission(intface, intDecl, callbackExist);
writeStructPermissionCplusSkeleton(methods, intDecl, intface);
/**
* HELPER: writeInitCallbackCplusSkeleton() writes the init callback method for skeleton class
*/
- private void writeInitCallbackCplusSkeleton(boolean callbackSkeleton) {
+ private void writeInitCallbackCplusSkeleton(boolean callbackSkeleton, String intface) {
// This is a callback skeleton generation
if (callbackSkeleton)
else
println("void ___regCB() {");
println("int numParam = 3;");
- println("int param1 = 0;");
+ println("vector<int> param1;");
println("string param2 = \"\";");
println("int param3 = 0;");
- println("string paramCls[] = { \"int\", \"String\", \"int\" };");
+ println("string paramCls[] = { \"int*\", \"String\", \"int\" };");
println("void* paramObj[] = { ¶m1, ¶m2, ¶m3 };");
println("rmiObj->getMethodParams(paramCls, numParam, paramObj);");
println("bool bResult = false;");
- println("rmiCall = new IoTRMICall(param1, param2.c_str(), param3, &bResult);");
+ String stubInt = null;
+ if (callbackSkeleton)
+ stubInt = getStubInterface(intface) + "_CallbackStub";
+ else
+ stubInt = getStubInterface(intface) + "_Stub";
+ int port = getPortCount(stubInt);
+ println("rmiCall = new IoTRMICall(param1[" + port + "], param2.c_str(), param3, &bResult);");
println("}\n");
}
* HELPER: writeMethodCplusSkeleton() writes the method of the skeleton class
*/
private void writeMethodCplusSkeleton(Collection<String> methods, InterfaceDecl intDecl,
- Set<String> callbackClasses, boolean callbackSkeleton) {
+ Set<String> callbackClasses, boolean callbackSkeleton, String intface) {
boolean isDefined = false;
for (String method : methods) {
writeStdMethodBodyCplusSkeleton(methParams, methodId, intDecl.getMethodType(method));
println("}\n");
if (isCallbackMethod && !isDefined) {
- writeInitCallbackCplusSkeleton(callbackSkeleton);
+ writeInitCallbackCplusSkeleton(callbackSkeleton, intface);
isDefined = true;
}
}
if (isArrayOrList(paramType, param)) {
println("vector<" + exchParamType + "*> stub" + i + ";");
println("for (int objId = 0; objId < numStubs" + i + "; objId++) {");
- println(exchParamType + "* cb" + i + " = new " + exchParamType + "_CallbackStub(rmiCall, objIdCnt);");
+ println(exchParamType + "* cb" + i + " = new " + exchParamType + "_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);");
println("stub" + i + ".push_back(cb" + i + ");");
println("vecCallbackObj.push_back(cb" + i + ");");
println("objIdCnt++;");
println("}");
} else {
- println(exchParamType + "* stub" + i + " = new " + exchParamType + "_CallbackStub(rmiCall, objIdCnt);");
+ println(exchParamType + "* stub" + i + " = new " + exchParamType + "_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);");
println("vecCallbackObj.push_back(stub" + i + ");");
println("objIdCnt++;");
}
// Write deconstructor
writeDeconstructorCplusSkeleton(newSkelClass, callbackExist, callbackClasses);
// Write methods
- writeMethodCplusSkeleton(methods, intDecl, callbackClasses, false);
+ writeMethodCplusSkeleton(methods, intDecl, callbackClasses, false, intface);
// Write method helper
writeMethodHelperCplusSkeleton(methods, intDecl, callbackClasses);
// Write waitRequestInvokeMethod() - main loop
println(intface + " *mainObj;");
// Keep track of object Ids of all stubs registered to this interface
println("int objectId;");
+ println("vector<int> ports;\n");
+ println("string callbackAddress;");
// Callback
if (callbackExist) {
Iterator it = callbackClasses.iterator();
*/
private void writeConstructorCplusCallbackSkeleton(String newSkelClass, String intface, boolean callbackExist, InterfaceDecl intDecl, Collection<String> methods) {
- println(newSkelClass + "(" + intface + " *_mainObj, int _objectId) {");
+ println(newSkelClass + "(" + intface + " *_mainObj, string _callbackAddress, int _objectId) {");
println("mainObj = _mainObj;");
+ println("callbackAddress = _callbackAddress;");
println("objectId = _objectId;");
println("}\n");
}
// Write deconstructor
writeDeconstructorCplusCallbackSkeleton(newSkelClass, callbackExist, callbackClasses);
// Write methods
- writeMethodCplusSkeleton(methods, intDecl, callbackClasses, true);
+ writeMethodCplusSkeleton(methods, intDecl, callbackClasses, true, intface);
// Write method helper
writeMethodHelperCplusCallbackSkeleton(methods, intDecl, callbackClasses);
// Write waitRequestInvokeMethod() - main loop
// Basically the compiler needs to parse the policy (and requires) files for callback class first
private int getNewIntfaceObjectId(String newIntface) {
- if (!mapNewIntfaceObjId.containsKey(newIntface)) {
- throw new Error("IoTCompiler: Need to parse policy and requires files for callback class first! " +
- "Please place the two files for callback class in front...\n");
- } else {
+// if (!mapNewIntfaceObjId.containsKey(newIntface)) {
+// throw new Error("IoTCompiler: Need to parse policy and requires files for callback class first! " +
+// "Please place the two files for callback class in front...\n");
+// return -1;
+// } else {
int retObjId = mapNewIntfaceObjId.get(newIntface);
return retObjId;
- }
+// }
}