i++;
}
println(" };");
- println("private List<Integer> set" + newObjectId + "Allowed;");
+ println("private static List<Integer> set" + newObjectId + "Allowed;");
}
}
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
int newObjectId = getNewIntfaceObjectId(newIntface);
- println("set" + newObjectId + "Allowed = Arrays.asList(object" + newObjectId +"Permission);");
+ println("set" + newObjectId + "Allowed = new ArrayList<Integer>(Arrays.asList(object" + newObjectId +"Permission));");
}
}
}
+ /**
+ * 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: writeInitCallbackJavaStub() writes callback initialization in stub
*/
println("thread.start();\n");
// Generate info sending part
String method = "___initCallBack()";
- println("int methodId = " + intDecl.getHelperMethodNumId(method) + ";");
+ 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], address, 0 };");
for (int i = 0; i < methParams.size(); i++) {
String paramType = methPrmTypes.get(i);
String param = methParams.get(i);
- String simpleType = getSimpleType(paramType);
+ String simpleType = getGenericType(paramType);
if (isEnumClass(simpleType)) {
// Check if this is enum type
if (isArray(param)) { // An array
- println("int len" + i + " = " + param + ".length;");
- println("int paramEnum" + i + "[] = new int[len];");
+ println("int len" + i + " = " + getSimpleIdentifier(param) + ".length;");
+ println("int paramEnum" + i + "[] = new int[len" + i + "];");
println("for (int i = 0; i < len" + i + "; i++) {");
- println("paramEnum" + i + "[i] = " + param + "[i].ordinal();");
+ println("paramEnum" + i + "[i] = " + getSimpleIdentifier(param) + "[i].ordinal();");
println("}");
} else if (isList(paramType)) { // A list
- println("int len" + i + " = " + param + ".size();");
- println("int paramEnum" + i + "[] = new int[len];");
+ println("int len" + i + " = " + getSimpleIdentifier(param) + ".size();");
+ println("int paramEnum" + i + "[] = new int[len" + i + "];");
println("for (int i = 0; i < len" + i + "; i++) {");
- println("paramEnum" + i + "[i] = " + param + ".get(i).ordinal();");
+ println("paramEnum" + i + "[i] = " + getSimpleIdentifier(param) + ".get(i).ordinal();");
println("}");
} else { // Just one element
println("int paramEnum" + i + "[] = new int[1];");
private void checkAndWriteEnumRetTypeJavaStub(String retType) {
// Strips off array "[]" for return type
- String pureType = getSimpleArrayType(getSimpleType(retType));
+ String pureType = getSimpleArrayType(getGenericType(retType));
// Take the inner type of generic
if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
- pureType = getTypeOfGeneric(retType)[0];
+ pureType = getGenericType(retType);
if (isEnumClass(pureType)) {
// Check if this is enum type
// Enum decoder
if (isStructClass(getGenericType(getSimpleArrayType(retType)))) {
writeStructReturnJavaStub(getGenericType(getSimpleArrayType(retType)), retType);
} else {
- // Check if the return value NONPRIMITIVES
- if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES) {
- String[] retGenValType = getTypeOfGeneric(retType);
- println("Class<?> retGenValType = " + retGenValType[0] + ".class;");
- println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, retGenValType, paramCls, paramObj);");
- println("return (" + retType + ")retObj;");
- } else if (getParamCategory(retType) == ParamCategory.ENUM) {
// This is an enum type
+ if (getParamCategory(getGenericType(getSimpleArrayType(retType))) == ParamCategory.ENUM) {
println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
checkAndWriteEnumRetTypeJavaStub(retType);
+ } else if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES) {
+ // Check if the return value NONPRIMITIVES
+ String retGenValType = getGenericType(retType);
+ println("Class<?> retGenValType = " + retGenValType + ".class;");
+ println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, retGenValType, paramCls, paramObj);");
+ println("return (" + retType + ")retObj;");
} else {
println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
println("return (" + retType + ")retObj;");
}
+ /**
+ * HELPER: writeStructPermissionJavaSkeleton() writes permission for struct helper
+ */
+ private void writeStructPermissionJavaSkeleton(Collection<String> methods, InterfaceDecl intDecl, String intface) {
+
+ // Use this set to handle two same methodIds
+ for (String method : methods) {
+ List<String> methParams = intDecl.getMethodParams(method);
+ List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+ // Check for params with structs
+ for (int i = 0; i < methParams.size(); i++) {
+ String paramType = methPrmTypes.get(i);
+ String param = methParams.get(i);
+ String simpleType = getSimpleType(paramType);
+ if (isStructClass(simpleType)) {
+ int methodNumId = intDecl.getMethodNumId(method);
+ String helperMethod = methodNumId + "struct" + i;
+ int methodHelperNumId = intDecl.getHelperMethodNumId(helperMethod);
+ // Iterate over interfaces to give permissions to
+ 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(" + methodHelperNumId + ");");
+ }
+ }
+ }
+ }
+ }
+
+
/**
* HELPER: writeConstructorJavaSkeleton() writes the constructor of the skeleton class
*/
- private void writeConstructorJavaSkeleton(String newSkelClass, String intface) {
+ private void writeConstructorJavaSkeleton(String newSkelClass, String intface, InterfaceDecl intDecl, Collection<String> methods, boolean callbackExist) {
println("public " + newSkelClass + "(" + intface + " _mainObj, int _port) throws Exception {");
println("mainObj = _mainObj;");
println("rmiObj = new IoTRMIObject(_port);");
// Generate permission control initialization
writeConstructorJavaPermission(intface);
+ writeJavaInitCallbackPermission(intface, intDecl, callbackExist);
+ writeStructPermissionJavaSkeleton(methods, intDecl, intface);
println("___waitRequestInvokeMethod();");
println("}\n");
}
for (int i = 0; i < methParams.size(); i++) {
String paramType = methPrmTypes.get(i);
String param = methParams.get(i);
- String simpleType = getSimpleType(paramType);
+ String simpleType = getGenericType(paramType);
if (isEnumClass(simpleType)) {
// Check if this is enum type
println("int paramInt" + i + "[] = (int[]) paramObj[" + i + "];");
println(simpleType + "[] enumVals = " + simpleType + ".values();");
if (isArray(param)) { // An array
println("int len" + i + " = paramInt" + i + ".length;");
- println(simpleType + "[] paramEnum = new " + simpleType + "[len];");
+ println(simpleType + "[] paramEnum" + i + " = new " + simpleType + "[len" + i + "];");
println("for (int i = 0; i < len" + i + "; i++) {");
- println("paramEnum[i] = enumVals[paramInt" + i + "[i]];");
+ println("paramEnum" + i + "[i] = enumVals[paramInt" + i + "[i]];");
println("}");
} else if (isList(paramType)) { // A list
println("int len" + i + " = paramInt" + i + ".length;");
- println("List<" + simpleType + "> paramEnum = new ArrayList<" + simpleType + ">();");
+ println("List<" + simpleType + "> paramEnum" + i + " = new ArrayList<" + simpleType + ">();");
println("for (int i = 0; i < len" + i + "; i++) {");
- println("paramEnum.add(enumVals[paramInt" + i + "[i]]);");
+ println("paramEnum" + i + ".add(enumVals[paramInt" + i + "[i]]);");
println("}");
} else { // Just one element
println(simpleType + " paramEnum" + i + " = enumVals[paramInt" + i + "[0]];");
private void checkAndWriteEnumRetTypeJavaSkeleton(String retType, String methodId) {
// Strips off array "[]" for return type
- String pureType = getSimpleArrayType(getSimpleType(retType));
+ String pureType = getSimpleArrayType(getGenericType(retType));
// Take the inner type of generic
if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
- pureType = getTypeOfGeneric(retType)[0];
+ pureType = getGenericType(retType);
if (isEnumClass(pureType)) {
// Check if this is enum type
// Enum decoder
private void checkAndWriteEnumRetConvJavaSkeleton(String retType) {
// Strips off array "[]" for return type
- String pureType = getSimpleArrayType(getSimpleType(retType));
+ String pureType = getSimpleArrayType(getGenericType(retType));
// Take the inner type of generic
if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
- pureType = getTypeOfGeneric(retType)[0];
+ pureType = getGenericType(retType);
if (isEnumClass(pureType)) {
// Check if this is enum type
if (isArray(retType)) { // An array
println("}");
} else if (isList(retType)) { // A list
println("int retLen = retEnum.size();");
- println("List<" + pureType + "> retEnumVal = new ArrayList<" + pureType + ">();");
+ println("int[] retEnumVal = new int[retLen];");
println("for (int i = 0; i < retLen; i++) {");
- println("retEnumVal.add(retEnum[i].ordinal());");
+ println("retEnumVal[i] = retEnum.get(i).ordinal();");
println("}");
} else { // Just one element
println("int[] retEnumVal = new int[1];");
String retType = intDecl.getMethodType(method);
if (retType.equals("void")) {
print(intDecl.getMethodId(method) + "(");
- } else if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) { // Enum type
+ } else if (isEnumClass(getSimpleArrayType(getGenericType(retType)))) { // Enum type
checkAndWriteEnumRetTypeJavaSkeleton(retType, intDecl.getMethodId(method));
- } else if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) { // Struct type
+ } else if (isStructClass(getSimpleArrayType(getGenericType(retType)))) { // Struct type
print(retType + " retStruct = " + intDecl.getMethodId(method) + "(");
} else { // We do have a return value
print("Object retObj = " + intDecl.getMethodId(method) + "(");
if (isCallbackMethod) {
print(mapStubParam.get(i)); // Get the callback parameter
- } else if (isEnumClass(getSimpleType(methPrmTypes.get(i)))) { // Enum class
+ } else if (isEnumClass(getGenericType(methPrmTypes.get(i)))) { // Enum class
print(getEnumParam(methPrmTypes.get(i), methParams.get(i), i));
- } else if (isStructClass(getSimpleType(methPrmTypes.get(i)))) {
+ } else if (isStructClass(getGenericType(methPrmTypes.get(i)))) {
print("paramStruct" + i);
} else {
String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
}
println(");");
if (!retType.equals("void")) {
- if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) { // Enum type
+ if (isEnumClass(getSimpleArrayType(getGenericType(retType)))) { // Enum type
checkAndWriteEnumRetConvJavaSkeleton(retType);
println("rmiObj.sendReturnObj(retObj);");
- } else if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) { // Struct type
- writeStructReturnJavaSkeleton(getSimpleArrayType(getSimpleType(retType)), retType);
+ } else if (isStructClass(getSimpleArrayType(getGenericType(retType)))) { // Struct type
+ writeStructReturnJavaSkeleton(getSimpleArrayType(getGenericType(retType)), retType);
println("rmiObj.sendReturnObj(retCls, retObj);");
} else
println("rmiObj.sendReturnObj(retObj);");
print("new Class<?>[] { ");
for (int i = 0; i < methParams.size(); i++) {
String prmType = methPrmTypes.get(i);
- if (getParamCategory(prmType) == ParamCategory.NONPRIMITIVES)
- print(getTypeOfGeneric(prmType)[0] + ".class");
+ if ((getParamCategory(prmType) == ParamCategory.NONPRIMITIVES) &&
+ !isEnumClass(getGenericType(prmType)))
+ print(getGenericType(prmType) + ".class");
else
print("null");
if (i != methParams.size() - 1)
// Write properties
writePropertiesJavaSkeleton(intface, callbackExist, intDecl);
// Write constructor
- writeConstructorJavaSkeleton(newSkelClass, intface);
+ writeConstructorJavaSkeleton(newSkelClass, intface, intDecl, methods, callbackExist);
// Write methods
writeMethodJavaSkeleton(methods, intDecl, callbackClasses, false);
// Write method helper
/**
* HELPER: writeConstructorJavaCallbackSkeleton() writes the constructor of the skeleton class
*/
- private void writeConstructorJavaCallbackSkeleton(String newSkelClass, String intface) {
+ private void writeConstructorJavaCallbackSkeleton(String newSkelClass, String intface, InterfaceDecl intDecl, Collection<String> methods) {
println("public " + newSkelClass + "(" + intface + " _mainObj, int _objectId) throws Exception {");
println("mainObj = _mainObj;");
// Write properties
writePropertiesJavaCallbackSkeleton(intface, callbackExist);
// Write constructor
- writeConstructorJavaCallbackSkeleton(newSkelClass, intface);
+ writeConstructorJavaCallbackSkeleton(newSkelClass, intface, intDecl, methods);
// Write methods
writeMethodJavaSkeleton(methods, intDecl, callbackClasses, true);
// Write method helper
// Write file headers
println("#ifndef _" + stType.toUpperCase() + "_HPP__");
println("#define _" + stType.toUpperCase() + "_HPP__");
+ println("using namespace std;");
println("struct " + stType + " {");
List<String> structMemberTypes = structDecl.getMemberTypes(stType);
List<String> structMembers = structDecl.getMembers(stType);
List<String> methParams = intDecl.getMethodParams(method);
List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
-
- //System.out.println("\n\nMethod return type: " + checkAndGetCplusType(intDecl.getMethodType(method)) + "\n\n");
-
print(checkAndGetCplusType(intDecl.getMethodType(method)) + " " +
intDecl.getMethodId(method) + "(");
boolean isCallbackMethod = false;
if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
print("\"int\"");
} else { // Generate normal classes if it's not a callback object
- //String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
- //String prmType = getSimpleType(getEnumType(paramTypeC));
String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
- String prmType = getEnumType(paramTypeC);
- print("\"" + prmType + "\"");
+ print("\"" + paramTypeC + "\"");
}
if (i != methParams.size() - 1) // Check if this is the last element
print(", ");
for (int i = 0; i < methParams.size(); i++) {
String paramType = methPrmTypes.get(i);
String param = methParams.get(i);
- String simpleType = getSimpleType(paramType);
- if (isEnumClass(simpleType)) {
+ if (isEnumClass(getGenericType(paramType))) {
// Check if this is enum type
if (isArrayOrList(paramType, param)) { // An array or vector
- println("int len" + i + " = " + param + ".size();");
- println("vector<int> paramEnum" + i + "(len);");
+ println("int len" + i + " = " + getSimpleIdentifier(param) + ".size();");
+ println("vector<int> paramEnum" + i + "(len" + i + ");");
println("for (int i = 0; i < len" + i + "; i++) {");
- println("paramEnum" + i + "[i] = (int) " + param + "[i];");
+ println("paramEnum" + i + "[i] = (int) " + getSimpleIdentifier(param) + "[i];");
println("}");
} else { // Just one element
println("vector<int> paramEnum" + i + "(1);");
private void checkAndWriteEnumRetTypeCplusStub(String retType) {
// Strips off array "[]" for return type
- String pureType = getSimpleArrayType(getSimpleType(retType));
+ String pureType = getSimpleArrayType(getGenericType(retType));
// Take the inner type of generic
if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
- pureType = getTypeOfGeneric(retType)[0];
+ pureType = getGenericType(retType);
if (isEnumClass(pureType)) {
// Check if this is enum type
println("vector<int> retEnumInt;");
}
if (isArrayOrList(param, paramType)) { // An array or list
for (int i = 0; i < members.size(); i++) {
- String prmTypeC = checkAndGetCplusType(memTypes.get(i));
- String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
- println("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+ String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+ println("paramCls[pos] = \"" + prmTypeC + "\";");
print("paramObj[pos++] = &" + param + "[i].");
print(getSimpleIdentifier(members.get(i)));
println(";");
println("}");
} else { // Just one struct element
for (int i = 0; i < members.size(); i++) {
- String prmTypeC = checkAndGetCplusType(memTypes.get(i));
- String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
- println("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+ String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+ println("paramCls[pos] = \"" + prmTypeC + "\";");
print("paramObj[pos++] = &" + param + ".");
print(getSimpleIdentifier(members.get(i)));
println(";");
if (isStructClass(simpleType)) {
writeStructMembersCplusStub(simpleType, paramType, param);
} else {
- String prmTypeC = checkAndGetCplusType(methPrmTypes.get(i));
- String prmType = checkAndGetCplusArrayType(prmTypeC, methParams.get(i));
- println("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+ String prmTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
+ println("paramCls[pos] = \"" + prmTypeC + "\";");
print("paramObj[pos++] = &");
print(getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i));
println(";");
if (isArrayOrList(retType, retType)) { // An array or list
println("for(int i = 0; i < retLen; i++) {");
for (int i = 0; i < members.size(); i++) {
- String prmTypeC = checkAndGetCplusType(memTypes.get(i));
- String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
- println("retCls[retPos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+ String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+ println("retCls[retPos] = \"" + prmTypeC + "\";");
println("retObj[retPos++] = &retParam" + i + "[i];");
}
println("}");
} else { // Just one struct element
for (int i = 0; i < members.size(); i++) {
- String prmTypeC = checkAndGetCplusType(memTypes.get(i));
- String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
- println("retCls[retPos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+ String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+ println("retCls[retPos] = \"" + prmTypeC + "\";");
println("retObj[retPos++] = &retParam" + i + ";");
}
}
checkAndWriteStructSetupCplusStub(methParams, methPrmTypes, intDecl, method);
println("int methodId = " + intDecl.getMethodNumId(method) + ";");
String retType = intDecl.getMethodType(method);
- //String retTypeC = checkAndGetCplusType(retType);
- //println("string retType = \"" + checkAndGetCplusArrayType(getStructType(getEnumType(retTypeC))) + "\";");
println("string retType = \"" + checkAndGetCplusRetClsType(getStructType(getEnumType(retType))) + "\";");
// Generate array of parameter types
if (isStructPresent(methParams, methPrmTypes)) {
println("int numParam = " + methParams.size() + ";");
print("string paramCls[] = { ");
for (int i = 0; i < methParams.size(); i++) {
- //String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
- //String prmType = getSimpleType(getEnumType(paramTypeC));
String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
- String prmType = getEnumType(paramTypeC);
- print("\"" + prmType + "\"");
+ print("\"" + paramTypeC + "\"");
// Check if this is the last element (don't print a comma)
if (i != methParams.size() - 1) {
print(", ");
writeStructReturnCplusStub(getGenericType(getSimpleArrayType(retType)), retType);
} else {
// Check if the return value NONPRIMITIVES
- if (getParamCategory(retType) == ParamCategory.ENUM) {
+ if (isEnumClass(getSimpleArrayType(getGenericType(retType)))) {
checkAndWriteEnumRetTypeCplusStub(retType);
} else {
//if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
String newIntface = intMeth.getKey();
int newObjectId = getNewIntfaceObjectId(newIntface);
println("const static int object" + newObjectId + "Id = " + newObjectId + ";\t//" + newIntface);
- println("const static set<int> set" + newObjectId + "Allowed;");
+ println("static set<int> set" + newObjectId + "Allowed;");
}
}
}
+ /**
+ * HELPER: writeCplusInitCallbackPermission() writes the permission for callback
+ */
+ private void writeCplusInitCallbackPermission(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.insert(" + methodNumId + ");");
+ }
+ }
+ }
+
+
/**
* HELPER: writeInitCallbackSendInfoCplusStub() writes the initialization (send info part) of callback
*/
println("void ___regCB() {");
println("int numParam = 3;");
String method = "___initCallBack()";
- println("int methodId = " + intDecl.getHelperMethodNumId(method) + ";");
+ int methodNumId = intDecl.getHelperMethodNumId(method);
+ println("int methodId = " + methodNumId + ";");
+ //writeCplusCallbackPermission(intface, methodNumId);
println("string retType = \"void\";");
println("string paramCls[] = { \"int\", \"string\", \"int\" };");
println("int rev = 0;");
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
int newObjectId = getNewIntfaceObjectId(newIntface);
- print("const 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) {
}
+ /**
+ * HELPER: writeStructPermissionCplusSkeleton() writes permission for struct helper
+ */
+ private void writeStructPermissionCplusSkeleton(Collection<String> methods, InterfaceDecl intDecl, String intface) {
+
+ // Use this set to handle two same methodIds
+ for (String method : methods) {
+ List<String> methParams = intDecl.getMethodParams(method);
+ List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+ // Check for params with structs
+ for (int i = 0; i < methParams.size(); i++) {
+ String paramType = methPrmTypes.get(i);
+ String param = methParams.get(i);
+ String simpleType = getSimpleType(paramType);
+ if (isStructClass(simpleType)) {
+ int methodNumId = intDecl.getMethodNumId(method);
+ String helperMethod = methodNumId + "struct" + i;
+ int helperMethodNumId = intDecl.getHelperMethodNumId(helperMethod);
+ // Iterate over interfaces to give permissions to
+ 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.insert(" + helperMethodNumId + ");");
+ }
+ }
+ }
+ }
+ }
+
+
/**
* HELPER: writeConstructorCplusSkeleton() writes the constructor of the skeleton class
*/
- private void writeConstructorCplusSkeleton(String newSkelClass, String intface, boolean callbackExist) {
+ private void writeConstructorCplusSkeleton(String newSkelClass, String intface, boolean callbackExist, InterfaceDecl intDecl, Collection<String> methods) {
println(newSkelClass + "(" + intface + " *_mainObj, int _port) {");
println("bool _bResult = false;");
println("mainObj = _mainObj;");
println("rmiObj = new IoTRMIObject(_port, &_bResult);");
+ writeCplusInitCallbackPermission(intface, intDecl, callbackExist);
+ writeStructPermissionCplusSkeleton(methods, intDecl, intface);
println("___waitRequestInvokeMethod();");
println("}\n");
}
for (int i = 0; i < methParams.size(); i++) {
String paramType = methPrmTypes.get(i);
String param = methParams.get(i);
- String simpleType = getSimpleType(paramType);
+ String simpleType = getGenericType(paramType);
if (isEnumClass(simpleType)) {
// Check if this is enum type
if (isArrayOrList(paramType, param)) { // An array
private void checkAndWriteEnumRetTypeCplusSkeleton(String retType) {
// Strips off array "[]" for return type
- String pureType = getSimpleArrayType(getSimpleType(retType));
+ String pureType = getSimpleArrayType(getGenericType(retType));
// Take the inner type of generic
if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
- pureType = getTypeOfGeneric(retType)[0];
+ pureType = getGenericType(retType);
if (isEnumClass(pureType)) {
// Check if this is enum type
// Enum decoder
String paramType = returnGenericCallbackType(methPrmTypes.get(i));
if (callbackClasses.contains(paramType))
print("stub" + i);
- else if (isEnumClass(getSimpleType(paramType))) // Check if this is enum type
+ else if (isEnumClass(getGenericType(paramType))) // Check if this is enum type
print("paramEnum" + i);
- else if (isStructClass(getSimpleType(paramType))) // Struct type
+ else if (isStructClass(getGenericType(paramType))) // Struct type
print("paramStruct" + i);
else
print(getSimpleIdentifier(methParams.get(i)));
if (retType.equals("void")) {
writeMethodInputParameters(methParams, methPrmTypes, callbackClasses, methodId);
} else { // We do have a return value
- if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) // Enum type
+ if (isEnumClass(getSimpleArrayType(getGenericType(retType)))) // Enum type
print(checkAndGetCplusType(retType) + " retEnum = ");
- else if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
+ else if (isStructClass(getSimpleArrayType(getGenericType(retType)))) // Struct type
print(checkAndGetCplusType(retType) + " retStruct = ");
else
print(checkAndGetCplusType(retType) + " retVal = ");
writeMethodInputParameters(methParams, methPrmTypes, callbackClasses, methodId);
checkAndWriteEnumRetTypeCplusSkeleton(retType);
- if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
- writeStructReturnCplusSkeleton(getSimpleArrayType(getSimpleType(retType)), retType);
- if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) // Enum type
+ if (isStructClass(getSimpleArrayType(getGenericType(retType)))) // Struct type
+ writeStructReturnCplusSkeleton(getSimpleArrayType(getGenericType(retType)), retType);
+ if (isEnumClass(getSimpleArrayType(getGenericType(retType)))) // Enum type
println("void* retObj = &retEnumInt;");
else
- if (!isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
+ if (!isStructClass(getSimpleArrayType(getGenericType(retType)))) // Struct type
println("void* retObj = &retVal;");
String retTypeC = checkAndGetCplusType(retType);
- if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
+ if (isStructClass(getSimpleArrayType(getGenericType(retType)))) // Struct type
println("rmiObj->sendReturnObj(retObj, retCls, numRetObj);");
else
println("rmiObj->sendReturnObj(retObj, \"" + checkAndGetCplusRetClsType(getEnumType(retType)) + "\");");
callbackType = paramType;
print("\"int\"");
} else { // Generate normal classes if it's not a callback object
- //String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
- //String prmType = getSimpleType(getEnumType(paramTypeC));
String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
- String prmType = getEnumType(paramTypeC);
- print("\"" + prmType + "\"");
+ print("\"" + paramTypeC + "\"");
}
if (i != methParams.size() - 1) {
print(", ");
for (int i = 0; i < methParams.size(); i++) {
String paramType = returnGenericCallbackType(methPrmTypes.get(i));
if (!callbackClasses.contains(paramType)) {
- String methPrmType = checkAndGetCplusType(methPrmTypes.get(i));
- if (isEnumClass(getSimpleType(methPrmType))) { // Check if this is enum type
+ String methParamType = methPrmTypes.get(i);
+ if (isEnumClass(getSimpleArrayType(getGenericType(methParamType)))) {
+ // Check if this is enum type
println("vector<int> paramEnumInt" + i + ";");
} else {
+ String methPrmType = checkAndGetCplusType(methParamType);
String methParamComplete = checkAndGetCplusArray(methPrmType, methParams.get(i));
println(methParamComplete + ";");
}
String paramType = returnGenericCallbackType(methPrmTypes.get(i));
if (callbackClasses.contains(paramType))
print("&numStubs" + i);
- else if (isEnumClass(getSimpleType(paramType))) // Check if this is enum type
+ else if (isEnumClass(getGenericType(paramType))) // Check if this is enum type
print("¶mEnumInt" + i);
else
print("&" + getSimpleIdentifier(methParams.get(i)));
if (isArrayOrList(param, paramType)) { // An array or list
println("for(int i = 0; i < retLen; i++) {");
for (int i = 0; i < members.size(); i++) {
- String prmTypeC = checkAndGetCplusType(memTypes.get(i));
- String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
- println("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+ String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+ println("paramCls[pos] = \"" + prmTypeC + "\";");
println("paramObj[pos++] = ¶m" + i + "[i];");
}
println("}");
} else { // Just one struct element
for (int i = 0; i < members.size(); i++) {
- String prmTypeC = checkAndGetCplusType(memTypes.get(i));
- String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
- println("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+ String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+ println("paramCls[pos] = \"" + prmTypeC + "\";");
println("paramObj[pos++] = ¶m" + i + ";");
}
}
if (isArrayOrList(retType, retType)) { // An array or list
println("for(int i = 0; i < retLen; i++) {");
for (int i = 0; i < members.size(); i++) {
- String paramTypeC = checkAndGetCplusType(memTypes.get(i));
- String prmType = checkAndGetCplusArrayType(paramTypeC, members.get(i));
- println("retCls[retPos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+ String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+ println("retCls[retPos] = \"" + prmTypeC + "\";");
print("retObj[retPos++] = &retStruct[i].");
print(getEnumParam(memTypes.get(i), getSimpleIdentifier(members.get(i)), i));
println(";");
println("}");
} else { // Just one struct element
for (int i = 0; i < members.size(); i++) {
- String paramTypeC = checkAndGetCplusType(memTypes.get(i));
- String prmType = checkAndGetCplusArrayType(paramTypeC, members.get(i));
- println("retCls[retPos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+ String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+ println("retCls[retPos] = \"" + prmTypeC + "\";");
print("retObj[retPos++] = &retStruct.");
print(getEnumParam(memTypes.get(i), getSimpleIdentifier(members.get(i)), i));
println(";");
println("paramObj[pos++] = &numStubs" + i + ";");
} else { // Generate normal classes if it's not a callback object
String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i));
- String prmTypeC = checkAndGetCplusArrayType(paramTypeC, methParams.get(i));
- if (isEnumClass(getSimpleType(paramTypeC))) { // Check if this is enum type
+ if (isEnumClass(getGenericType(paramTypeC))) { // Check if this is enum type
println("vector<int> paramEnumInt" + i + ";");
} else {
String methParamComplete = checkAndGetCplusArray(paramTypeC, methParams.get(i));
println(methParamComplete + ";");
}
- println("paramCls[pos] = \"" + getEnumType(prmTypeC) + "\";");
- if (isEnumClass(getSimpleType(paramType))) // Check if this is enum type
+ String prmTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
+ println("paramCls[pos] = \"" + prmTypeC + "\";");
+ if (isEnumClass(getGenericType(paramType))) // Check if this is enum type
println("paramObj[pos++] = ¶mEnumInt" + i);
else
println("paramObj[pos++] = &" + getSimpleIdentifier(methParams.get(i)) + ";");
writePropertiesCplusSkeleton(intface, callbackExist, callbackClasses);
println("public:\n");
// Write constructor
- writeConstructorCplusSkeleton(newSkelClass, intface, callbackExist);
+ writeConstructorCplusSkeleton(newSkelClass, intface, callbackExist, intDecl, methods);
// Write deconstructor
writeDeconstructorCplusSkeleton(newSkelClass, callbackExist, callbackClasses);
// Write methods
/**
* HELPER: writeConstructorCplusCallbackSkeleton() writes the constructor of the skeleton class
*/
- private void writeConstructorCplusCallbackSkeleton(String newSkelClass, String intface, boolean callbackExist) {
+ private void writeConstructorCplusCallbackSkeleton(String newSkelClass, String intface, boolean callbackExist, InterfaceDecl intDecl, Collection<String> methods) {
println(newSkelClass + "(" + intface + " *_mainObj, int _objectId) {");
println("mainObj = _mainObj;");
writePropertiesCplusCallbackSkeleton(intface, callbackExist, callbackClasses);
println("public:\n");
// Write constructor
- writeConstructorCplusCallbackSkeleton(newSkelClass, intface, callbackExist);
+ writeConstructorCplusCallbackSkeleton(newSkelClass, intface, callbackExist, intDecl, methods);
// Write deconstructor
writeDeconstructorCplusCallbackSkeleton(newSkelClass, callbackExist, callbackClasses);
// Write methods
/**
* This function converts Java to C++ type for compilation
*/
- private String convertType(String jType) {
+ private String convertType(String type) {
- return mapPrimitives.get(jType);
+ if (mapPrimitives.containsKey(type))
+ return mapPrimitives.get(type);
+ else
+ return type;
}
String pureType = getSimpleArrayType(type);
// Take the inner type of generic
if (getParamCategory(type) == ParamCategory.NONPRIMITIVES)
- pureType = getTypeOfGeneric(type)[0];
+ pureType = getGenericType(type);
if (isEnumClass(pureType)) {
String enumType = "int[]";
return enumType;
return type;
}
+ // Handle and return the correct enum declaration translate into int* for C
+ private String getEnumCplusClsType(String type) {
+
+ // Strips off array "[]" for return type
+ String pureType = getSimpleArrayType(type);
+ // Take the inner type of generic
+ if (getParamCategory(type) == ParamCategory.NONPRIMITIVES)
+ pureType = getGenericType(type);
+ if (isEnumClass(pureType)) {
+ String enumType = "int*";
+ return enumType;
+ } else
+ return type;
+ }
+
// Handle and return the correct struct declaration
private String getStructType(String type) {
String pureType = getSimpleArrayType(type);
// Take the inner type of generic
if (getParamCategory(type) == ParamCategory.NONPRIMITIVES)
- pureType = getTypeOfGeneric(type)[0];
+ pureType = getGenericType(type);
if (isStructClass(pureType)) {
String structType = "int";
return structType;
// - Check and return C++ vector class, e.g. List<Integer> A into vector<int>
private String checkAndGetCplusArgClsType(String paramType, String param) {
- String paramTypeRet = null;
+ String paramTypeRet = getEnumCplusClsType(paramType);
+ if (!paramTypeRet.equals(paramType))
+ // Just return if it is an enum type
+ // Type will still be the same if it's not an enum type
+ return paramTypeRet;
+
// Check for array declaration
if (param.contains("[]")) {
paramTypeRet = getSimpleArrayType(paramType) + "*";