private String returnGenericCallbackType(String paramType) {
if (getParamCategory(paramType) == ParamCategory.NONPRIMITIVES)
- return getTypeOfGeneric(paramType)[0];
+ return getGenericType(paramType);
else
return paramType;
}
if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
String param = methParams.get(i);
if (isArrayOrList(paramType, param)) { // Generate loop
- println("for (" + paramType + " cb : " + getSimpleIdentifier(param) + ") {");
- println(callbackType + "_CallbackSkeleton skel = new " + callbackType + "_CallbackSkeleton(cb, objIdCnt++);");
+ println("for (" + getGenericType(paramType) + " cb : " + getSimpleIdentifier(param) + ") {");
+ println(callbackType + "_CallbackSkeleton skel" + i + " = new " + callbackType + "_CallbackSkeleton(cb, objIdCnt++);");
} else
- println(callbackType + "_CallbackSkeleton skel = new " + callbackType + "_CallbackSkeleton(" +
+ println(callbackType + "_CallbackSkeleton skel" + i + " = new " + callbackType + "_CallbackSkeleton(" +
getSimpleIdentifier(param) + ", objIdCnt++);");
- println("listCallbackObj.add(skel);");
+ println("listCallbackObj.add(skel" + i + ");");
if (isArrayOrList(paramType, param))
println("}");
}
*/
private void writeMethodJavaStub(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
+ boolean isDefined = false;
for (String method : methods) {
List<String> methParams = intDecl.getMethodParams(method);
writeStdMethodBodyJavaStub(intDecl, methParams, methPrmTypes, method);
println("}\n");
// Write the init callback helper method
- if (isCallbackMethod)
+ if (isCallbackMethod && !isDefined) {
writeInitCallbackJavaStub(callbackType, intDecl);
+ isDefined = true;
+ }
}
}
println("public void ___regCB(IoTRMIObject rmiObj) throws IOException {");
else
println("public void ___regCB() throws IOException {");
- println("Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class },");
- println("\tnew Class<?>[] { null, null, null });");
+ 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("}\n");
}
private void writeMethodJavaSkeleton(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses,
boolean callbackSkeleton) {
+ boolean isDefined = false;
for (String method : methods) {
List<String> methParams = intDecl.getMethodParams(method);
// Now, write the body of skeleton!
writeStdMethodBodyJavaSkeleton(methParams, methodId, intDecl.getMethodType(method));
println("}\n");
- if (isCallbackMethod)
+ if (isCallbackMethod && !isDefined) { // Make sure that this function is only defined once!
writeInitCallbackJavaSkeleton(callbackSkeleton);
+ isDefined = true;
+ }
}
}
//if (callbackType.equals(paramType)) {
if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
println("try {");
- String exchParamType = checkAndGetParamClass(paramType);
+ String exchParamType = checkAndGetParamClass(getGenericType(paramType));
// Print array if this is array or list if this is a list of callback objects
if (isArray(param)) {
println("int numStubs" + i + " = (int) paramObj[" + i + "];");
}
// Generate a loop if needed
if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
- String exchParamType = checkAndGetParamClass(paramType);
+ 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);");
for (int i = 0; i < methParams.size(); i++) {
String prmType = methPrmTypes.get(i);
if ((getParamCategory(prmType) == ParamCategory.NONPRIMITIVES) &&
- !isEnumClass(getGenericType(prmType)))
+ !isEnumClass(getGenericType(prmType)) &&
+ !callbackClasses.contains(getGenericType(prmType)))
print(getGenericType(prmType) + ".class");
else
print("null");
*/
private void writeMethodCplusStub(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
+ boolean isDefined = false;
for (String method : methods) {
List<String> methParams = intDecl.getMethodParams(method);
String callbackType = null;
for (int i = 0; i < methParams.size(); i++) {
- String paramType = methPrmTypes.get(i);
+ String paramType = returnGenericCallbackType(methPrmTypes.get(i));
// Check if this has callback object
if (callbackClasses.contains(paramType)) {
isCallbackMethod = true;
if (isCallbackMethod)
writeCallbackMethodBodyCplusStub(intDecl, methParams, methPrmTypes, method, callbackType);
else
- writeStdMethodBodyCplusStub(intDecl, methParams, methPrmTypes, method);
+ writeStdMethodBodyCplusStub(intDecl, methParams, methPrmTypes, method, callbackClasses);
println("}\n");
// Write the init callback helper method
- if (isCallbackMethod) {
+ if (isCallbackMethod && !isDefined) {
writeInitCallbackCplusStub(callbackType, intDecl);
writeInitCallbackSendInfoCplusStub(intDecl);
+ isDefined = true;
}
}
}
if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
String param = methParams.get(i);
if (isArrayOrList(paramType, param)) { // Generate loop
- println("for (" + paramType + "* cb : " + getSimpleIdentifier(param) + ") {");
+ println("for (" + getGenericType(paramType) + "* cb : " + getSimpleIdentifier(param) + ") {");
println(callbackType + "_CallbackSkeleton* skel = new " + callbackType + "_CallbackSkeleton(cb, objIdCnt++);");
isArrayOrList = true;
callbackParam = getSimpleIdentifier(param);
println(callbackType + "_CallbackSkeleton* skel = new " + callbackType + "_CallbackSkeleton(" +
getSimpleIdentifier(param) + ", objIdCnt++);");
println("vecCallbackObj.push_back(skel);");
- if (isArrayOrList(paramType, param))
+ if (isArrayOrList)
println("}");
}
}
* HELPER: writeStdMethodBodyCplusStub() writes the standard method body in the stub class
*/
private void writeStdMethodBodyCplusStub(InterfaceDecl intDecl, List<String> methParams,
- List<String> methPrmTypes, String method) {
+ List<String> methPrmTypes, String method, Set<String> callbackClasses) {
checkAndWriteStructSetupCplusStub(methParams, methPrmTypes, intDecl, method);
println("int methodId = " + intDecl.getMethodNumId(method) + ";");
println("int numParam = " + methParams.size() + ";");
print("string paramCls[] = { ");
for (int i = 0; i < methParams.size(); i++) {
- String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
- print("\"" + paramTypeC + "\"");
+ String paramType = returnGenericCallbackType(methPrmTypes.get(i));
+ if (callbackClasses.contains(paramType)) {
+ print("\"int\"");
+ } else {
+ String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
+ print("\"" + paramTypeC + "\"");
+ }
// Check if this is the last element (don't print a comma)
if (i != methParams.size() - 1) {
print(", ");
println("int methodId = " + methodNumId + ";");
//writeCplusCallbackPermission(intface, 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], &address, &rev };");
println("void* retObj = NULL;");
// Write methods
writeMethodCplusStub(methods, intDecl, callbackClasses);
print("}"); println(";");
- if (callbackExist)
- writePermissionInitializationCplus(intface, newStubClass, intDecl);
+ if (callbackExist) {
+ Iterator it = callbackClasses.iterator();
+ String callbackType = (String) it.next();
+ // Generate permission stuff for callback stubs
+ DeclarationHandler decHandlerCallback = mapIntDeclHand.get(callbackType);
+ InterfaceDecl intDeclCallback = (InterfaceDecl) decHandlerCallback.getInterfaceDecl(callbackType);
+ writePermissionInitializationCplus(callbackType, newStubClass, intDeclCallback);
+ }
writeObjectIdCountInitializationCplus(newStubClass, callbackExist);
println("#endif");
pw.close();
// Write methods
writeMethodCplusStub(methods, intDecl, callbackClasses);
println("};");
- if (callbackExist)
- writePermissionInitializationCplus(intface, newStubClass, intDecl);
+ if (callbackExist) {
+ Iterator it = callbackClasses.iterator();
+ String callbackType = (String) it.next();
+ // Generate permission stuff for callback stubs
+ DeclarationHandler decHandlerCallback = mapIntDeclHand.get(callbackType);
+ InterfaceDecl intDeclCallback = (InterfaceDecl) decHandlerCallback.getInterfaceDecl(callbackType);
+ writePermissionInitializationCplus(callbackType, newStubClass, intDeclCallback);
+ }
writeObjectIdCountInitializationCplus(newStubClass, callbackExist);
println("#endif");
pw.close();
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
int newObjectId = getNewIntfaceObjectId(newIntface);
- print("set<int> " + newSkelClass + "::set" + newObjectId + "Allowed {");
+ print("set<int> " + newSkelClass + "::set" + newObjectId + "Allowed { ");
Set<String> methodIds = intMeth.getValue();
int i = 0;
for (String methodId : methodIds) {
println("int param1 = 0;");
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;");
private void writeMethodCplusSkeleton(Collection<String> methods, InterfaceDecl intDecl,
Set<String> callbackClasses, boolean callbackSkeleton) {
+ boolean isDefined = false;
for (String method : methods) {
List<String> methParams = intDecl.getMethodParams(method);
// Now, write the body of skeleton!
writeStdMethodBodyCplusSkeleton(methParams, methodId, intDecl.getMethodType(method));
println("}\n");
- if (isCallbackMethod)
+ if (isCallbackMethod && !isDefined) {
writeInitCallbackCplusSkeleton(callbackSkeleton);
+ isDefined = true;
+ }
}
}
String paramType = methPrmTypes.get(i);
String param = methParams.get(i);
//if (callbackType.equals(paramType)) {
- if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
- String exchParamType = checkAndGetParamClass(paramType);
- // Print array if this is array or list if this is a list of callback objects
+ if (checkCallbackType(paramType, callbackType)) // Check if this has callback object
println("int numStubs" + i + " = 0;");
- }
}
}
String param = methParams.get(i);
// Generate a loop if needed
if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
- String exchParamType = checkAndGetParamClass(paramType);
+ String exchParamType = checkAndGetParamClass(getGenericType(paramType));
if (isArrayOrList(paramType, param)) {
- println("vector<" + exchParamType + "> stub;");
+ println("vector<" + exchParamType + "*> stub" + i + ";");
println("for (int objId = 0; objId < numStubs" + i + "; objId++) {");
println(exchParamType + "* cb" + i + " = new " + exchParamType + "_CallbackStub(rmiCall, objIdCnt);");
- println("stub" + i + ".push_back(cb);");
- println("vecCallbackObj.push_back(cb);");
+ println("stub" + i + ".push_back(cb" + i + ");");
+ println("vecCallbackObj.push_back(cb" + i + ");");
println("objIdCnt++;");
println("}");
} else {
if (paramType.contains("<") && paramType.contains(">")) {
String genericClass = getSimpleType(paramType);
- String[] genericType = getTypeOfGeneric(paramType);
+ String genericType = getGenericType(paramType);
String cplusTemplate = null;
- if (genericType.length == 1) // Generic/template with one type
- cplusTemplate = getNonPrimitiveCplusClass(genericClass) +
- "<" + convertType(genericType[0]) + ">";
- else // Generic/template with two types
- cplusTemplate = getNonPrimitiveCplusClass(genericClass) +
- "<" + convertType(genericType[0]) + "," + convertType(genericType[1]) + ">";
+ cplusTemplate = getNonPrimitiveCplusClass(genericClass);
+ if(getParamCategory(getGenericType(paramType)) == ParamCategory.USERDEFINED) {
+ cplusTemplate = cplusTemplate + "<" + genericType + "*>";
+ } else {
+ cplusTemplate = cplusTemplate + "<" + convertType(genericType) + ">";
+ }
return cplusTemplate;
} else
return getNonPrimitiveCplusClass(paramType);
} else
// Just return it as is if it's not non-primitives
return paramType;
- //return checkAndGetParamClass(paramType, true);
}
// Check if this is generics
if(getParamCategory(paramType) == ParamCategory.USERDEFINED) {
return exchangeParamType(paramType);
+ } else if (isList(paramType) &&
+ (getParamCategory(getGenericType(paramType)) == ParamCategory.USERDEFINED)) {
+ return "List<" + exchangeParamType(getGenericType(paramType)) + ">";
} else
return paramType;
}