Integrating enum and struct in one method call; fixing minor bugs
[iot2.git] / iotjava / iotpolicy / IoTCompiler.java
index 9d9ecdd948f576618dd68f7f71783950f2026c2c..5c3ab9226913c2a771b8cea644078b4ff9d5911d 100644 (file)
@@ -447,7 +447,7 @@ public class IoTCompiler {
                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));");
                }
        }
 
@@ -629,7 +629,7 @@ public class IoTCompiler {
                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 (isStructClass(simpleType)) {
                        // Check if this is enum type
                                int methodNumId = intDecl.getMethodNumId(method);
@@ -661,7 +661,7 @@ public class IoTCompiler {
                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 (isStructClass(simpleType))
                                return true;
                }
@@ -682,10 +682,10 @@ public class IoTCompiler {
                        if (isStructClass(simpleType)) {
                                int members = getNumOfMembers(simpleType);
                                if (isArray(param)) {                   // An array
-                                       String structLen = param + ".length";
+                                       String structLen = getSimpleArrayType(param) + ".length";
                                        print(members + "*" + structLen);
                                } else if (isList(paramType)) { // A list
-                                       String structLen = param + ".size()";
+                                       String structLen = getSimpleArrayType(param) + ".size()";
                                        print(members + "*" + structLen);
                                } else
                                        print(Integer.toString(members));
@@ -708,15 +708,21 @@ public class IoTCompiler {
                List<String> memTypes = structDecl.getMemberTypes(simpleType);
                List<String> members = structDecl.getMembers(simpleType);
                if (isArray(param)) {                   // An array
-                       println("for(int i = 0; i < " + param + ".length; i++) {");
+                       println("for(int i = 0; i < " + getSimpleIdentifier(param) + ".length; i++) {");
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               println("paramCls[pos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
+                               print("paramObj[pos++] = " + getSimpleIdentifier(param) + "[i].");
+                               print(getSimpleIdentifier(members.get(i)));
+                               println(";");
+                       }
+                       println("}");
                } else if (isList(paramType)) { // A list
-                       println("for(int i = 0; i < " + param + ".size(); i++) {");
-               }
-               if (isArrayOrList(param, paramType)) {  // An array or list
+                       println("for(int i = 0; i < " + getSimpleIdentifier(param) + ".size(); i++) {");
                        for (int i = 0; i < members.size(); i++) {
                                String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
                                println("paramCls[pos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
-                               print("paramObj[pos++] = " + param + "[i].");
+                               print("paramObj[pos++] = " + getSimpleIdentifier(param) + ".get(i).");
                                print(getSimpleIdentifier(members.get(i)));
                                println(";");
                        }
@@ -725,7 +731,7 @@ public class IoTCompiler {
                        for (int i = 0; i < members.size(); i++) {
                                String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
                                println("paramCls[pos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
-                               print("paramObj[pos++] = " + param + ".");
+                               print("paramObj[pos++] = " + getSimpleIdentifier(param) + ".");
                                print(getSimpleIdentifier(members.get(i)));
                                println(";");
                        }
@@ -918,7 +924,7 @@ public class IoTCompiler {
        private String returnGenericCallbackType(String paramType) {
 
                if (getParamCategory(paramType) == ParamCategory.NONPRIMITIVES)
-                       return getTypeOfGeneric(paramType)[0];
+                       return getGenericType(paramType);
                else
                        return paramType;
        }
@@ -947,12 +953,12 @@ public class IoTCompiler {
                        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("}");
                        }
@@ -1020,6 +1026,7 @@ public class IoTCompiler {
         */
        private void writeMethodJavaStub(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
 
+               boolean isDefined = false;
                for (String method : methods) {
 
                        List<String> methParams = intDecl.getMethodParams(method);
@@ -1051,8 +1058,10 @@ public class IoTCompiler {
                                writeStdMethodBodyJavaStub(intDecl, methParams, methPrmTypes, method);
                        println("}\n");
                        // Write the init callback helper method
-                       if (isCallbackMethod)
+                       if (isCallbackMethod && !isDefined) {
                                writeInitCallbackJavaStub(callbackType, intDecl);
+                               isDefined = true;
+                       }
                }
        }
 
@@ -1110,7 +1119,7 @@ public class IoTCompiler {
                println("private String address;");
                println("private int[] ports;\n");
                // Get the object Id
-               println("private static int objectId = 0;");
+               println("private int objectId = 0;");
                if (callbackExist) {
                // We assume that each class only has one callback interface for now
                        Iterator it = callbackClasses.iterator();
@@ -1229,15 +1238,17 @@ public class IoTCompiler {
                        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 (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(" + methodNumId + ");");
+                                               println("set" + newObjectId + "Allowed.add(" + methodHelperNumId + ");");
                                        }
                                }
                        }
@@ -1293,8 +1304,8 @@ public class IoTCompiler {
                        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");
        }
@@ -1306,6 +1317,7 @@ public class IoTCompiler {
        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);
@@ -1332,8 +1344,10 @@ public class IoTCompiler {
                        // 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;
+                       }
                }
        }
 
@@ -1349,10 +1363,9 @@ public class IoTCompiler {
                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(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 + "];");
@@ -1367,7 +1380,7 @@ public class IoTCompiler {
                        }
                        // 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);");
@@ -1512,14 +1525,12 @@ public class IoTCompiler {
                StructDecl structDecl = getStructDecl(simpleType);
                List<String> memTypes = structDecl.getMemberTypes(simpleType);
                List<String> members = structDecl.getMembers(simpleType);
-               if (isArrayOrList(param, paramType)) {  // An array or list
+               if (isArrayOrList(paramType, param)) {  // An array or list
                        int methodNumId = intDecl.getMethodNumId(method);
                        String counter = "struct" + methodNumId + "Size" + iVar;
                        println("for(int i = 0; i < " + counter + "; i++) {");
                }
-               println("int pos = 0;");
-               if (isArrayOrList(param, paramType)) {  // An array or list
-                       println("for(int i = 0; i < retLen; i++) {");
+               if (isArrayOrList(paramType, param)) {  // An array or list
                        for (int i = 0; i < members.size(); i++) {
                                String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
                                println("paramCls[pos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
@@ -1542,6 +1553,7 @@ public class IoTCompiler {
        private void writeStructMembersInitJavaSkeleton(InterfaceDecl intDecl, List<String> methParams,
                        List<String> 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);
@@ -1559,12 +1571,11 @@ 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<String> members = structDecl.getMembers(simpleType);
                                List<String> memTypes = structDecl.getMemberTypes(simpleType);
-                               if (isArrayOrList(param, paramType)) {  // An array or list
+                               if (isArrayOrList(paramType, param)) {  // An array or list
                                        println("for(int i = 0; i < " + counter + "; i++) {");
                                }
                                if (isArray(param)) {   // An array
@@ -1592,7 +1603,7 @@ public class IoTCompiler {
                                }
                        } else {
                                // Take offsets of parameters
-                               println("int offset" + i +" = objPos;");
+                               println("int offset" + i +" = objPos++;");
                        }
                }
        }
@@ -1620,7 +1631,7 @@ public class IoTCompiler {
                StructDecl structDecl = getStructDecl(simpleType);
                List<String> memTypes = structDecl.getMemberTypes(simpleType);
                List<String> members = structDecl.getMembers(simpleType);
-               if (isArrayOrList(retType, retType)) {  // An array or list
+               if (isArray(retType)) { // An array or list
                        println("for(int i = 0; i < retLen; i++) {");
                        for (int i = 0; i < members.size(); i++) {
                                String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
@@ -1630,6 +1641,16 @@ public class IoTCompiler {
                                println(";");
                        }
                        println("}");
+               } else if (isList(retType)) {   // An array or list
+                       println("for(int i = 0; i < retLen; i++) {");
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               println("retCls[retPos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
+                               print("retObj[retPos++] = retStruct.get(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 prmType = checkAndGetArray(memTypes.get(i), members.get(i));
@@ -1652,8 +1673,9 @@ public class IoTCompiler {
 
                checkAndWriteEnumTypeJavaSkeleton(methParams, methPrmTypes);
                Map<Integer,String> mapStubParam = null;
-               if (isCallbackMethod)
+               if (isCallbackMethod) {
                        mapStubParam = writeCallbackJavaStubGeneration(methParams, methPrmTypes, callbackType);
+               }
                // Check if this is "void"
                String retType = intDecl.getMethodType(method);
                if (retType.equals("void")) {
@@ -1667,14 +1689,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
@@ -1718,6 +1741,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);
@@ -1781,7 +1805,8 @@ public class IoTCompiler {
                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");
@@ -1819,7 +1844,7 @@ public class IoTCompiler {
                                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);
+                                       String simpleType = getGenericType(paramType);
                                        if (isStructClass(simpleType)) {
                                                if (!begin) {   // Generate comma for not the beginning variable
                                                        print(", "); begin = false;
@@ -1874,7 +1899,7 @@ public class IoTCompiler {
                        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 (isStructClass(simpleType)) {
                                        int methodNumId = intDecl.getMethodNumId(method);
                                        print("public int ___");
@@ -1905,7 +1930,7 @@ public class IoTCompiler {
                        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 (isStructClass(simpleType)) {
                                        int methodNumId = intDecl.getMethodNumId(method);
                                        print("public int ___");
@@ -1935,7 +1960,7 @@ public class IoTCompiler {
                        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 (isStructClass(simpleType)) {
                                        int methodNumId = intDecl.getMethodNumId(method);
                                        println("int struct" + methodNumId + "Size" + i + " = 0;");
@@ -1957,7 +1982,7 @@ public class IoTCompiler {
                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);
                        boolean begin = true;
                        if (isStructClass(simpleType)) {
                                structExist = true;
@@ -1986,7 +2011,7 @@ public class IoTCompiler {
                        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 (isStructClass(simpleType)) {
                                        int methodNumId = intDecl.getMethodNumId(method);
                                        print("case ");
@@ -2015,7 +2040,7 @@ public class IoTCompiler {
                        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 (isStructClass(simpleType)) {
                                        int methodNumId = intDecl.getMethodNumId(method);
                                        print("case ");
@@ -2148,7 +2173,7 @@ public class IoTCompiler {
 
                println("private " + intface + " mainObj;");
                // For callback skeletons, this is its own object Id
-               println("private static int objectId = 0;");
+               println("private int objectId = 0;");
                // Callback
                if (callbackExist) {
                        println("private static int objIdCnt = 0;");
@@ -2166,7 +2191,6 @@ public class IoTCompiler {
                println("public " + newSkelClass + "(" + intface + " _mainObj, int _objectId) throws Exception {");
                println("mainObj = _mainObj;");
                println("objectId = _objectId;");
-               writeStructPermissionJavaSkeleton(methods, intDecl, intface);
                println("}\n");
        }
 
@@ -2196,7 +2220,7 @@ public class IoTCompiler {
                                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);
+                                       String simpleType = getGenericType(paramType);
                                        if (isStructClass(simpleType)) {
                                                if (!begin) {   // Generate comma for not the beginning variable
                                                        print(", "); begin = false;
@@ -2442,6 +2466,7 @@ public class IoTCompiler {
                                // 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);
@@ -2551,6 +2576,7 @@ public class IoTCompiler {
         */
        private void writeMethodCplusStub(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
 
+               boolean isDefined = false;
                for (String method : methods) {
 
                        List<String> methParams = intDecl.getMethodParams(method);
@@ -2561,7 +2587,7 @@ public class IoTCompiler {
                        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;
@@ -2580,12 +2606,13 @@ public class IoTCompiler {
                        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;
                        }
                }
        }
@@ -2606,7 +2633,7 @@ public class IoTCompiler {
                        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);
@@ -2614,7 +2641,7 @@ public class IoTCompiler {
                                        println(callbackType + "_CallbackSkeleton* skel = new " + callbackType + "_CallbackSkeleton(" +
                                                getSimpleIdentifier(param) + ", objIdCnt++);");
                                println("vecCallbackObj.push_back(skel);");
-                               if (isArrayOrList(paramType, param))
+                               if (isArrayOrList)
                                        println("}");
                        }
                }
@@ -2650,7 +2677,7 @@ public class IoTCompiler {
                        if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
                                print("&___paramCB");
                        } else
-                               print(getSimpleIdentifier(methParams.get(i)));
+                               print("&" + getSimpleIdentifier(methParams.get(i)));
                        if (i != methParams.size() - 1)
                                print(", ");
                }
@@ -2736,7 +2763,7 @@ public class IoTCompiler {
                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 (isStructClass(simpleType)) {
                        // Check if this is enum type
                                println("int numParam" + i + " = 1;");
@@ -2746,7 +2773,7 @@ public class IoTCompiler {
                                println("string retTypeStruct" + i + " = \"void\";");
                                println("string paramClsStruct" + i + "[] = { \"int\" };");
                                print("int structLen" + i + " = ");
-                               if (isArrayOrList(param, paramType)) {  // An array
+                               if (isArrayOrList(paramType, param)) {  // An array
                                        println(getSimpleArrayType(param) + ".size();");
                                } else {        // Just one element
                                        println("1;");
@@ -2773,8 +2800,8 @@ public class IoTCompiler {
                        String simpleType = getGenericType(paramType);
                        if (isStructClass(simpleType)) {
                                int members = getNumOfMembers(simpleType);
-                               if (isArrayOrList(param, paramType)) {                  // An array
-                                       String structLen = param + ".size()";
+                               if (isArrayOrList(paramType, param)) {  // An array or list
+                                       String structLen = getSimpleIdentifier(param) + ".size()";
                                        print(members + "*" + structLen);
                                } else
                                        print(Integer.toString(members));
@@ -2796,24 +2823,22 @@ public class IoTCompiler {
                StructDecl structDecl = getStructDecl(simpleType);
                List<String> memTypes = structDecl.getMemberTypes(simpleType);
                List<String> members = structDecl.getMembers(simpleType);
-               if (isArrayOrList(param, paramType)) {  // An array or list
-                       println("for(int i = 0; i < " + param + ".size(); i++) {");
+               if (isArrayOrList(paramType, param)) {  // An array or list
+                       println("for(int i = 0; i < " + getSimpleIdentifier(param) + ".size(); i++) {");
                }
-               if (isArrayOrList(param, paramType)) {  // An array or list
+               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("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
-                               print("paramObj[pos++] = &" + param + "[i].");
+                               String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+                               println("paramCls[pos] = \"" + prmTypeC + "\";");
+                               print("paramObj[pos++] = &" + getSimpleIdentifier(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(";");
@@ -2841,9 +2866,8 @@ public class IoTCompiler {
                        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(";");
@@ -2919,17 +2943,15 @@ public class IoTCompiler {
                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 + ";");
                        }
                }
@@ -2946,12 +2968,13 @@ public class IoTCompiler {
         * 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) + ";");
                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);
@@ -2959,15 +2982,19 @@ public class IoTCompiler {
                        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(" };");
-                       checkAndWriteEnumTypeCplusStub(methParams, methPrmTypes);
                        // Generate array of parameter objects
                        print("void* paramObj[] = { ");
                        for (int i = 0; i < methParams.size(); i++) {
@@ -3112,7 +3139,7 @@ public class IoTCompiler {
                        int newObjectId = getNewIntfaceObjectId(newIntface);
                        println("if (set" + newObjectId + "Allowed.find(methodId) == set" + newObjectId + "Allowed.end()) {");
                        println("cerr << \"Callback object for " + intface + " is not allowed to access method: \" << methodId;");
-                       println("exit(-1);");
+                       println("return;");
                        println("}");
                }
        }
@@ -3138,7 +3165,7 @@ public class IoTCompiler {
                println(" else {");
                println("cerr << \"Illegal object Id: \" << to_string(objId);");
                // TODO: perhaps need to change this into "throw" to make it cleaner (allow stack unfolding)
-               println("exit(-1);");
+               println("return;");
                println("}");
                println("}");
                println("}\n");
@@ -3148,15 +3175,17 @@ public class IoTCompiler {
        /**
         * HELPER: writeCplusInitCallbackPermission() writes the permission for callback
         */
-       private void writeCplusInitCallbackPermission(String intface, InterfaceDecl intDecl) {
+       private void writeCplusInitCallbackPermission(String intface, InterfaceDecl intDecl, boolean 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 + ");");
+               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 + ");");
+                       }
                }
        }
 
@@ -3174,7 +3203,7 @@ public class IoTCompiler {
                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;");
@@ -3224,8 +3253,14 @@ public class IoTCompiler {
                                // 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();
@@ -3320,8 +3355,14 @@ public class IoTCompiler {
                                // 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();
@@ -3374,7 +3415,7 @@ public class IoTCompiler {
                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) {
@@ -3404,15 +3445,17 @@ public class IoTCompiler {
                        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 (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(" + methodNumId + ");");
+                                               println("set" + newObjectId + "Allowed.insert(" + helperMethodNumId + ");");
                                        }
                                }
                        }
@@ -3429,7 +3472,7 @@ public class IoTCompiler {
                println("bool _bResult = false;");
                println("mainObj = _mainObj;");
                println("rmiObj = new IoTRMIObject(_port, &_bResult);");
-               writeCplusInitCallbackPermission(intface, intDecl);
+               writeCplusInitCallbackPermission(intface, intDecl, callbackExist);
                writeStructPermissionCplusSkeleton(methods, intDecl, intface);
                println("___waitRequestInvokeMethod();");
                println("}\n");
@@ -3500,7 +3543,7 @@ public class IoTCompiler {
                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[] = { &param1, &param2, &param3 };");
                println("rmiObj->getMethodParams(paramCls, numParam, paramObj);");
                println("bool bResult = false;");
@@ -3515,6 +3558,7 @@ public class IoTCompiler {
        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);
@@ -3544,8 +3588,10 @@ public class IoTCompiler {
                        // Now, write the body of skeleton!
                        writeStdMethodBodyCplusSkeleton(methParams, methodId, intDecl.getMethodType(method));
                        println("}\n");
-                       if (isCallbackMethod)
+                       if (isCallbackMethod && !isDefined) {
                                writeInitCallbackCplusSkeleton(callbackSkeleton);
+                               isDefined = true;
+                       }
                }
        }
 
@@ -3559,11 +3605,8 @@ public class IoTCompiler {
                        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;");
-                       }
                }
        }
 
@@ -3579,13 +3622,13 @@ public class IoTCompiler {
                        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 {
@@ -3634,7 +3677,7 @@ public class IoTCompiler {
                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
@@ -3795,11 +3838,8 @@ public class IoTCompiler {
                List<String> members = structDecl.getMembers(simpleType);
                int methodNumId = intDecl.getMethodNumId(method);
                String counter = "struct" + methodNumId + "Size" + iVar;
-               if (isArrayOrList(param, paramType)) {  // An array or list
-                       println("for(int i = 0; i < " + counter + "; i++) {");
-               }
                // Set up variables
-               if (isArrayOrList(param, paramType)) {  // An array or list
+               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));
@@ -3812,21 +3852,20 @@ public class IoTCompiler {
                                println(getSimpleType(getEnumType(prmType)) + " param" + i + ";");
                        }
                }
-               println("int pos = 0;");
-               if (isArrayOrList(param, paramType)) {  // An array or list
-                       println("for(int i = 0; i < retLen; i++) {");
+               if (isArrayOrList(paramType, param)) {  // An array or list
+                       println("for(int i = 0; i < " + counter + "; i++) {");
+               }
+               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("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               String prmTypeC = checkAndGetCplusArgClsType(memTypes.get(i), members.get(i));
+                               println("paramCls[pos] = \"" + prmTypeC + "\";");
                                println("paramObj[pos++] = &param" + 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++] = &param" + i + ";");
                        }
                }
@@ -3847,15 +3886,15 @@ public class IoTCompiler {
                                int methodNumId = intDecl.getMethodNumId(method);
                                String counter = "struct" + methodNumId + "Size" + i;
                                // Declaration
-                               if (isArrayOrList(param, paramType)) {  // An array or list
-                                       println("vector<" + simpleType + "> paramStruct" + i + ";");
+                               if (isArrayOrList(paramType, param)) {  // An array or list
+                                       println("vector<" + simpleType + "> paramStruct" + i + "(" + counter + ");");
                                } else
                                        println(simpleType + " paramStruct" + i + ";");
                                // Initialize members
                                StructDecl structDecl = getStructDecl(simpleType);
                                List<String> members = structDecl.getMembers(simpleType);
                                List<String> memTypes = structDecl.getMemberTypes(simpleType);
-                               if (isArrayOrList(param, paramType)) {  // An array or list
+                               if (isArrayOrList(paramType, param)) {  // An array or list
                                        println("for(int i = 0; i < " + counter + "; i++) {");
                                        for (int j = 0; j < members.size(); j++) {
                                                print("paramStruct" + i + "[i]." + getSimpleIdentifier(members.get(j)));
@@ -3897,9 +3936,8 @@ public class IoTCompiler {
                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(";");
@@ -3907,9 +3945,8 @@ public class IoTCompiler {
                        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(";");
@@ -3933,6 +3970,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);
@@ -3950,16 +3988,16 @@ public class IoTCompiler {
                                        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(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) + "\";");
+                                       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++] = &paramEnumInt" + i);
+                                               println("paramObj[pos++] = &paramEnumInt" + i + ";");
                                        else
                                                println("paramObj[pos++] = &" + getSimpleIdentifier(methParams.get(i)) + ";");
                                }
@@ -3996,7 +4034,7 @@ public class IoTCompiler {
                                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);
+                                       String simpleType = getGenericType(paramType);
                                        if (isStructClass(simpleType)) {
                                                if (!begin) {   // Generate comma for not the beginning variable
                                                        print(", "); begin = false;
@@ -4044,7 +4082,7 @@ public class IoTCompiler {
                        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 (isStructClass(simpleType)) {
                                        int methodNumId = intDecl.getMethodNumId(method);
                                        print("int ___");
@@ -4079,7 +4117,7 @@ public class IoTCompiler {
                        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 (isStructClass(simpleType)) {
                                        int methodNumId = intDecl.getMethodNumId(method);
                                        print("int ___");
@@ -4112,12 +4150,12 @@ public class IoTCompiler {
                        println("if (_objectId == object" + newObjectId + "Id) {");
                        println("if (set" + newObjectId + "Allowed.find(methodId) == set" + newObjectId + "Allowed.end()) {");
                        println("cerr << \"Object with object Id: \" << _objectId << \"  is not allowed to access method: \" << methodId << endl;");
-                       println("exit(-1);");
+                       println("return;");
                        println("}");
                        println("}");
                        println("else {");
                        println("cerr << \"Object Id: \" << _objectId << \" not recognized!\" << endl;");
-                       println("exit(-1);");
+                       println("return;");
                        println("}");
                }
        }
@@ -4255,7 +4293,6 @@ public class IoTCompiler {
                println(newSkelClass + "(" + intface + " *_mainObj, int _objectId) {");
                println("mainObj = _mainObj;");
                println("objectId = _objectId;");
-               writeStructPermissionCplusSkeleton(methods, intDecl, intface);
                println("}\n");
        }
 
@@ -4312,7 +4349,7 @@ public class IoTCompiler {
                                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);
+                                       String simpleType = getGenericType(paramType);
                                        if (isStructClass(simpleType)) {
                                                if (!begin) {   // Generate comma for not the beginning variable
                                                        print(", "); begin = false;
@@ -5048,14 +5085,14 @@ public class IoTCompiler {
                        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);
@@ -5067,7 +5104,6 @@ public class IoTCompiler {
                } else
                        // Just return it as is if it's not non-primitives
                        return paramType;
-                       //return checkAndGetParamClass(paramType, true);
        }
 
 
@@ -5232,6 +5268,9 @@ public class IoTCompiler {
                // 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;
        }