X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=blobdiff_plain;f=iotjava%2Fiotpolicy%2FIoTCompiler.java;h=a5a6781293882ba2fdf854085b8f8b6b87abd466;hp=04bf089ff98dd06529ff480ecd66dd5ca1734b53;hb=7a27eab091d560ca1222d3a2652da56c97456980;hpb=38523cbbcc710ff7413e8b5d85df402aa109bd13 diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index 04bf089..a5a6781 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -414,7 +414,7 @@ public class IoTCompiler { private void writePropertiesJavaStub(String intface, String newIntface, boolean callbackExist, Set callbackClasses) { println("private IoTRMICall rmiCall;"); - println("private String address;"); + println("private String callbackAddress;"); println("private int[] ports;\n"); // Get the object Id Integer objId = mapIntfaceObjId.get(intface); @@ -457,10 +457,10 @@ public class IoTCompiler { */ private void writeConstructorJavaStub(String intface, String newStubClass, boolean callbackExist, Set callbackClasses) { - println("public " + newStubClass + "(int _port, String _address, int _rev, int[] _ports) throws Exception {"); - println("address = _address;"); + println("public " + newStubClass + "(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {"); + println("callbackAddress = _callbackAddress;"); println("ports = _ports;"); - println("rmiCall = new IoTRMICall(_port, _address, _rev);"); + println("rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);"); if (callbackExist) { Iterator it = callbackClasses.iterator(); String callbackType = (String) it.next(); @@ -545,7 +545,7 @@ public class IoTCompiler { 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 };"); + println("Object[] paramObj = new Object[] { ports[0], callbackAddress, 0 };"); println("rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);"); println("}\n"); } @@ -742,7 +742,7 @@ public class IoTCompiler { /** * HELPER: writeStructParamClassJavaStub() writes parameters if struct is present */ - private void writeStructParamClassJavaStub(List methParams, List methPrmTypes) { + private void writeStructParamClassJavaStub(List methParams, List methPrmTypes, String callbackType) { print("int paramLen = "); writeLengthStructParamClassJavaStub(methParams, methPrmTypes); @@ -757,6 +757,16 @@ public class IoTCompiler { String simpleType = getGenericType(paramType); 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(";"); } else { String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i)); println("paramCls[pos] = " + getSimpleType(getEnumType(prmType)) + ".class;"); @@ -859,7 +869,7 @@ public class IoTCompiler { * HELPER: writeStdMethodBodyJavaStub() writes the standard method body in the stub class */ private void writeStdMethodBodyJavaStub(InterfaceDecl intDecl, List methParams, - List methPrmTypes, String method) { + List methPrmTypes, String method, String callbackType) { checkAndWriteStructSetupJavaStub(methParams, methPrmTypes, intDecl, method); println("int methodId = " + intDecl.getMethodNumId(method) + ";"); @@ -868,12 +878,17 @@ public class IoTCompiler { checkAndWriteEnumTypeJavaStub(methParams, methPrmTypes); // Generate array of parameter types if (isStructPresent(methParams, methPrmTypes)) { - writeStructParamClassJavaStub(methParams, methPrmTypes); + writeStructParamClassJavaStub(methParams, methPrmTypes, callbackType); } else { print("Class[] paramCls = new Class[] { "); for (int i = 0; i < methParams.size(); i++) { - String paramType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i)); - print(getSimpleType(getEnumType(paramType)) + ".class"); + String prmType = methPrmTypes.get(i); + if (checkCallbackType(prmType, callbackType)) { // Check if this has callback object + print("int.class"); + } else { // Generate normal classes if it's not a callback object + String paramType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i)); + print(getSimpleType(getEnumType(paramType)) + ".class"); + } // Check if this is the last element (don't print a comma) if (i != methParams.size() - 1) { print(", "); @@ -883,7 +898,17 @@ public class IoTCompiler { // Generate array of parameter objects print("Object[] paramObj = new Object[] { "); for (int i = 0; i < methParams.size(); i++) { - print(getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i)); + String paramType = methPrmTypes.get(i); + if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object + //if (isArray(methPrmTypes.get(i), methParams.get(i))) + 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)"); + } else + print(getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i)); // Check if this is the last element (don't print a comma) if (i != methParams.size() - 1) { print(", "); @@ -936,7 +961,10 @@ public class IoTCompiler { private boolean checkCallbackType(String paramType, String callbackType) { String prmType = returnGenericCallbackType(paramType); - return callbackType.equals(prmType); + if (callbackType == null) // If there is no callbackType it means not a callback method + return false; + else + return callbackType.equals(prmType); } @@ -968,56 +996,6 @@ public class IoTCompiler { println("ex.printStackTrace();"); println("throw new Error(\"Exception when generating skeleton objects!\");"); println("}\n"); - println("int methodId = " + intDecl.getMethodNumId(method) + ";"); - String retType = intDecl.getMethodType(method); - println("Class retType = " + getSimpleType(getEnumType(retType)) + ".class;"); - // Generate array of parameter types - print("Class[] paramCls = new 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("int.class"); - } else { // Generate normal classes if it's not a callback object - String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i)); - print(getSimpleType(prmType) + ".class"); - } - if (i != methParams.size() - 1) // Check if this is the last element - print(", "); - } - println(" };"); - // Generate array of parameter objects - print("Object[] paramObj = new Object[] { "); - for (int i = 0; i < methParams.size(); i++) { - String paramType = methPrmTypes.get(i); - if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object - //if (isArray(methPrmTypes.get(i), methParams.get(i))) - 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)"); - } else - print(getSimpleIdentifier(methParams.get(i))); - if (i != methParams.size() - 1) - print(", "); - } - println(" };"); - // Check if this is "void" - if (retType.equals("void")) { - println("rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);"); - } else { // We do have a return value - // 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 { - println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);"); - println("return (" + retType + ")retObj;"); - } - } } @@ -1054,8 +1032,8 @@ public class IoTCompiler { // Now, write the body of stub! if (isCallbackMethod) writeCallbackMethodBodyJavaStub(intDecl, methParams, methPrmTypes, method, callbackType); - else - writeStdMethodBodyJavaStub(intDecl, methParams, methPrmTypes, method); + //else + writeStdMethodBodyJavaStub(intDecl, methParams, methPrmTypes, method, callbackType); println("}\n"); // Write the init callback helper method if (isCallbackMethod && !isDefined) { @@ -1356,23 +1334,24 @@ public class IoTCompiler { * HELPER: writeCallbackJavaStubGeneration() writes the callback stub generation part */ private Map writeCallbackJavaStubGeneration(List methParams, List methPrmTypes, - String callbackType) { + String callbackType, boolean isStructMethod) { Map mapStubParam = new HashMap(); + String offsetPfx = ""; + if (isStructMethod) + offsetPfx = "offset"; // Iterate over callback objects for (int i = 0; i < methParams.size(); i++) { String paramType = methPrmTypes.get(i); String param = methParams.get(i); - //if (callbackType.equals(paramType)) { if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object - println("try {"); 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 + "];"); + println("int numStubs" + i + " = (int) paramObj[" + offsetPfx + i + "];"); println(exchParamType + "[] stub" + i + " = new " + exchParamType + "[numStubs" + i + "];"); } else if (isList(paramType)) { - println("int numStubs" + i + " = (int) paramObj[" + i + "];"); + 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);"); @@ -1403,17 +1382,24 @@ public class IoTCompiler { /** * HELPER: checkAndWriteEnumTypeJavaSkeleton() writes the enum type (convert from enum to int) */ - private void checkAndWriteEnumTypeJavaSkeleton(List methParams, List methPrmTypes) { + private void checkAndWriteEnumTypeJavaSkeleton(List methParams, List methPrmTypes, boolean isStructMethod) { + String offsetPfx = ""; + if (isStructMethod) + offsetPfx = "offset"; // Iterate and find enum declarations + boolean printed = false; for (int i = 0; i < methParams.size(); i++) { String paramType = methPrmTypes.get(i); String param = methParams.get(i); 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();"); + println("int paramInt" + i + "[] = (int[]) paramObj[" + offsetPfx + i + "];"); + if (!printed) { + println(simpleType + "[] enumVals = " + simpleType + ".values();"); + printed = true; + } if (isArray(param)) { // An array println("int len" + i + " = paramInt" + i + ".length;"); println(simpleType + "[] paramEnum" + i + " = new " + simpleType + "[len" + i + "];"); @@ -1526,7 +1512,6 @@ public class IoTCompiler { StructDecl structDecl = getStructDecl(simpleType); List memTypes = structDecl.getMemberTypes(simpleType); List members = structDecl.getMembers(simpleType); - println("int pos = 0;"); if (isArrayOrList(paramType, param)) { // An array or list int methodNumId = intDecl.getMethodNumId(method); String counter = "struct" + methodNumId + "Size" + iVar; @@ -1555,6 +1540,7 @@ public class IoTCompiler { private void writeStructMembersInitJavaSkeleton(InterfaceDecl intDecl, List methParams, List methPrmTypes, String method) { + println("int objPos = 0;"); for (int i = 0; i < methParams.size(); i++) { String paramType = methPrmTypes.get(i); String param = methParams.get(i); @@ -1572,7 +1558,6 @@ public class IoTCompiler { println("List<" + simpleType + "> paramStruct" + i + " = new ArrayList<" + simpleType + ">();"); } else println(simpleType + " paramStruct" + i + " = new " + simpleType + "();"); - println("int objPos = 0;"); // Initialize members StructDecl structDecl = getStructDecl(simpleType); List members = structDecl.getMembers(simpleType); @@ -1605,7 +1590,7 @@ public class IoTCompiler { } } else { // Take offsets of parameters - println("int offset" + i +" = objPos;"); + println("int offset" + i +" = objPos++;"); } } } @@ -1673,10 +1658,12 @@ public class IoTCompiler { List methPrmTypes, String method, boolean isCallbackMethod, String callbackType, boolean isStructMethod) { - checkAndWriteEnumTypeJavaSkeleton(methParams, methPrmTypes); + checkAndWriteEnumTypeJavaSkeleton(methParams, methPrmTypes, isStructMethod); Map mapStubParam = null; - if (isCallbackMethod) - mapStubParam = writeCallbackJavaStubGeneration(methParams, methPrmTypes, callbackType); + if (isCallbackMethod) { + println("try {"); + mapStubParam = writeCallbackJavaStubGeneration(methParams, methPrmTypes, callbackType, isStructMethod); + } // Check if this is "void" String retType = intDecl.getMethodType(method); if (retType.equals("void")) { @@ -1690,14 +1677,15 @@ public class IoTCompiler { } for (int i = 0; i < methParams.size(); i++) { - if (isCallbackMethod) { + String paramType = methPrmTypes.get(i); + if (isCallbackMethod && checkCallbackType(paramType, callbackType)) { print(mapStubParam.get(i)); // Get the callback parameter - } else if (isEnumClass(getGenericType(methPrmTypes.get(i)))) { // Enum class - print(getEnumParam(methPrmTypes.get(i), methParams.get(i), i)); - } else if (isStructClass(getGenericType(methPrmTypes.get(i)))) { + } else if (isEnumClass(getGenericType(paramType))) { // Enum class + print(getEnumParam(paramType, methParams.get(i), i)); + } else if (isStructClass(getGenericType(paramType))) { print("paramStruct" + i); } else { - String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i)); + String prmType = checkAndGetArray(paramType, methParams.get(i)); if (isStructMethod) print("(" + prmType + ") paramObj[offset" + i + "]"); else @@ -1741,6 +1729,7 @@ public class IoTCompiler { println(";"); println("Class[] paramCls = new Class[paramLen];"); println("Class[] paramClsGen = new Class[paramLen];"); + println("int pos = 0;"); // Iterate again over the parameters for (int i = 0; i < methParams.size(); i++) { String paramType = methPrmTypes.get(i); @@ -1845,9 +1834,10 @@ public class IoTCompiler { String param = methParams.get(i); String simpleType = getGenericType(paramType); if (isStructClass(simpleType)) { - if (!begin) { // Generate comma for not the beginning variable - print(", "); begin = false; - } + if (!begin) // Generate comma for not the beginning variable + print(", "); + else + begin = false; int methodNumId = intDecl.getMethodNumId(method); print("int struct" + methodNumId + "Size" + i); } @@ -1977,17 +1967,18 @@ public class IoTCompiler { List methParams = intDecl.getMethodParams(method); List methPrmTypes = intDecl.getMethodParamTypes(method); boolean structExist = false; + boolean begin = true; // 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 = getGenericType(paramType); - boolean begin = true; if (isStructClass(simpleType)) { structExist = true; - if (!begin) { - print(", "); begin = false; - } + if (!begin) + print(", "); + else + begin = false; int methodNumId = intDecl.getMethodNumId(method); print("struct" + methodNumId + "Size" + i); } @@ -2221,9 +2212,10 @@ public class IoTCompiler { String param = methParams.get(i); String simpleType = getGenericType(paramType); if (isStructClass(simpleType)) { - if (!begin) { // Generate comma for not the beginning variable - print(", "); begin = false; - } + if (!begin) // Generate comma for not the beginning variable + print(", "); + else + begin = false; int methodNumId = intDecl.getMethodNumId(method); print("int struct" + methodNumId + "Size" + i); } @@ -2604,8 +2596,7 @@ public class IoTCompiler { println(") { "); if (isCallbackMethod) writeCallbackMethodBodyCplusStub(intDecl, methParams, methPrmTypes, method, callbackType); - else - writeStdMethodBodyCplusStub(intDecl, methParams, methPrmTypes, method, callbackClasses); + writeStdMethodBodyCplusStub(intDecl, methParams, methPrmTypes, method, callbackType, isCallbackMethod); println("}\n"); // Write the init callback helper method if (isCallbackMethod && !isDefined) { @@ -2633,67 +2624,22 @@ public class IoTCompiler { String param = methParams.get(i); if (isArrayOrList(paramType, param)) { // Generate loop println("for (" + getGenericType(paramType) + "* cb : " + getSimpleIdentifier(param) + ") {"); - println(callbackType + "_CallbackSkeleton* skel = new " + callbackType + "_CallbackSkeleton(cb, objIdCnt++);"); + println(callbackType + "_CallbackSkeleton* skel" + i + " = new " + callbackType + "_CallbackSkeleton(cb, objIdCnt++);"); isArrayOrList = true; callbackParam = getSimpleIdentifier(param); } else - println(callbackType + "_CallbackSkeleton* skel = new " + callbackType + "_CallbackSkeleton(" + + println(callbackType + "_CallbackSkeleton* skel" + i + " = new " + callbackType + "_CallbackSkeleton(" + getSimpleIdentifier(param) + ", objIdCnt++);"); - println("vecCallbackObj.push_back(skel);"); + println("vecCallbackObj.push_back(skel" + i + ");"); if (isArrayOrList) println("}"); + print("int ___paramCB" + i + " = "); + if (isArrayOrList) + println(callbackParam + ".size();"); + else + println("1;"); } } - println("int numParam = " + methParams.size() + ";"); - 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 - print("string paramCls[] = { "); - 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\""); - } else { // Generate normal classes if it's not a callback object - String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i)); - print("\"" + paramTypeC + "\""); - } - if (i != methParams.size() - 1) // Check if this is the last element - print(", "); - } - println(" };"); - print("int ___paramCB = "); - if (isArrayOrList) - println(callbackParam + ".size();"); - else - println("1;"); - // Generate array of parameter objects - print("void* paramObj[] = { "); - for (int i = 0; i < methParams.size(); i++) { - String paramType = methPrmTypes.get(i); - if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object - print("&___paramCB"); - } else - print(getSimpleIdentifier(methParams.get(i))); - if (i != methParams.size() - 1) - print(", "); - } - println(" };"); - // Check if this is "void" - if (retType.equals("void")) { - println("void* retObj = NULL;"); - println("rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);"); - } else { // We do have a return value - if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES) - println(checkAndGetCplusType(retType) + " retVal;"); - else - println(checkAndGetCplusType(retType) + " retVal = " + generateCplusInitializer(retType) + ";"); - println("void* retObj = &retVal;"); - println("rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);"); - println("return retVal;"); - } } @@ -2849,7 +2795,7 @@ public class IoTCompiler { /** * HELPER: writeStructParamClassCplusStub() writes member parameters of struct */ - private void writeStructParamClassCplusStub(List methParams, List methPrmTypes) { + private void writeStructParamClassCplusStub(List methParams, List methPrmTypes, String callbackType) { print("int numParam = "); writeLengthStructParamClassCplusStub(methParams, methPrmTypes); @@ -2864,6 +2810,9 @@ public class IoTCompiler { String simpleType = getGenericType(paramType); if (isStructClass(simpleType)) { writeStructMembersCplusStub(simpleType, paramType, param); + } else if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object + println("paramCls[pos] = \"int\";"); + println("paramObj[pos++] = &___paramCB" + i + ";"); } else { String prmTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i)); println("paramCls[pos] = \"" + prmTypeC + "\";"); @@ -2967,21 +2916,22 @@ public class IoTCompiler { * HELPER: writeStdMethodBodyCplusStub() writes the standard method body in the stub class */ private void writeStdMethodBodyCplusStub(InterfaceDecl intDecl, List methParams, - List methPrmTypes, String method, Set callbackClasses) { + List methPrmTypes, String method, String callbackType, boolean isCallbackMethod) { checkAndWriteStructSetupCplusStub(methParams, methPrmTypes, intDecl, method); println("int methodId = " + intDecl.getMethodNumId(method) + ";"); String retType = intDecl.getMethodType(method); println("string retType = \"" + checkAndGetCplusRetClsType(getStructType(getEnumType(retType))) + "\";"); + checkAndWriteEnumTypeCplusStub(methParams, methPrmTypes); // Generate array of parameter types if (isStructPresent(methParams, methPrmTypes)) { - writeStructParamClassCplusStub(methParams, methPrmTypes); + writeStructParamClassCplusStub(methParams, methPrmTypes, callbackType); } else { println("int numParam = " + methParams.size() + ";"); print("string paramCls[] = { "); for (int i = 0; i < methParams.size(); i++) { String paramType = returnGenericCallbackType(methPrmTypes.get(i)); - if (callbackClasses.contains(paramType)) { + if (checkCallbackType(paramType, callbackType)) { print("\"int\""); } else { String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i)); @@ -2993,11 +2943,14 @@ public class IoTCompiler { } } println(" };"); - checkAndWriteEnumTypeCplusStub(methParams, methPrmTypes); // Generate array of parameter objects print("void* paramObj[] = { "); for (int i = 0; i < methParams.size(); i++) { - print("&" + getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i)); + String paramType = returnGenericCallbackType(methPrmTypes.get(i)); + if (checkCallbackType(paramType, callbackType)) // Check if this has callback object + print("&___paramCB" + i); + else + print("&" + getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i)); // Check if this is the last element (don't print a comma) if (i != methParams.size() - 1) { print(", "); @@ -3053,8 +3006,7 @@ public class IoTCompiler { private void writePropertiesCplusStub(String intface, String newIntface, boolean callbackExist, Set callbackClasses) { println("IoTRMICall *rmiCall;"); - //println("IoTRMIObject\t\t\t*rmiObj;"); - println("string address;"); + println("string callbackAddress;"); println("vector ports;\n"); // Get the object Id Integer objId = mapIntfaceObjId.get(intface); @@ -3082,10 +3034,10 @@ public class IoTCompiler { private void writeConstructorCplusStub(String newStubClass, boolean callbackExist, Set callbackClasses) { println(newStubClass + - "(int _port, const char* _address, int _rev, bool* _bResult, vector _ports) {"); - println("address = _address;"); + "(int _port, const char* _skeletonAddress, const char* _callbackAddress, int _rev, bool* _bResult, vector _ports) {"); + println("callbackAddress = _callbackAddress;"); println("ports = _ports;"); - println("rmiCall = new IoTRMICall(_port, _address, _rev, _bResult);"); + println("rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev, _bResult);"); if (callbackExist) { Iterator it = callbackClasses.iterator(); String callbackType = (String) it.next(); @@ -3200,11 +3152,10 @@ public class IoTCompiler { String method = "___initCallBack()"; 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;"); - println("void* paramObj[] = { &ports[0], &address, &rev };"); + println("void* paramObj[] = { &ports[0], &callbackAddress, &rev };"); println("void* retObj = NULL;"); println("rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);"); println("}\n"); @@ -3695,7 +3646,7 @@ public class IoTCompiler { /** - * HELPER: writeMethodHelperReturnCplusSkeleton() writes the return statement part in skeleton + * HELPER: writeMethodInputParameters() writes the parameter variables for C++ skeleton */ private void writeMethodInputParameters(List methParams, List methPrmTypes, Set callbackClasses, String methodId) { @@ -3837,19 +3788,18 @@ public class IoTCompiler { List members = structDecl.getMembers(simpleType); int methodNumId = intDecl.getMethodNumId(method); String counter = "struct" + methodNumId + "Size" + iVar; - println("int pos = 0;"); // Set up variables if (isArrayOrList(paramType, param)) { // 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(getSimpleType(getEnumType(prmType)) + " param" + i + "[" + counter + "];"); + println(getSimpleType(getEnumType(prmType)) + " param" + iVar + i + "[" + counter + "];"); } } 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(getSimpleType(getEnumType(prmType)) + " param" + i + ";"); + println(getSimpleType(getEnumType(prmType)) + " param" + iVar + i + ";"); } } if (isArrayOrList(paramType, param)) { // An array or list @@ -3859,14 +3809,14 @@ public class IoTCompiler { for (int i = 0; i < members.size(); i++) { String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i)); println("paramCls[pos] = \"" + prmTypeC + "\";"); - println("paramObj[pos++] = ¶m" + i + "[i];"); + println("paramObj[pos++] = ¶m" + iVar + i + "[i];"); } println("}"); } else { // Just one struct element for (int i = 0; i < members.size(); i++) { String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i)); println("paramCls[pos] = \"" + prmTypeC + "\";"); - println("paramObj[pos++] = ¶m" + i + ";"); + println("paramObj[pos++] = ¶m" + iVar + i + ";"); } } } @@ -3898,13 +3848,13 @@ public class IoTCompiler { println("for(int i = 0; i < " + counter + "; i++) {"); for (int j = 0; j < members.size(); j++) { print("paramStruct" + i + "[i]." + getSimpleIdentifier(members.get(j))); - println(" = param" + j + "[i];"); + println(" = param" + i + j + "[i];"); } println("}"); } else { // Just one struct element for (int j = 0; j < members.size(); j++) { print("paramStruct" + i + "." + getSimpleIdentifier(members.get(j))); - println(" = param" + j + ";"); + println(" = param" + i + j + ";"); } } } @@ -3970,6 +3920,7 @@ public class IoTCompiler { println(";"); println("string paramCls[numParam];"); println("void* paramObj[numParam];"); + println("int pos = 0;"); // Iterate again over the parameters for (int i = 0; i < methParams.size(); i++) { String paramType = methPrmTypes.get(i); @@ -3981,8 +3932,8 @@ public class IoTCompiler { String prmType = returnGenericCallbackType(methPrmTypes.get(i)); if (callbackClasses.contains(prmType)) { isCallbackMethod = true; - callbackType = paramType; - writeCallbackCplusNumStubs(methParams, methPrmTypes, callbackType); + callbackType = prmType; + println("int numStubs" + i + " = 0;"); println("paramCls[pos] = \"int\";"); println("paramObj[pos++] = &numStubs" + i + ";"); } else { // Generate normal classes if it's not a callback object @@ -3996,7 +3947,7 @@ public class IoTCompiler { 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); + println("paramObj[pos++] = ¶mEnumInt" + i + ";"); else println("paramObj[pos++] = &" + getSimpleIdentifier(methParams.get(i)) + ";"); } @@ -4035,9 +3986,10 @@ public class IoTCompiler { String param = methParams.get(i); String simpleType = getGenericType(paramType); if (isStructClass(simpleType)) { - if (!begin) { // Generate comma for not the beginning variable - print(", "); begin = false; - } + if (!begin) // Generate comma for not the beginning variable + print(", "); + else + begin = false; int methodNumId = intDecl.getMethodNumId(method); print("int struct" + methodNumId + "Size" + i); } @@ -4350,9 +4302,10 @@ public class IoTCompiler { String param = methParams.get(i); String simpleType = getGenericType(paramType); if (isStructClass(simpleType)) { - if (!begin) { // Generate comma for not the beginning variable - print(", "); begin = false; - } + if (!begin) // Generate comma for not the beginning variable + print(", "); + else + begin = false; int methodNumId = intDecl.getMethodNumId(method); print("int struct" + methodNumId + "Size" + i); }