private void writeConstructorJavaStub(String intface, String newStubClass, Set<String> methods, InterfaceDecl intDecl) {
println("public " + newStubClass + "(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {");
+ println("if (_localPortSend != 0 && _localPortRecv != 0) {");
println("rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);");
+ println("} else");
+ println("{");
+ println("rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);");
+ println("}");
// Register the AtomicBoolean variables
for (String method : methods) {
// Generate AtomicBooleans for methods that have return values
if (isStructClass(simpleType)) {
writeStructMembersJavaStub(simpleType, paramType, param);
} else if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
- println("paramCls[pos] = int.class;");
- print("paramObj[pos++] = ");
- if (isArray(methParams.get(i)))
- print(getSimpleIdentifier(methParams.get(i)) + ".length");
- else if (isList(methPrmTypes.get(i)))
- print(getSimpleIdentifier(methParams.get(i)) + ".size()");
- else
- print("new Integer(1)");
- println(";");
+ println("paramCls[pos] = int[].class;");
+ println("paramObj[pos++] = objIdSent" + i + ";");
} else {
String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
println("paramCls[pos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
for (int i = 0; i < methParams.size(); i++) {
String paramType = methPrmTypes.get(i);
if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
- print("objIdSent");
+ print("objIdSent" + i);
} else
print(getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i));
// Check if this is the last element (don't print a comma)
println("if (!IoTRMIUtil.mapSkel.containsKey(" + paramIdent + ")) {");
println("int newObjIdSent = rmiComm.getObjectIdCounter();");
if (isMultipleCallbacks)
- println("objIdSent[i++] = newObjIdSent;");
+ println("objIdSent" + counter + "[cnt" + counter + "++] = newObjIdSent;");
else
- println("objIdSent[0] = newObjIdSent;");
+ println("objIdSent" + counter + "[0] = newObjIdSent;");
println("rmiComm.decrementObjectIdCounter();");
println(callbackType + "_Skeleton skel" + counter + " = new " + callbackType + "_Skeleton(" + paramIdent + ", rmiComm, newObjIdSent);");
- println("IoTRMIUtil.mapSkel.put(" + paramIdent + ", skel0);");
+ println("IoTRMIUtil.mapSkel.put(" + paramIdent + ", skel" + counter + ");");
println("IoTRMIUtil.mapSkelId.put(" + paramIdent + ", newObjIdSent);");
println("Thread thread = new Thread() {");
println("public void run() {");
println("try {");
- println("skel0.___waitRequestInvokeMethod();");
+ println("skel" + counter + ".___waitRequestInvokeMethod();");
println("} catch (Exception ex) {");
println("ex.printStackTrace();");
println("throw new Error(\"Exception when trying to run ___waitRequestInvokeMethod() for " +
println("{");
println("int newObjIdSent = IoTRMIUtil.mapSkelId.get(" + paramIdent + ");");
if (isMultipleCallbacks)
- println("objIdSent[i++] = newObjIdSent;");
+ println("objIdSent" + counter + "[cnt" + counter + "++] = newObjIdSent;");
else
- println("objIdSent[0] = newObjIdSent;");
+ println("objIdSent" + counter + "[0] = newObjIdSent;");
println("}");
}
List<String> methPrmTypes, String method, String callbackType) {
// Determine callback object counter type (List vs. single variable)
- print("int[] objIdSent = ");
for (int i = 0; i < methParams.size(); i++) {
String paramType = methPrmTypes.get(i);
if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
+ print("int[] objIdSent" + i + " = ");
String param = methParams.get(i);
if (isArray(methParams.get(i)))
println("new int[" + getSimpleIdentifier(methParams.get(i)) + ".length];");
if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
String param = methParams.get(i);
if (isArrayOrList(paramType, param)) { // Generate loop
- println("int i = 0;");
+ println("int cnt" + i + " = 0;");
println("for (" + getGenericType(paramType) + " cb : " + getSimpleIdentifier(param) + ") {");
writeCallbackInstantiationMethodBodyJavaStub("cb", callbackType, i, true);
} else
println("auto it = IoTRMIUtil::mapSkel->find(" + paramIdent + ");");
println("if (it == IoTRMIUtil::mapSkel->end()) {");
println("int newObjIdSent = rmiComm->getObjectIdCounter();");
- println("objIdSent.push_back(newObjIdSent);");
+ println("objIdSent" + counter + ".push_back(newObjIdSent);");
println("rmiComm->decrementObjectIdCounter();");
println(callbackType + "_Skeleton* skel" + counter + " = new " + callbackType + "_Skeleton(" + paramIdent + ", rmiComm, newObjIdSent);");
- println("vecCallbackObj.push_back(skel0);");
- println("IoTRMIUtil::mapSkel->insert(make_pair(" + paramIdent + ", skel0));");
+ println("vecCallbackObj.push_back(skel" + counter + ");");
+ println("IoTRMIUtil::mapSkel->insert(make_pair(" + paramIdent + ", skel" + counter + "));");
println("IoTRMIUtil::mapSkelId->insert(make_pair(" + paramIdent + ", newObjIdSent));");
- println("thread th0 (&" + callbackType + "_Skeleton::___waitRequestInvokeMethod, std::ref(skel0), std::ref(skel0));");
- println("th0.detach();");
+ println("thread th" + counter + " (&" + callbackType + "_Skeleton::___waitRequestInvokeMethod, std::ref(skel" + counter +
+ "), std::ref(skel" + counter +"));");
+ println("th" + counter + ".detach();");
println("while(!skel" + counter + "->didInitWaitInvoke());");
println("}");
println("else");
println("{");
println("auto itId = IoTRMIUtil::mapSkelId->find(" + paramIdent + ");");
- println("objIdSent.push_back(itId->second);");
+ println("objIdSent" + counter + ".push_back(itId->second);");
println("}");
}
// Check if this is single object, array, or list of objects
boolean isArrayOrList = false;
String callbackParam = null;
- println("vector<int> objIdSent;");
for (int i = 0; i < methParams.size(); i++) {
-
String paramType = methPrmTypes.get(i);
if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
+ println("vector<int> objIdSent" + i + ";");
String param = methParams.get(i);
if (isArrayOrList(paramType, param)) { // Generate loop
println("for (" + getGenericType(paramType) + "* cb : " + getSimpleIdentifier(param) + ") {");
}
if (isArrayOrList)
println("}");
- println("vector<int> ___paramCB" + i + " = objIdSent;");
+ println("vector<int> ___paramCB" + i + " = objIdSent" + i + ";");
}
}
}
println("}");
if (callbackExist) {
// We assume that each class only has one callback interface for now
- Iterator it = callbackClasses.iterator();
- String callbackType = (String) it.next();
- println("for(" + callbackType + "* cb : vecCallbackObj) {");
- println("delete cb;");
- println("cb = NULL;");
- println("}");
+ //Iterator it = callbackClasses.iterator();
+ //String callbackType = (String) it.next();
+ for (String callbackType : callbackClasses) {
+ println("for(" + callbackType + "* cb : vecCallbackObj) {");
+ println("delete cb;");
+ println("cb = NULL;");
+ println("}");
+ }
}
println("}");
println("");
println("}");
if (callbackExist) {
// We assume that each class only has one callback interface for now
- Iterator it = callbackClasses.iterator();
- String callbackType = (String) it.next();
- String exchangeType = checkAndGetParamClass(callbackType);
- println("for(" + exchangeType + "* cb : vecCallbackObj) {");
- println("delete cb;");
- println("cb = NULL;");
- println("}");
+ //Iterator it = callbackClasses.iterator();
+ //String callbackType = (String) it.next();
+ for (String callbackType : callbackClasses) {
+ String exchangeType = checkAndGetParamClass(callbackType);
+ println("for(" + exchangeType + "* cb : vecCallbackObj) {");
+ println("delete cb;");
+ println("cb = NULL;");
+ println("}");
+ }
}
println("}");
println("");