}
+ /**
+ * HELPER: writeMethodHelperStructSetupJavaCallbackSkeleton() writes the method helper of the struct in skeleton class
+ */
+ private void writeMethodHelperStructSetupJavaCallbackSkeleton(Collection<String> methods,
+ InterfaceDecl intDecl) {
+
+ // 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);
+ print("public int ___");
+ String helperMethod = methodNumId + "struct" + i;
+ println(helperMethod + "(IoTRMIObject rmiObj) {");
+ // Now, write the helper body of skeleton!
+ println("Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null });");
+ println("return (int) paramObj[0];");
+ println("}\n");
+ }
+ }
+ }
+ }
+
+
/**
* HELPER: writeCountVarStructJavaSkeleton() writes counter variable of struct for skeleton
*/
/**
* HELPER: writeInputCountVarStructJavaSkeleton() writes counter variable of struct for skeleton
*/
- private void writeInputCountVarStructJavaSkeleton(String method, InterfaceDecl intDecl) {
+ private boolean writeInputCountVarStructJavaSkeleton(String method, InterfaceDecl intDecl) {
List<String> methParams = intDecl.getMethodParams(method);
List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+ boolean structExist = false;
// Check for params with structs
for (int i = 0; i < methParams.size(); i++) {
String paramType = methPrmTypes.get(i);
String simpleType = getSimpleType(paramType);
boolean begin = true;
if (isStructClass(simpleType)) {
+ structExist = true;
if (!begin) {
print(", "); begin = false;
}
print("struct" + methodNumId + "Size" + i);
}
}
+ return structExist;
}
}
+ /**
+ * HELPER: writeMethodCallStructJavaCallbackSkeleton() writes method call for wait invoke in skeleton
+ */
+ private void writeMethodCallStructJavaCallbackSkeleton(Collection<String> methods, InterfaceDecl intDecl) {
+
+ // 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);
+ print("case ");
+ String helperMethod = methodNumId + "struct" + i;
+ String tempVar = "struct" + methodNumId + "Size" + i;
+ print(intDecl.getHelperMethodNumId(helperMethod) + ": ");
+ print(tempVar + " = ___");
+ println(helperMethod + "(rmiObj); break;");
+ }
+ }
+ }
+ }
+
+
/**
* HELPER: writeJavaMethodPermission() writes permission checks in skeleton
*/
List<String> methParams = intDecl.getMethodParams(method);
List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
- String methodId = intDecl.getMethodId(method);
- print("public void ___");
- String helperMethod = methodId;
- if (uniqueMethodIds.contains(methodId))
- helperMethod = helperMethod + intDecl.getMethodNumId(method);
- else
- uniqueMethodIds.add(methodId);
- // Check if this is "void"
- String retType = intDecl.getMethodType(method);
- if (retType.equals("void"))
- println(helperMethod + "(IoTRMIObject rmiObj) {");
- else
- println(helperMethod + "(IoTRMIObject rmiObj) throws IOException {");
- // Now, write the helper body of skeleton!
- writeStdMethodHelperBodyJavaSkeleton(intDecl, methParams, methPrmTypes, method, callbackClasses);
- println("}\n");
+ if (isStructPresent(methParams, methPrmTypes)) { // Treat struct differently
+ String methodId = intDecl.getMethodId(method);
+ print("public void ___");
+ String helperMethod = methodId;
+ if (uniqueMethodIds.contains(methodId))
+ helperMethod = helperMethod + intDecl.getMethodNumId(method);
+ else
+ uniqueMethodIds.add(methodId);
+ String retType = intDecl.getMethodType(method);
+ print(helperMethod + "(");
+ boolean begin = true;
+ for (int i = 0; i < methParams.size(); i++) { // Print size variables
+ String paramType = methPrmTypes.get(i);
+ String param = methParams.get(i);
+ String simpleType = getSimpleType(paramType);
+ if (isStructClass(simpleType)) {
+ if (!begin) { // Generate comma for not the beginning variable
+ print(", "); begin = false;
+ }
+ int methodNumId = intDecl.getMethodNumId(method);
+ print("int struct" + methodNumId + "Size" + i);
+ }
+ // TODO: Need to create comma separation
+ }
+ // Check if this is "void"
+ if (retType.equals("void"))
+ println(", IoTRMIObject rmiObj) {");
+ else
+ println(", IoTRMIObject rmiObj) throws IOException {");
+ writeMethodHelperStructJavaSkeleton(intDecl, methParams, methPrmTypes, method, callbackClasses);
+ println("}\n");
+ } else {
+ String methodId = intDecl.getMethodId(method);
+ print("public void ___");
+ String helperMethod = methodId;
+ if (uniqueMethodIds.contains(methodId))
+ helperMethod = helperMethod + intDecl.getMethodNumId(method);
+ else
+ uniqueMethodIds.add(methodId);
+ // Check if this is "void"
+ String retType = intDecl.getMethodType(method);
+ if (retType.equals("void"))
+ println(helperMethod + "(IoTRMIObject rmiObj) {");
+ else
+ println(helperMethod + "(IoTRMIObject rmiObj) throws IOException {");
+ // Now, write the helper body of skeleton!
+ writeStdMethodHelperBodyJavaSkeleton(intDecl, methParams, methPrmTypes, method, callbackClasses);
+ println("}\n");
+ }
}
+ // Write method helper for structs
+ writeMethodHelperStructSetupJavaCallbackSkeleton(methods, intDecl);
}
Set<String> uniqueMethodIds = new HashSet<String>();
println("public void invokeMethod(IoTRMIObject rmiObj) throws IOException {");
// Write variables here if we have callbacks or enums or structs
+ writeCountVarStructJavaSkeleton(methods, intDecl);
+ // Write variables here if we have callbacks or enums or structs
println("int methodId = rmiObj.getMethodId();");
// TODO: code the permission check here!
println("switch (methodId) {");
helperMethod = helperMethod + methodNumId;
else
uniqueMethodIds.add(methodId);
- println(helperMethod + "(rmiObj); break;");
+ print(helperMethod + "(");
+ if (writeInputCountVarStructJavaSkeleton(method, intDecl))
+ println(", rmiObj); break;");
+ else
+ println("rmiObj); break;");
}
String method = "___initCallBack()";
// Print case -9999 (callback handler) if callback exists
int methodId = intDecl.getHelperMethodNumId(method);
println("case " + methodId + ": ___regCB(rmiObj); break;");
}
+ writeMethodCallStructJavaCallbackSkeleton(methods, intDecl);
println("default: ");
println("throw new Error(\"Method Id \" + methodId + \" not recognized!\");");
println("}");