Adding new policy, Java, and Cpp files for testing/debugging
[iot2.git] / iotjava / iotpolicy / IoTCompiler.java
index db60fccf95e3218f6a4109cd795f8f94adcf92da..028373b77b8883a43f9b70ee16089ec01bfa7fd1 100644 (file)
@@ -59,6 +59,7 @@ public class IoTCompiler {
        private String dir;
        private String subdir;
 
+
        /**
         * Class constants
         */
@@ -73,6 +74,7 @@ public class IoTCompiler {
                USERDEFINED             // Assumed as driver classes
        }
 
+
        /**
         * Class constructors
         */
@@ -104,7 +106,6 @@ public class IoTCompiler {
         * data structures.
         * Additionally, the data structure handles are
         * returned from tree-parsing for further process.
-        *
         */
        public void setDataStructures(String origInt, ParseNode pnPol, ParseNode pnReq) {
 
@@ -183,7 +184,7 @@ public class IoTCompiler {
 
 
        /**
-        * HELPER: writeMethodJavaLocalInterface() writes the method of the interface
+        * HELPER: writeMethodJavaLocalInterface() writes the method of the local interface
         */
        private void writeMethodJavaLocalInterface(Collection<String> methods, InterfaceDecl intDecl) {
 
@@ -330,12 +331,6 @@ public class IoTCompiler {
                        // Write interface header
                        println("");
                        println("public interface " + intface + " {");
-                       // Write enum if any...
-                       //EnumDecl enumDecl = (EnumDecl) decHandler.getEnumDecl(intface);
-                       //writeEnumJava(enumDecl);
-                       // Write struct if any...
-                       //StructDecl structDecl = (StructDecl) decHandler.getStructDecl(intface);
-                       //writeStructJava(structDecl);
                        // Write methods
                        writeMethodJavaLocalInterface(methods, intDecl);
                        println("}");
@@ -491,7 +486,7 @@ public class IoTCompiler {
 
 
        /**
-        * HELPER: writeConstructorJavaStub() writes the constructor of the stub class
+        * HELPER: writeInitCallbackJavaStub() writes callback initialization in stub
         */
        private void writeInitCallbackJavaStub(String intface, InterfaceDecl intDecl) {
 
@@ -598,54 +593,294 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: checkAndWriteStructSetupJavaStub() writes the struct type setup
+        */
+       private void checkAndWriteStructSetupJavaStub(List<String> methParams, List<String> methPrmTypes, 
+                       InterfaceDecl intDecl, String method) {
+               
+               // Iterate and find struct declarations
+               for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getSimpleType(paramType);
+                       if (isStructClass(simpleType)) {
+                       // Check if this is enum type
+                               int methodNumId = intDecl.getMethodNumId(method);
+                               String helperMethod = methodNumId + "struct" + i;
+                               println("int methodIdStruct" + i + " = " + intDecl.getHelperMethodNumId(helperMethod) + ";");
+                               println("Class<?> retTypeStruct" + i + " = void.class;");
+                               println("Class<?>[] paramClsStruct" + i + " = new Class<?>[] { int.class };");
+                               if (isArray(param)) {   // An array
+                                       println("Object[] paramObjStruct" + i + " = new Object[] { " + getSimpleArrayType(param) + ".length };");
+                               } else if (isList(paramType)) { // A list
+                                       println("Object[] paramObjStruct" + i + " = new Object[] { " + getSimpleArrayType(param) + ".size() };");
+                               } else {        // Just one element
+                                       println("Object[] paramObjStruct" + i + " = new Object[] { new Integer(1) };");
+                               }
+                               println("rmiCall.remoteCall(objectId, methodIdStruct" + i + 
+                                               ", retTypeStruct" + i + ", null, paramClsStruct" + i + 
+                                               ", paramObjStruct" + i + ");\n");
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: isStructPresent() checks presence of struct
+        */
+       private boolean isStructPresent(List<String> methParams, List<String> methPrmTypes) {
+
+               // Iterate and find enum declarations
+               for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getSimpleType(paramType);
+                       if (isStructClass(simpleType))
+                               return true;
+               }
+               return false;
+       }
+
+
+       /**
+        * HELPER: writeLengthStructParamClassJavaStub() writes lengths of parameters
+        */
+       private void writeLengthStructParamClassJavaStub(List<String> methParams, List<String> methPrmTypes) {
+
+               // Iterate and find struct declarations - count number of params
+               for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getGenericType(paramType);
+                       if (isStructClass(simpleType)) {
+                               int members = getNumOfMembers(simpleType);
+                               if (isArray(param)) {                   // An array
+                                       String structLen = param + ".length";
+                                       print(members + "*" + structLen);
+                               } else if (isList(paramType)) { // A list
+                                       String structLen = param + ".size()";
+                                       print(members + "*" + structLen);
+                               } else
+                                       print(Integer.toString(members));
+                       } else
+                               print("1");
+                       if (i != methParams.size() - 1) {
+                               print("+");
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: writeStructMembersJavaStub() writes parameters of struct
+        */
+       private void writeStructMembersJavaStub(String simpleType, String paramType, String param) {
+
+               // Get the struct declaration for this struct and generate initialization code
+               StructDecl structDecl = getStructDecl(simpleType);
+               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++) {");
+               } else if (isList(paramType)) { // A list
+                       println("for(int i = 0; i < " + param + ".size(); i++) {");
+               }
+               if (isArrayOrList(param, paramType)) {  // 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;");
+                               print("paramObj[pos++] = " + param + "[i].");
+                               print(getSimpleIdentifier(members.get(i)));
+                               println(";");
+                       }
+                       println("}");
+               } else {        // Just one struct element
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               println("paramCls[pos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
+                               print("paramObj[pos++] = " + param + ".");
+                               print(getSimpleIdentifier(members.get(i)));
+                               println(";");
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: writeStructParamClassJavaStub() writes parameters if struct is present
+        */
+       private void writeStructParamClassJavaStub(List<String> methParams, List<String> methPrmTypes) {
+
+               print("int paramLen = ");
+               writeLengthStructParamClassJavaStub(methParams, methPrmTypes);
+               println(";");
+               println("Object[] paramObj = new Object[paramLen];");
+               println("Class<?>[] paramCls = 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);
+                       String param = methParams.get(i);
+                       String simpleType = getGenericType(paramType);
+                       if (isStructClass(simpleType)) {
+                               writeStructMembersJavaStub(simpleType, paramType, param);
+                       } else {
+                               String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
+                               println("paramCls[pos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
+                               print("paramObj[pos++] = ");
+                               print(getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i));
+                               println(";");
+                       }
+               }
+               
+       }
+
+
+       /**
+        * HELPER: writeStructRetMembersJavaStub() writes parameters of struct for return statement
+        */
+       private void writeStructRetMembersJavaStub(String simpleType, String retType) {
+
+               // Get the struct declaration for this struct and generate initialization code
+               StructDecl structDecl = getStructDecl(simpleType);
+               List<String> memTypes = structDecl.getMemberTypes(simpleType);
+               List<String> members = structDecl.getMembers(simpleType);
+               if (isArrayOrList(retType, retType)) {  // An array or list
+                       println("for(int i = 0; i < retLen; i++) {");
+               }
+               if (isArray(retType)) { // An array
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               print("structRet[i]." + getSimpleIdentifier(members.get(i)));
+                               println(" = (" + getSimpleType(getEnumType(prmType)) + ") retObj[retObjPos++];");
+                       }
+                       println("}");
+               } else if (isList(retType)) {   // A list
+                       println(simpleType + " structRetMem = new " + simpleType + "();");
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               print("structRetMem." + getSimpleIdentifier(members.get(i)));
+                               println(" = (" + getSimpleType(getEnumType(prmType)) + ") retObj[retObjPos++];");
+                       }
+                       println("structRet.add(structRetMem);");
+                       println("}");
+               } else {        // Just one struct element
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               print("structRet." + getSimpleIdentifier(members.get(i)));
+                               println(" = (" + getSimpleType(getEnumType(prmType)) + ") retObj[retObjPos++];");
+                       }
+               }
+               println("return structRet;");
+       }
+
+
+       /**
+        * HELPER: writeStructReturnJavaStub() writes parameters if struct is present for return statement
+        */
+       private void writeStructReturnJavaStub(String simpleType, String retType) {
+
+               // Handle the returned struct!!!
+               println("Object retLenObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
+               // Minimum retLen is 1 if this is a single struct object
+               println("int retLen = (int) retLenObj;");
+               int numMem = getNumOfMembers(simpleType);
+               println("Class<?>[] retCls = new Class<?>[" + numMem + "*retLen];");
+               println("Class<?>[] retClsVal = new Class<?>[" + numMem + "*retLen];");
+               println("int retPos = 0;");
+               // Get the struct declaration for this struct and generate initialization code
+               StructDecl structDecl = getStructDecl(simpleType);
+               List<String> memTypes = structDecl.getMemberTypes(simpleType);
+               List<String> members = structDecl.getMembers(simpleType);
+               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 prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               println("retCls[retPos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
+                               println("retClsVal[retPos++] = null;");
+                       }
+                       println("}");
+               } else {        // Just one struct element
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               println("retCls[retPos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
+                               println("retClsVal[retPos++] = null;");
+                       }
+               }
+               println("Object[] retObj = rmiCall.getStructObjects(retCls, retClsVal);");
+               if (isArray(retType)) {                 // An array
+                       println(simpleType + "[] structRet = new " + simpleType + "[retLen];");
+                       println("for(int i = 0; i < retLen; i++) {");
+                       println("structRet[i] = new " + simpleType + "();");
+                       println("}");
+               } else if (isList(retType)) {   // A list
+                       println("List<" + simpleType + "> structRet = new ArrayList<" + simpleType + ">();");
+               } else
+                       println(simpleType + " structRet = new " + simpleType + "();");
+               println("int retObjPos = 0;");
+               writeStructRetMembersJavaStub(simpleType, retType);
+       }
+
+
        /**
         * HELPER: writeStdMethodBodyJavaStub() writes the standard method body in the stub class
         */
        private void writeStdMethodBodyJavaStub(InterfaceDecl intDecl, List<String> methParams,
                        List<String> methPrmTypes, String method) {
 
+               checkAndWriteStructSetupJavaStub(methParams, methPrmTypes, intDecl, method);
                println("int methodId = " + intDecl.getMethodNumId(method) + ";");
                String retType = intDecl.getMethodType(method);
-               println("Class<?> retType = " + getSimpleType(getEnumType(retType)) + ".class;");
+               println("Class<?> retType = " + getSimpleType(getStructType(getEnumType(retType))) + ".class;");
                checkAndWriteEnumTypeJavaStub(methParams, methPrmTypes);
                // Generate array of parameter types
-               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");
-                       // Check if this is the last element (don't print a comma)
-                       if (i != methParams.size() - 1) {
-                               print(", ");
+               if (isStructPresent(methParams, methPrmTypes)) {
+                       writeStructParamClassJavaStub(methParams, methPrmTypes);
+               } 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");
+                               // Check if this is the last element (don't print a comma)
+                               if (i != methParams.size() - 1) {
+                                       print(", ");
+                               }
                        }
-               }
-               println(" };");
-               // 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));
-                       // Check if this is the last element (don't print a comma)
-                       if (i != methParams.size() - 1) {
-                               print(", ");
+                       println(" };");
+                       // 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));
+                               // Check if this is the last element (don't print a comma)
+                               if (i != methParams.size() - 1) {
+                                       print(", ");
+                               }
                        }
+                       println(" };");
                }
-               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 if (getParamCategory(retType) == ParamCategory.ENUM) {
-                       // This is an enum type
-                               println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
-                               checkAndWriteEnumRetTypeJavaStub(retType);
+                       // Generate array of parameter types
+                       if (isStructClass(getGenericType(getSimpleArrayType(retType)))) {
+                               writeStructReturnJavaStub(getGenericType(getSimpleArrayType(retType)), retType);
                        } else {
-                               println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
-                               println("return (" + retType + ")retObj;");
+                       // Check if the return value NONPRIMITIVES
+                               if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES) {
+                                       String[] retGenValType = getTypeOfGeneric(retType);
+                                       println("Class<?> retGenValType = " + retGenValType[0] + ".class;");
+                                       println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, retGenValType, paramCls, paramObj);");
+                                       println("return (" + retType + ")retObj;");
+                               } else if (getParamCategory(retType) == ParamCategory.ENUM) {
+                               // This is an enum type
+                                       println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
+                                       checkAndWriteEnumRetTypeJavaStub(retType);
+                               } else {
+                                       println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
+                                       println("return (" + retType + ")retObj;");
+                               }
                        }
                }
        }
@@ -682,7 +917,6 @@ public class IoTCompiler {
                println("try {");
                // Check if this is single object, array, or list of objects
                for (int i = 0; i < methParams.size(); i++) {
-
                        String paramType = methPrmTypes.get(i);
                        if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
                                String param = methParams.get(i);
@@ -755,7 +989,7 @@ public class IoTCompiler {
 
 
        /**
-        * HELPER: writeMethodJavaStub() writes the method of the stub class
+        * HELPER: writeMethodJavaStub() writes the methods of the stub class
         */
        private void writeMethodJavaStub(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
 
@@ -1049,7 +1283,8 @@ public class IoTCompiler {
        /**
         * HELPER: writeCallbackJavaStubGeneration() writes the callback stub generation part
         */
-       private Map<Integer,String> writeCallbackJavaStubGeneration(List<String> methParams, List<String> methPrmTypes, String callbackType) {
+       private Map<Integer,String> writeCallbackJavaStubGeneration(List<String> methParams, List<String> methPrmTypes, 
+                       String callbackType) {
 
                Map<Integer,String> mapStubParam = new HashMap<Integer,String>();
                // Iterate over callback objects
@@ -1182,44 +1417,181 @@ public class IoTCompiler {
                        println("Object retObj = retEnumVal;");
                }
        }
-
-
+       
+       
        /**
-        * HELPER: writeStdMethodHelperBodyJavaSkeleton() writes the standard method body helper in the skeleton class
+        * HELPER: writeLengthStructParamClassSkeleton() writes lengths of params
         */
-       private void writeStdMethodHelperBodyJavaSkeleton(InterfaceDecl intDecl, List<String> methParams,
-                       List<String> methPrmTypes, String method, Set<String> callbackClasses) {
-               // Generate array of parameter objects
-               boolean isCallbackMethod = false;
-               String callbackType = null;
-               print("Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { ");
+       private void writeLengthStructParamClassSkeleton(List<String> methParams, List<String> methPrmTypes, 
+                       String method, InterfaceDecl intDecl) {
+
+               // Iterate and find struct declarations - count number of params
                for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getGenericType(paramType);
+                       if (isStructClass(simpleType)) {
+                               int members = getNumOfMembers(simpleType);
+                               print(Integer.toString(members) + "*");
+                               int methodNumId = intDecl.getMethodNumId(method);
+                               print("struct" + methodNumId + "Size" + i);
+                       } else
+                               print("1");
+                       if (i != methParams.size() - 1) {
+                               print("+");
+                       }
+               }
+       }
 
-                       String paramType = returnGenericCallbackType(methPrmTypes.get(i));
-                       if (callbackClasses.contains(paramType)) {
-                               isCallbackMethod = true;
-                               callbackType = paramType;
-                               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(getEnumType(prmType)) + ".class");
+       
+       /**
+        * HELPER: writeStructMembersJavaSkeleton() writes member parameters of struct
+        */
+       private void writeStructMembersJavaSkeleton(String simpleType, String paramType, 
+                       String param, String method, InterfaceDecl intDecl, int iVar) {
+
+               // Get the struct declaration for this struct and generate initialization code
+               StructDecl structDecl = getStructDecl(simpleType);
+               List<String> memTypes = structDecl.getMemberTypes(simpleType);
+               List<String> members = structDecl.getMembers(simpleType);
+               if (isArrayOrList(param, paramType)) {  // 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++) {");
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               println("paramCls[pos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
+                               println("paramClsGen[pos++] = null;");
+                       }
+                       println("}");
+               } else {        // Just one struct element
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               println("paramCls[pos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
+                               println("paramClsGen[pos++] = null;");
                        }
-                       if (i != methParams.size() - 1)
-                               print(", ");
                }
-               println(" }, ");
-               // Generate generic class if it's a generic type.. null otherwise
-               print("new Class<?>[] { ");
+       }
+
+
+       /**
+        * HELPER: writeStructMembersInitJavaSkeleton() writes member parameters initialization of struct
+        */
+       private void writeStructMembersInitJavaSkeleton(InterfaceDecl intDecl, List<String> methParams,
+                       List<String> methPrmTypes, String method) {
+
                for (int i = 0; i < methParams.size(); i++) {
-                       String prmType = methPrmTypes.get(i);
-                       if (getParamCategory(prmType) == ParamCategory.NONPRIMITIVES)
-                               print(getTypeOfGeneric(prmType)[0] + ".class");
-                       else
-                               print("null");
-                       if (i != methParams.size() - 1)
-                               print(", ");
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getGenericType(paramType);
+                       if (isStructClass(simpleType)) {
+                               int methodNumId = intDecl.getMethodNumId(method);
+                               String counter = "struct" + methodNumId + "Size" + i;
+                               // Declaration
+                               if (isArray(param)) {                   // An array
+                                       println(simpleType + "[] paramStruct" + i + " = new " + simpleType + "[" + counter + "];");
+                                       println("for(int i = 0; i < " + counter + "; i++) {");
+                                       println("paramStruct" + i + "[i] = new " + simpleType + "();");
+                                       println("}");
+                               } else if (isList(paramType)) { // A list
+                                       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
+                                       println("for(int i = 0; i < " + counter + "; i++) {");
+                               }
+                               if (isArray(param)) {   // An array
+                                       for (int j = 0; j < members.size(); j++) {
+                                               String prmType = checkAndGetArray(memTypes.get(j), members.get(j));
+                                               print("paramStruct" + i + "[i]." + getSimpleIdentifier(members.get(j)));
+                                               println(" = (" + getSimpleType(getEnumType(prmType)) + ") paramObj[objPos++];");
+                                       }
+                                       println("}");
+                               } else if (isList(paramType)) { // A list
+                                       println(simpleType + " paramStructMem = new " + simpleType + "();");
+                                       for (int j = 0; j < members.size(); j++) {
+                                               String prmType = checkAndGetArray(memTypes.get(j), members.get(j));
+                                               print("paramStructMem." + getSimpleIdentifier(members.get(j)));
+                                               println(" = (" + getSimpleType(getEnumType(prmType)) + ") paramObj[objPos++];");
+                                       }
+                                       println("paramStruct" + i + ".add(paramStructMem);");
+                                       println("}");
+                               } else {        // Just one struct element
+                                       for (int j = 0; j < members.size(); j++) {
+                                               String prmType = checkAndGetArray(memTypes.get(j), members.get(j));
+                                               print("paramStruct" + i + "." + getSimpleIdentifier(members.get(j)));
+                                               println(" = (" + getSimpleType(getEnumType(prmType)) + ") paramObj[objPos++];");
+                                       }
+                               }
+                       } else {
+                               // Take offsets of parameters
+                               println("int offset" + i +" = objPos;");
+                       }
                }
-               println(" });");
+       }
+
+
+       /**
+        * HELPER: writeStructReturnJavaSkeleton() writes struct for return statement
+        */
+       private void writeStructReturnJavaSkeleton(String simpleType, String retType) {
+
+               // Minimum retLen is 1 if this is a single struct object
+               if (isArray(retType))
+                       println("int retLen = retStruct.length;");
+               else if (isList(retType))
+                       println("int retLen = retStruct.size();");
+               else    // Just single struct object
+                       println("int retLen = 1;");
+               println("Object retLenObj = retLen;");
+               println("rmiObj.sendReturnObj(retLenObj);");
+               int numMem = getNumOfMembers(simpleType);
+               println("Class<?>[] retCls = new Class<?>[" + numMem + "*retLen];");
+               println("Object[] retObj = new Object[" + numMem + "*retLen];");
+               println("int retPos = 0;");
+               // Get the struct declaration for this struct and generate initialization code
+               StructDecl structDecl = getStructDecl(simpleType);
+               List<String> memTypes = structDecl.getMemberTypes(simpleType);
+               List<String> members = structDecl.getMembers(simpleType);
+               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 prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               println("retCls[retPos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
+                               print("retObj[retPos++] = retStruct[i].");
+                               print(getEnumParam(memTypes.get(i), getSimpleIdentifier(members.get(i)), i));
+                               println(";");
+                       }
+                       println("}");
+               } else {        // Just one struct element
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               println("retCls[retPos] = " + getSimpleType(getEnumType(prmType)) + ".class;");
+                               print("retObj[retPos++] = retStruct.");
+                               print(getEnumParam(memTypes.get(i), getSimpleIdentifier(members.get(i)), i));
+                               println(";");
+                       }
+               }
+
+       }
+
+
+       /**
+        * HELPER: writeMethodHelperReturnJavaSkeleton() writes return statement part in skeleton
+        */
+       private void writeMethodHelperReturnJavaSkeleton(InterfaceDecl intDecl, List<String> methParams,
+                       List<String> methPrmTypes, String method, boolean isCallbackMethod, String callbackType,
+                       boolean isStructMethod) {
+
                checkAndWriteEnumTypeJavaSkeleton(methParams, methPrmTypes);
                Map<Integer,String> mapStubParam = null;
                if (isCallbackMethod)
@@ -1230,6 +1602,8 @@ public class IoTCompiler {
                        print(intDecl.getMethodId(method) + "(");
                } else if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) {   // Enum type
                        checkAndWriteEnumRetTypeJavaSkeleton(retType, intDecl.getMethodId(method));
+               } else if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) { // Struct type
+                       print(retType + " retStruct = " + intDecl.getMethodId(method) + "(");
                } else { // We do have a return value
                        print("Object retObj = " + intDecl.getMethodId(method) + "(");
                }
@@ -1239,18 +1613,28 @@ public class IoTCompiler {
                                print(mapStubParam.get(i));     // Get the callback parameter
                        } else if (isEnumClass(getSimpleType(methPrmTypes.get(i)))) { // Enum class
                                print(getEnumParam(methPrmTypes.get(i), methParams.get(i), i));
+                       } else if (isStructClass(getSimpleType(methPrmTypes.get(i)))) {
+                               print("paramStruct" + i);
                        } else {
                                String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
-                               print("(" + prmType + ") paramObj[" + i + "]");
+                               if (isStructMethod)
+                                       print("(" + prmType + ") paramObj[offset" + i + "]");
+                               else
+                                       print("(" + prmType + ") paramObj[" + i + "]");
                        }
                        if (i != methParams.size() - 1)
                                print(", ");
                }
                println(");");
                if (!retType.equals("void")) {
-                       if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) // Enum type
+                       if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) // Enum type
                                checkAndWriteEnumRetConvJavaSkeleton(retType);
-                       println("rmiObj.sendReturnObj(retObj);");
+                               println("rmiObj.sendReturnObj(retObj);");
+                       } else if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) { // Struct type
+                               writeStructReturnJavaSkeleton(getSimpleArrayType(getSimpleType(retType)), retType);
+                               println("rmiObj.sendReturnObj(retCls, retObj);");
+                       } else
+                               println("rmiObj.sendReturnObj(retObj);");
                }
                if (isCallbackMethod) { // Catch exception if this is callback
                        println("} catch(Exception ex) {");
@@ -1262,42 +1646,336 @@ public class IoTCompiler {
 
 
        /**
-        * HELPER: writeMethodHelperJavaSkeleton() writes the method helper of the skeleton class
+        * HELPER: writeMethodHelperStructJavaSkeleton() writes the struct in skeleton
         */
-       private void writeMethodHelperJavaSkeleton(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
-
-               // Use this set to handle two same methodIds
-               Set<String> uniqueMethodIds = new HashSet<String>();
-               for (String method : methods) {
+       private void writeMethodHelperStructJavaSkeleton(InterfaceDecl intDecl, List<String> methParams,
+                       List<String> methPrmTypes, String method, Set<String> callbackClasses) {
 
-                       List<String> methParams = intDecl.getMethodParams(method);
-                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
-                       String methodId = intDecl.getMethodId(method);
-                       print("public void ___");
-                       String helperMethod = methodId;
-                       if (uniqueMethodIds.contains(methodId))
-                               helperMethod = helperMethod + intDecl.getMethodNumId(method);
-                       else
-                               uniqueMethodIds.add(methodId);
-                       // Check if this is "void"
-                       String retType = intDecl.getMethodType(method);
-                       if (retType.equals("void"))
-                               println(helperMethod + "() {");
-                       else
-                               println(helperMethod + "() throws IOException {");
-                       // Now, write the helper body of skeleton!
-                       writeStdMethodHelperBodyJavaSkeleton(intDecl, methParams, methPrmTypes, method, callbackClasses);
-                       println("}\n");
+               // Generate array of parameter objects
+               boolean isCallbackMethod = false;
+               String callbackType = null;
+               print("int paramLen = ");
+               writeLengthStructParamClassSkeleton(methParams, methPrmTypes, method, intDecl);
+               println(";");
+               println("Class<?>[] paramCls = new Class<?>[paramLen];");
+               println("Class<?>[] paramClsGen = new Class<?>[paramLen];");
+               // Iterate again over the parameters
+               for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getGenericType(paramType);
+                       if (isStructClass(simpleType)) {
+                               writeStructMembersJavaSkeleton(simpleType, paramType, param, method, intDecl, i);
+                       } else {
+                               String prmType = returnGenericCallbackType(methPrmTypes.get(i));
+                               if (callbackClasses.contains(prmType)) {
+                                       isCallbackMethod = true;
+                                       callbackType = prmType;
+                                       println("paramCls[pos] = int.class;");
+                                       println("paramClsGen[pos++] = null;");
+                               } else {        // Generate normal classes if it's not a callback object
+                                       String paramTypeOth = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
+                                       println("paramCls[pos] = " + getSimpleType(getEnumType(paramTypeOth)) + ".class;");
+                                       print("paramClsGen[pos++] = ");
+                                       String prmTypeOth = methPrmTypes.get(i);
+                                       if (getParamCategory(prmTypeOth) == ParamCategory.NONPRIMITIVES)
+                                               println(getTypeOfGeneric(prmType)[0] + ".class;");
+                                       else
+                                               println("null;");
+                               }
+                       }
                }
+               println("Object[] paramObj = rmiObj.getMethodParams(paramCls, paramClsGen);");
+               writeStructMembersInitJavaSkeleton(intDecl, methParams, methPrmTypes, method);
+               // Write the return value part
+               writeMethodHelperReturnJavaSkeleton(intDecl, methParams, methPrmTypes, method, isCallbackMethod, callbackType, true);
        }
 
 
        /**
-        * HELPER: writeJavaMethodPermission() writes permission checks in skeleton
+        * HELPER: writeStdMethodHelperBodyJavaSkeleton() writes the standard method body helper in the skeleton class
         */
-       private void writeJavaMethodPermission(String intface) {
+       private void writeStdMethodHelperBodyJavaSkeleton(InterfaceDecl intDecl, List<String> methParams,
+                       List<String> methPrmTypes, String method, Set<String> callbackClasses) {
 
-               // Get all the different stubs
+               // Generate array of parameter objects
+               boolean isCallbackMethod = false;
+               String callbackType = null;
+               print("Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { ");
+               for (int i = 0; i < methParams.size(); i++) {
+
+                       String paramType = returnGenericCallbackType(methPrmTypes.get(i));
+                       if (callbackClasses.contains(paramType)) {
+                               isCallbackMethod = true;
+                               callbackType = paramType;
+                               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(getEnumType(prmType)) + ".class");
+                       }
+                       if (i != methParams.size() - 1)
+                               print(", ");
+               }
+               println(" }, ");
+               // Generate generic class if it's a generic type.. null otherwise
+               print("new Class<?>[] { ");
+               for (int i = 0; i < methParams.size(); i++) {
+                       String prmType = methPrmTypes.get(i);
+                       if (getParamCategory(prmType) == ParamCategory.NONPRIMITIVES)
+                               print(getTypeOfGeneric(prmType)[0] + ".class");
+                       else
+                               print("null");
+                       if (i != methParams.size() - 1)
+                               print(", ");
+               }
+               println(" });");
+               // Write the return value part
+               writeMethodHelperReturnJavaSkeleton(intDecl, methParams, methPrmTypes, method, isCallbackMethod, callbackType, false);
+       }
+
+
+       /**
+        * HELPER: writeMethodHelperJavaSkeleton() writes the method helper of the skeleton class
+        */
+       private void writeMethodHelperJavaSkeleton(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
+
+               // Use this set to handle two same methodIds
+               Set<String> uniqueMethodIds = new HashSet<String>();
+               for (String method : methods) {
+
+                       List<String> methParams = intDecl.getMethodParams(method);
+                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                       if (isStructPresent(methParams, methPrmTypes)) {        // Treat struct differently
+                               String methodId = intDecl.getMethodId(method);
+                               print("public void ___");
+                               String helperMethod = methodId;
+                               if (uniqueMethodIds.contains(methodId))
+                                       helperMethod = helperMethod + intDecl.getMethodNumId(method);
+                               else
+                                       uniqueMethodIds.add(methodId);
+                               String retType = intDecl.getMethodType(method);
+                               print(helperMethod + "(");
+                               boolean begin = true;
+                               for (int i = 0; i < methParams.size(); i++) { // Print size variables
+                                       String paramType = methPrmTypes.get(i);
+                                       String param = methParams.get(i);
+                                       String simpleType = getSimpleType(paramType);
+                                       if (isStructClass(simpleType)) {
+                                               if (!begin) {   // Generate comma for not the beginning variable
+                                                       print(", "); begin = false;
+                                               }
+                                               int methodNumId = intDecl.getMethodNumId(method);
+                                               print("int struct" + methodNumId + "Size" + i);
+                                       }
+                               }
+                               // Check if this is "void"
+                               if (retType.equals("void"))
+                                       println(") {");
+                               else
+                                       println(") throws IOException {");
+                               writeMethodHelperStructJavaSkeleton(intDecl, methParams, methPrmTypes, method, callbackClasses);
+                               println("}\n");
+                       } else {
+                               String methodId = intDecl.getMethodId(method);
+                               print("public void ___");
+                               String helperMethod = methodId;
+                               if (uniqueMethodIds.contains(methodId))
+                                       helperMethod = helperMethod + intDecl.getMethodNumId(method);
+                               else
+                                       uniqueMethodIds.add(methodId);
+                               // Check if this is "void"
+                               String retType = intDecl.getMethodType(method);
+                               if (retType.equals("void"))
+                                       println(helperMethod + "() {");
+                               else
+                                       println(helperMethod + "() throws IOException {");
+                               // Now, write the helper body of skeleton!
+                               writeStdMethodHelperBodyJavaSkeleton(intDecl, methParams, methPrmTypes, method, callbackClasses);
+                               println("}\n");
+                       }
+               }
+               // Write method helper for structs
+               writeMethodHelperStructSetupJavaSkeleton(methods, intDecl);
+       }
+
+
+       /**
+        * HELPER: writeMethodHelperStructSetupJavaSkeleton() writes the method helper of struct setup in skeleton class
+        */
+       private void writeMethodHelperStructSetupJavaSkeleton(Collection<String> methods, 
+                       InterfaceDecl intDecl) {
+
+               // Use this set to handle two same methodIds
+               for (String method : methods) {
+
+                       List<String> methParams = intDecl.getMethodParams(method);
+                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                       // Check for params with structs
+                       for (int i = 0; i < methParams.size(); i++) {
+                               String paramType = methPrmTypes.get(i);
+                               String param = methParams.get(i);
+                               String simpleType = getSimpleType(paramType);
+                               if (isStructClass(simpleType)) {
+                                       int methodNumId = intDecl.getMethodNumId(method);
+                                       print("public int ___");
+                                       String helperMethod = methodNumId + "struct" + i;
+                                       println(helperMethod + "() {");
+                                       // Now, write the helper body of skeleton!
+                                       println("Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null });");
+                                       println("return (int) paramObj[0];");
+                                       println("}\n");
+                               }
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: writeMethodHelperStructSetupJavaCallbackSkeleton() writes the method helper of struct setup in callback skeleton class
+        */
+       private void writeMethodHelperStructSetupJavaCallbackSkeleton(Collection<String> methods, 
+                       InterfaceDecl intDecl) {
+
+               // Use this set to handle two same methodIds
+               for (String method : methods) {
+
+                       List<String> methParams = intDecl.getMethodParams(method);
+                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                       // Check for params with structs
+                       for (int i = 0; i < methParams.size(); i++) {
+                               String paramType = methPrmTypes.get(i);
+                               String param = methParams.get(i);
+                               String simpleType = getSimpleType(paramType);
+                               if (isStructClass(simpleType)) {
+                                       int methodNumId = intDecl.getMethodNumId(method);
+                                       print("public int ___");
+                                       String helperMethod = methodNumId + "struct" + i;
+                                       println(helperMethod + "(IoTRMIObject rmiObj) {");
+                                       // Now, write the helper body of skeleton!
+                                       println("Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null });");
+                                       println("return (int) paramObj[0];");
+                                       println("}\n");
+                               }
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: writeCountVarStructSkeleton() writes counter variable of struct for skeleton
+        */
+       private void writeCountVarStructSkeleton(Collection<String> methods, InterfaceDecl intDecl) {
+
+               // Use this set to handle two same methodIds
+               for (String method : methods) {
+
+                       List<String> methParams = intDecl.getMethodParams(method);
+                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                       // Check for params with structs
+                       for (int i = 0; i < methParams.size(); i++) {
+                               String paramType = methPrmTypes.get(i);
+                               String param = methParams.get(i);
+                               String simpleType = getSimpleType(paramType);
+                               if (isStructClass(simpleType)) {
+                                       int methodNumId = intDecl.getMethodNumId(method);
+                                       println("int struct" + methodNumId + "Size" + i + " = 0;");
+                               }
+                       }
+               }
+       }
+       
+       
+       /**
+        * HELPER: writeInputCountVarStructSkeleton() writes input counter variable of struct for skeleton
+        */
+       private boolean writeInputCountVarStructSkeleton(String method, InterfaceDecl intDecl) {
+
+               List<String> methParams = intDecl.getMethodParams(method);
+               List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+               boolean structExist = false;
+               // Check for params with structs
+               for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getSimpleType(paramType);
+                       boolean begin = true;
+                       if (isStructClass(simpleType)) {
+                               structExist = true;
+                               if (!begin) {
+                                       print(", "); begin = false;
+                               }
+                               int methodNumId = intDecl.getMethodNumId(method);
+                               print("struct" + methodNumId + "Size" + i);
+                       }
+               }
+               return structExist;
+       }
+
+
+       /**
+        * HELPER: writeMethodCallStructSkeleton() writes method call for wait invoke in skeleton
+        */
+       private void writeMethodCallStructSkeleton(Collection<String> methods, InterfaceDecl intDecl) {
+
+               // Use this set to handle two same methodIds
+               for (String method : methods) {
+
+                       List<String> methParams = intDecl.getMethodParams(method);
+                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                       // Check for params with structs
+                       for (int i = 0; i < methParams.size(); i++) {
+                               String paramType = methPrmTypes.get(i);
+                               String param = methParams.get(i);
+                               String simpleType = getSimpleType(paramType);
+                               if (isStructClass(simpleType)) {
+                                       int methodNumId = intDecl.getMethodNumId(method);
+                                       print("case ");
+                                       String helperMethod = methodNumId + "struct" + i;
+                                       String tempVar = "struct" + methodNumId + "Size" + i;
+                                       print(intDecl.getHelperMethodNumId(helperMethod) + ": ");
+                                       print(tempVar + " = ___");
+                                       println(helperMethod + "(); break;");
+                               }
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: writeMethodCallStructCallbackSkeleton() writes method call for wait invoke in skeleton
+        */
+       private void writeMethodCallStructCallbackSkeleton(Collection<String> methods, InterfaceDecl intDecl) {
+
+               // Use this set to handle two same methodIds
+               for (String method : methods) {
+
+                       List<String> methParams = intDecl.getMethodParams(method);
+                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                       // Check for params with structs
+                       for (int i = 0; i < methParams.size(); i++) {
+                               String paramType = methPrmTypes.get(i);
+                               String param = methParams.get(i);
+                               String simpleType = getSimpleType(paramType);
+                               if (isStructClass(simpleType)) {
+                                       int methodNumId = intDecl.getMethodNumId(method);
+                                       print("case ");
+                                       String helperMethod = methodNumId + "struct" + i;
+                                       String tempVar = "struct" + methodNumId + "Size" + i;
+                                       print(intDecl.getHelperMethodNumId(helperMethod) + ": ");
+                                       print(tempVar + " = ___");
+                                       println(helperMethod + "(rmiObj); break;");
+                               }
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: writeJavaMethodPermission() writes permission checks in skeleton
+        */
+       private void writeJavaMethodPermission(String intface) {
+
+               // Get all the different stubs
                Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
                for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
                        String newIntface = intMeth.getKey();
@@ -1306,10 +1984,10 @@ public class IoTCompiler {
                        println("if (!set" + newObjectId + "Allowed.contains(methodId)) {");
                        println("throw new Error(\"Object with object Id: \" + _objectId + \"  is not allowed to access method: \" + methodId);");
                        println("}");
+                       println("}");
                        println("else {");
                        println("throw new Error(\"Object Id: \" + _objectId + \" not recognized!\");");
                        println("}");
-                       println("}");
                }
        }
 
@@ -1323,6 +2001,7 @@ public class IoTCompiler {
                Set<String> uniqueMethodIds = new HashSet<String>();
                println("private void ___waitRequestInvokeMethod() throws IOException {");
                // Write variables here if we have callbacks or enums or structs
+               writeCountVarStructSkeleton(methods, intDecl);
                println("while (true) {");
                println("rmiObj.getMethodBytes();");
                println("int _objectId = rmiObj.getObjectId();");
@@ -1340,7 +2019,9 @@ public class IoTCompiler {
                                helperMethod = helperMethod + methodNumId;
                        else
                                uniqueMethodIds.add(methodId);
-                       println(helperMethod + "(); break;");
+                       print(helperMethod + "(");
+                       writeInputCountVarStructSkeleton(method, intDecl);
+                       println("); break;");
                }
                String method = "___initCallBack()";
                // Print case -9999 (callback handler) if callback exists
@@ -1348,6 +2029,7 @@ public class IoTCompiler {
                        int methodId = intDecl.getHelperMethodNumId(method);
                        println("case " + methodId + ": ___regCB(); break;");
                }
+               writeMethodCallStructSkeleton(methods, intDecl);
                println("default: ");
                println("throw new Error(\"Method Id \" + methodId + \" not recognized!\");");
                println("}");
@@ -1439,28 +2121,62 @@ public class IoTCompiler {
 
                        List<String> methParams = intDecl.getMethodParams(method);
                        List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
-                       String methodId = intDecl.getMethodId(method);
-                       print("public void ___");
-                       String helperMethod = methodId;
-                       if (uniqueMethodIds.contains(methodId))
-                               helperMethod = helperMethod + intDecl.getMethodNumId(method);
-                       else
-                               uniqueMethodIds.add(methodId);
-                       // Check if this is "void"
-                       String retType = intDecl.getMethodType(method);
-                       if (retType.equals("void"))
-                               println(helperMethod + "(IoTRMIObject rmiObj) {");
-                       else
-                               println(helperMethod + "(IoTRMIObject rmiObj) throws IOException {");
-                       // Now, write the helper body of skeleton!
-                       writeStdMethodHelperBodyJavaSkeleton(intDecl, methParams, methPrmTypes, method, callbackClasses);
-                       println("}\n");
+                       if (isStructPresent(methParams, methPrmTypes)) {        // Treat struct differently
+                               String methodId = intDecl.getMethodId(method);
+                               print("public void ___");
+                               String helperMethod = methodId;
+                               if (uniqueMethodIds.contains(methodId))
+                                       helperMethod = helperMethod + intDecl.getMethodNumId(method);
+                               else
+                                       uniqueMethodIds.add(methodId);
+                               String retType = intDecl.getMethodType(method);
+                               print(helperMethod + "(");
+                               boolean begin = true;
+                               for (int i = 0; i < methParams.size(); i++) { // Print size variables
+                                       String paramType = methPrmTypes.get(i);
+                                       String param = methParams.get(i);
+                                       String simpleType = getSimpleType(paramType);
+                                       if (isStructClass(simpleType)) {
+                                               if (!begin) {   // Generate comma for not the beginning variable
+                                                       print(", "); begin = false;
+                                               }
+                                               int methodNumId = intDecl.getMethodNumId(method);
+                                               print("int struct" + methodNumId + "Size" + i);
+                                       }
+                               }
+                               // Check if this is "void"
+                               if (retType.equals("void"))
+                                       println(", IoTRMIObject rmiObj) {");
+                               else
+                                       println(", IoTRMIObject rmiObj) throws IOException {");
+                               writeMethodHelperStructJavaSkeleton(intDecl, methParams, methPrmTypes, method, callbackClasses);
+                               println("}\n");
+                       } else {
+                               String methodId = intDecl.getMethodId(method);
+                               print("public void ___");
+                               String helperMethod = methodId;
+                               if (uniqueMethodIds.contains(methodId))
+                                       helperMethod = helperMethod + intDecl.getMethodNumId(method);
+                               else
+                                       uniqueMethodIds.add(methodId);
+                               // Check if this is "void"
+                               String retType = intDecl.getMethodType(method);
+                               if (retType.equals("void"))
+                                       println(helperMethod + "(IoTRMIObject rmiObj) {");
+                               else
+                                       println(helperMethod + "(IoTRMIObject rmiObj) throws IOException {");
+                               // Now, write the helper body of skeleton!
+                               writeStdMethodHelperBodyJavaSkeleton(intDecl, methParams, methPrmTypes, method, callbackClasses);
+                               println("}\n");
+                       }
                }
+               // Write method helper for structs
+               writeMethodHelperStructSetupJavaCallbackSkeleton(methods, intDecl);
        }
 
 
        /**
-        * HELPER: writeJavaCallbackWaitRequestInvokeMethod() writes the main loop of the skeleton class
+        * HELPER: writeJavaCallbackWaitRequestInvokeMethod() writes the request invoke method of the callback skeleton class
         */
        private void writeJavaCallbackWaitRequestInvokeMethod(Collection<String> methods, InterfaceDecl intDecl, boolean callbackExist) {
 
@@ -1468,6 +2184,8 @@ public class IoTCompiler {
                Set<String> uniqueMethodIds = new HashSet<String>();
                println("public void invokeMethod(IoTRMIObject rmiObj) throws IOException {");
                // Write variables here if we have callbacks or enums or structs
+               writeCountVarStructSkeleton(methods, intDecl);
+               // Write variables here if we have callbacks or enums or structs
                println("int methodId = rmiObj.getMethodId();");
                // TODO: code the permission check here!
                println("switch (methodId) {");
@@ -1481,7 +2199,11 @@ public class IoTCompiler {
                                helperMethod = helperMethod + methodNumId;
                        else
                                uniqueMethodIds.add(methodId);
-                       println(helperMethod + "(rmiObj); break;");
+                       print(helperMethod + "(");
+                       if (writeInputCountVarStructSkeleton(method, intDecl))
+                               println(", rmiObj); break;");
+                       else
+                               println("rmiObj); break;");
                }
                String method = "___initCallBack()";
                // Print case -9999 (callback handler) if callback exists
@@ -1489,6 +2211,7 @@ public class IoTCompiler {
                        int methodId = intDecl.getHelperMethodNumId(method);
                        println("case " + methodId + ": ___regCB(rmiObj); break;");
                }
+               writeMethodCallStructCallbackSkeleton(methods, intDecl);
                println("default: ");
                println("throw new Error(\"Method Id \" + methodId + \" not recognized!\");");
                println("}");
@@ -1540,7 +2263,7 @@ public class IoTCompiler {
 
 
        /**
-        * HELPER: writeMethodCplusLocalInterface() writes the method of the interface
+        * HELPER: writeMethodCplusLocalInterface() writes the method of the local interface
         */
        private void writeMethodCplusLocalInterface(Collection<String> methods, InterfaceDecl intDecl) {
 
@@ -1705,11 +2428,6 @@ public class IoTCompiler {
                        Set<String> includeClasses = getIncludeClasses(methods, intDecl, intface, true);
                        printIncludeStatements(includeClasses); println("");
                        println("using namespace std;\n");
-                       // Write enum if any...
-                       //EnumDecl enumDecl = (EnumDecl) decHandler.getEnumDecl(intface);
-                       //writeEnumCplus(enumDecl);
-                       // Write struct if any...
-                       //StructDecl structDecl = (StructDecl) decHandler.getStructDecl(intface);
                        //writeStructCplus(structDecl);
                        println("class " + intface); println("{");
                        println("public:");
@@ -1768,7 +2486,7 @@ public class IoTCompiler {
 
 
        /**
-        * HELPER: writeMethodCplusStub() writes the method of the stub
+        * HELPER: writeMethodCplusStub() writes the methods of the stub
         */
        private void writeMethodCplusStub(Collection<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
 
@@ -1948,55 +2666,282 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: checkAndWriteStructSetupCplusStub() writes the struct type setup
+        */
+       private void checkAndWriteStructSetupCplusStub(List<String> methParams, List<String> methPrmTypes, 
+                       InterfaceDecl intDecl, String method) {
+               
+               // Iterate and find struct declarations
+               for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getSimpleType(paramType);
+                       if (isStructClass(simpleType)) {
+                       // Check if this is enum type
+                               println("int numParam" + i + " = 1;");
+                               int methodNumId = intDecl.getMethodNumId(method);
+                               String helperMethod = methodNumId + "struct" + i;
+                               println("int methodIdStruct" + i + " = " + intDecl.getHelperMethodNumId(helperMethod) + ";");
+                               println("string retTypeStruct" + i + " = \"void\";");
+                               println("string paramClsStruct" + i + "[] = { \"int\" };");
+                               print("int structLen" + i + " = ");
+                               if (isArrayOrList(param, paramType)) {  // An array
+                                       println(getSimpleArrayType(param) + ".size();");
+                               } else {        // Just one element
+                                       println("1;");
+                               }
+                               println("void* paramObjStruct" + i + "[] = { &structLen" + i + " };");
+                               println("void* retStructLen" + i + " = NULL;");
+                               println("rmiCall->remoteCall(objectId, methodIdStruct" + i + 
+                                               ", retTypeStruct" + i + ", paramClsStruct" + i + ", paramObjStruct" + i + 
+                                               ", numParam" + i + ", retStructLen" + i + ");\n");
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: writeLengthStructParamClassCplusStub() writes lengths of params
+        */
+       private void writeLengthStructParamClassCplusStub(List<String> methParams, List<String> methPrmTypes) {
+
+               // Iterate and find struct declarations - count number of params
+               for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getGenericType(paramType);
+                       if (isStructClass(simpleType)) {
+                               int members = getNumOfMembers(simpleType);
+                               if (isArrayOrList(param, paramType)) {                  // An array
+                                       String structLen = param + ".size()";
+                                       print(members + "*" + structLen);
+                               } else
+                                       print(Integer.toString(members));
+                       } else
+                               print("1");
+                       if (i != methParams.size() - 1) {
+                               print("+");
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: writeStructMembersCplusStub() writes member parameters of struct
+        */
+       private void writeStructMembersCplusStub(String simpleType, String paramType, String param) {
+
+               // Get the struct declaration for this struct and generate initialization code
+               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(param, paramType)) {  // An array or list
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmTypeC = checkAndGetCplusType(memTypes.get(i));
+                               String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
+                               println("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               print("paramObj[pos++] = &" + param + "[i].");
+                               print(getSimpleIdentifier(members.get(i)));
+                               println(";");
+                       }
+                       println("}");
+               } else {        // Just one struct element
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmTypeC = checkAndGetCplusType(memTypes.get(i));
+                               String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
+                               println("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               print("paramObj[pos++] = &" + param + ".");
+                               print(getSimpleIdentifier(members.get(i)));
+                               println(";");
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: writeStructParamClassCplusStub() writes member parameters of struct
+        */
+       private void writeStructParamClassCplusStub(List<String> methParams, List<String> methPrmTypes) {
+
+               print("int numParam = ");
+               writeLengthStructParamClassCplusStub(methParams, methPrmTypes);
+               println(";");
+               println("void* paramObj[numParam];");
+               println("string paramCls[numParam];");
+               println("int pos = 0;");
+               // Iterate again over the parameters
+               for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getGenericType(paramType);
+                       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)) + "\";");
+                               print("paramObj[pos++] = &");
+                               print(getEnumParam(methPrmTypes.get(i), getSimpleIdentifier(methParams.get(i)), i));
+                               println(";");
+                       }
+               }
+               
+       }
+
+
+       /**
+        * HELPER: writeStructRetMembersCplusStub() writes member parameters of struct for return statement
+        */
+       private void writeStructRetMembersCplusStub(String simpleType, String retType) {
+
+               // Get the struct declaration for this struct and generate initialization code
+               StructDecl structDecl = getStructDecl(simpleType);
+               List<String> memTypes = structDecl.getMemberTypes(simpleType);
+               List<String> members = structDecl.getMembers(simpleType);
+               if (isArrayOrList(retType, retType)) {  // An array or list
+                       println("for(int i = 0; i < retLen; i++) {");
+               }
+               if (isArrayOrList(retType, retType)) {  // An array or list
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               print("structRet[i]." + getSimpleIdentifier(members.get(i)));
+                               println(" = retParam" + i + "[i];");
+                       }
+                       println("}");
+               } else {        // Just one struct element
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmType = checkAndGetArray(memTypes.get(i), members.get(i));
+                               print("structRet." + getSimpleIdentifier(members.get(i)));
+                               println(" = retParam" + i + ";");
+                       }
+               }
+               println("return structRet;");
+       }
+
+
+       /**
+        * HELPER: writeStructReturnCplusStub() writes member parameters of struct for return statement
+        */
+       private void writeStructReturnCplusStub(String simpleType, String retType) {
+
+               // Minimum retLen is 1 if this is a single struct object
+               println("int retLen = 0;");
+               println("void* retLenObj = { &retLen };");
+               // Handle the returned struct!!!
+               println("rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retLenObj);");
+               int numMem = getNumOfMembers(simpleType);
+               println("int numRet = " + numMem + "*retLen;");
+               println("string retCls[numRet];");
+               println("void* retObj[numRet];");
+               StructDecl structDecl = getStructDecl(simpleType);
+               List<String> memTypes = structDecl.getMemberTypes(simpleType);
+               List<String> members = structDecl.getMembers(simpleType);
+               // Set up variables
+               if (isArrayOrList(retType, retType)) {  // 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)) + " retParam" + i + "[retLen];");
+                       }
+               } 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)) + " retParam" + i + ";");
+                       }
+               }
+               println("int retPos = 0;");
+               // Get the struct declaration for this struct and generate initialization code
+               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)) + "\";");
+                               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)) + "\";");
+                               println("retObj[retPos++] = &retParam" + i + ";");
+                       }
+               }
+               println("rmiCall->getStructObjects(retCls, numRet, retObj);");
+               if (isArrayOrList(retType, retType)) {  // An array or list
+                       println("vector<" + simpleType + "> structRet(retLen);");
+               } else
+                       println(simpleType + " structRet;");
+               writeStructRetMembersCplusStub(simpleType, retType);
+       }
+
+
        /**
         * HELPER: writeStdMethodBodyCplusStub() writes the standard method body in the stub class
         */
        private void writeStdMethodBodyCplusStub(InterfaceDecl intDecl, List<String> methParams,
                        List<String> methPrmTypes, String method) {
 
-               println("int numParam = " + methParams.size() + ";");
+               checkAndWriteStructSetupCplusStub(methParams, methPrmTypes, intDecl, method);
                println("int methodId = " + intDecl.getMethodNumId(method) + ";");
                String retType = intDecl.getMethodType(method);
                String retTypeC = checkAndGetCplusType(retType);
-               println("string retType = \"" + checkAndGetCplusArrayType(getEnumType(retTypeC)) + "\";");
+               println("string retType = \"" + checkAndGetCplusArrayType(getStructType(getEnumType(retTypeC))) + "\";");
                // Generate array of parameter types
-               print("string paramCls[] = { ");
-               for (int i = 0; i < methParams.size(); i++) {
-                       String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i));
-                       String paramType = checkAndGetCplusArrayType(paramTypeC, methParams.get(i));
-                       print("\"" + getEnumType(paramType) + "\"");
-                       // Check if this is the last element (don't print a comma)
-                       if (i != methParams.size() - 1) {
-                               print(", ");
+               if (isStructPresent(methParams, methPrmTypes)) {
+                       writeStructParamClassCplusStub(methParams, methPrmTypes);
+               } else {
+                       println("int numParam = " + methParams.size() + ";");
+                       print("string paramCls[] = { ");
+                       for (int i = 0; i < methParams.size(); i++) {
+                               String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i));
+                               String paramType = checkAndGetCplusArrayType(paramTypeC, methParams.get(i));
+                               print("\"" + getEnumType(paramType) + "\"");
+                               // 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++) {
-                       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(", ");
+                       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));
+                               // Check if this is the last element (don't print a comma)
+                               if (i != methParams.size() - 1) {
+                                       print(", ");
+                               }
                        }
+                       println(" };");
                }
-               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.ENUM) {
-                               checkAndWriteEnumRetTypeCplusStub(retType);
+                       // Generate array of parameter types
+                       if (isStructClass(getGenericType(getSimpleArrayType(retType)))) {
+                               writeStructReturnCplusStub(getGenericType(getSimpleArrayType(retType)), retType);
                        } else {
-                               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;");
+                       // Check if the return value NONPRIMITIVES
+                               if (getParamCategory(retType) == ParamCategory.ENUM) {
+                                       checkAndWriteEnumRetTypeCplusStub(retType);
+                               } else {
+                                       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;");
+                               }
                        }
                }
        }
@@ -2141,7 +3086,7 @@ public class IoTCompiler {
 
 
        /**
-        * HELPER: writeInitCallbackSendInfoCplusStub() writes the initialization of callback
+        * HELPER: writeInitCallbackSendInfoCplusStub() writes the initialization (send info part) of callback
         */
        private void writeInitCallbackSendInfoCplusStub(InterfaceDecl intDecl) {
 
@@ -2589,6 +3534,73 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: writeMethodHelperReturnCplusSkeleton() writes the return statement part in skeleton
+        */
+       private void writeMethodInputParameters(List<String> methParams, List<String> methPrmTypes, 
+                       Set<String> callbackClasses, String methodId) {
+
+               print(methodId + "(");
+               for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = returnGenericCallbackType(methPrmTypes.get(i));
+                       if (callbackClasses.contains(paramType))
+                               print("stub" + i);
+                       else if (isEnumClass(getSimpleType(paramType))) // Check if this is enum type
+                               print("paramEnum" + i);
+                       else if (isStructClass(getSimpleType(paramType)))       // Struct type
+                               print("paramStruct" + i);
+                       else
+                               print(getSimpleIdentifier(methParams.get(i)));
+                       if (i != methParams.size() - 1) {
+                               print(", ");
+                       }
+               }
+               println(");");
+       }
+
+
+       /**
+        * HELPER: writeMethodHelperReturnCplusSkeleton() writes the return statement part in skeleton
+        */
+       private void writeMethodHelperReturnCplusSkeleton(InterfaceDecl intDecl, List<String> methParams,
+                       List<String> methPrmTypes, String method, boolean isCallbackMethod, String callbackType,
+                       String methodId, Set<String> callbackClasses) {
+
+               println("rmiObj->getMethodParams(paramCls, numParam, paramObj);");
+               if (isCallbackMethod)
+                       writeCallbackCplusStubGeneration(methParams, methPrmTypes, callbackType);
+               checkAndWriteEnumTypeCplusSkeleton(methParams, methPrmTypes);
+               writeStructMembersInitCplusSkeleton(intDecl, methParams, methPrmTypes, method);
+               // Check if this is "void"
+               String retType = intDecl.getMethodType(method);
+               // Check if this is "void"
+               if (retType.equals("void")) {
+                       writeMethodInputParameters(methParams, methPrmTypes, callbackClasses, methodId);
+               } else { // We do have a return value
+                       if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) // Enum type
+                               print(checkAndGetCplusType(retType) + " retEnum = ");
+                       else if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
+                               print(checkAndGetCplusType(retType) + " retStruct = ");
+                       else
+                               print(checkAndGetCplusType(retType) + " retVal = ");
+                       writeMethodInputParameters(methParams, methPrmTypes, callbackClasses, methodId);
+                       checkAndWriteEnumRetTypeCplusSkeleton(retType);
+                       if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
+                               writeStructReturnCplusSkeleton(getSimpleArrayType(getSimpleType(retType)), retType);
+                       if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) // Enum type
+                               println("void* retObj = &retEnumInt;");
+                       else
+                               if (!isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
+                                       println("void* retObj = &retVal;");
+                       String retTypeC = checkAndGetCplusType(retType);
+                       if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
+                               println("rmiObj->sendReturnObj(retObj, retCls, numRetObj);");
+                       else
+                               println("rmiObj->sendReturnObj(retObj, \"" + getEnumType(checkAndGetCplusArrayType(retTypeC)) + "\");");
+               }
+       }
+
+
        /**
         * HELPER: writeStdMethodHelperBodyCplusSkeleton() writes the standard method body helper in the skeleton class
         */
@@ -2627,7 +3639,8 @@ public class IoTCompiler {
                                        println("vector<int> paramEnumInt" + i + ";");
                                } else {
                                        String methParamComplete = checkAndGetCplusArray(methPrmType, methParams.get(i));
-                                       println(methParamComplete + ";");
+                                       //println(methParamComplete + " = " + generateCplusInitializer(methPrmType) + ";");
+                    println(methParamComplete + ";");
                                }
                        }
                }
@@ -2646,54 +3659,197 @@ public class IoTCompiler {
                        }
                }
                println(" };");
-               println("rmiObj->getMethodParams(paramCls, numParam, paramObj);");
-               if (isCallbackMethod)
-                       writeCallbackCplusStubGeneration(methParams, methPrmTypes, callbackType);
-               checkAndWriteEnumTypeCplusSkeleton(methParams, methPrmTypes);
-               String retType = intDecl.getMethodType(method);
-               // Check if this is "void"
-               if (retType.equals("void")) {
-                       print(methodId + "(");
-                       for (int i = 0; i < methParams.size(); i++) {
-                               String paramType = returnGenericCallbackType(methPrmTypes.get(i));
-                               if (callbackClasses.contains(paramType))
-                                       print("stub" + i);
-                               else if (isEnumClass(getSimpleType(paramType))) // Check if this is enum type
-                                       print("paramEnum" + i);
-                               else
-                                       print(getSimpleIdentifier(methParams.get(i)));
-                               if (i != methParams.size() - 1) {
-                                       print(", ");
+               // Write the return value part
+               writeMethodHelperReturnCplusSkeleton(intDecl, methParams, methPrmTypes, method, isCallbackMethod, 
+                       callbackType, methodId, callbackClasses);
+       }
+
+
+       /**
+        * HELPER: writeStructMembersCplusSkeleton() writes member parameters of struct
+        */
+       private void writeStructMembersCplusSkeleton(String simpleType, String paramType, 
+                       String param, String method, InterfaceDecl intDecl, int iVar) {
+
+               // Get the struct declaration for this struct and generate initialization code
+               StructDecl structDecl = getStructDecl(simpleType);
+               List<String> memTypes = structDecl.getMemberTypes(simpleType);
+               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
+                       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 + "];");
+                       }
+               } 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("int pos = 0;");
+               if (isArrayOrList(param, paramType)) {  // An array or list
+                       println("for(int i = 0; i < retLen; i++) {");
+                       for (int i = 0; i < members.size(); i++) {
+                               String prmTypeC = checkAndGetCplusType(memTypes.get(i));
+                               String prmType = checkAndGetCplusArrayType(prmTypeC, members.get(i));
+                               println("paramCls[pos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               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)) + "\";");
+                               println("paramObj[pos++] = &param" + i + ";");
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: writeStructMembersInitCplusSkeleton() writes member parameters initialization of struct
+        */
+       private void writeStructMembersInitCplusSkeleton(InterfaceDecl intDecl, List<String> methParams,
+                       List<String> methPrmTypes, String method) {
+
+               for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getGenericType(paramType);
+                       if (isStructClass(simpleType)) {
+                               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 + ";");
+                               } 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
+                                       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("}");
+                               } else {        // Just one struct element
+                                       for (int j = 0; j < members.size(); j++) {
+                                               print("paramStruct" + i + "." + getSimpleIdentifier(members.get(j)));
+                                               println(" = param" + j + ";");
+                                       }
                                }
                        }
-                       println(");");
-               } else { // We do have a return value
-                       if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) // Enum type
-                               print(checkAndGetCplusType(retType) + " retEnum = ");
-                       else
-                               print(checkAndGetCplusType(retType) + " retVal = ");
-                       print(methodId + "(");
-                       for (int i = 0; i < methParams.size(); i++) {
-                               String paramType = returnGenericCallbackType(methPrmTypes.get(i));
-                               if (callbackClasses.contains(paramType))
-                                       print("stub" + i);
-                               else if (isEnumClass(getSimpleType(paramType))) // Check if this is enum type
-                                       print("paramEnum" + i);
-                               else
-                                       print(getSimpleIdentifier(methParams.get(i)));
-                               if (i != methParams.size() - 1) {
-                                       print(", ");
+               }
+       }
+
+
+       /**
+        * HELPER: writeStructReturnCplusSkeleton() writes parameters of struct for return statement
+        */
+       private void writeStructReturnCplusSkeleton(String simpleType, String retType) {
+
+               // Minimum retLen is 1 if this is a single struct object
+               if (isArrayOrList(retType, retType))
+                       println("int retLen = retStruct.size();");
+               else    // Just single struct object
+                       println("int retLen = 1;");
+               println("void* retLenObj = &retLen;");
+               println("rmiObj->sendReturnObj(retLenObj, \"int\");");
+               int numMem = getNumOfMembers(simpleType);
+               println("int numRetObj = " + numMem + "*retLen;");
+               println("string retCls[numRetObj];");
+               println("void* retObj[numRetObj];");
+               println("int retPos = 0;");
+               // Get the struct declaration for this struct and generate initialization code
+               StructDecl structDecl = getStructDecl(simpleType);
+               List<String> memTypes = structDecl.getMemberTypes(simpleType);
+               List<String> members = structDecl.getMembers(simpleType);
+               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)) + "\";");
+                               print("retObj[retPos++] = &retStruct[i].");
+                               print(getEnumParam(memTypes.get(i), getSimpleIdentifier(members.get(i)), i));
+                               println(";");
+                       }
+                       println("}");
+               } else {        // Just one struct element
+                       for (int i = 0; i < members.size(); i++) {
+                               String paramTypeC = checkAndGetCplusType(memTypes.get(i));
+                               String prmType = checkAndGetCplusArrayType(paramTypeC, members.get(i));
+                               println("retCls[retPos] = \"" + getSimpleType(getEnumType(prmType)) + "\";");
+                               print("retObj[retPos++] = &retStruct.");
+                               print(getEnumParam(memTypes.get(i), getSimpleIdentifier(members.get(i)), i));
+                               println(";");
+                       }
+               }
+
+       }
+
+
+       /**
+        * HELPER: writeMethodHelperStructCplusSkeleton() writes the struct in skeleton
+        */
+       private void writeMethodHelperStructCplusSkeleton(InterfaceDecl intDecl, List<String> methParams,
+                       List<String> methPrmTypes, String method, String methodId, Set<String> callbackClasses) {
+
+               // Generate array of parameter objects
+               boolean isCallbackMethod = false;
+               String callbackType = null;
+               print("int numParam = ");
+               writeLengthStructParamClassSkeleton(methParams, methPrmTypes, method, intDecl);
+               println(";");
+               println("string paramCls[numParam];");
+               println("void* paramObj[numParam];");
+               // Iterate again over the parameters
+               for (int i = 0; i < methParams.size(); i++) {
+                       String paramType = methPrmTypes.get(i);
+                       String param = methParams.get(i);
+                       String simpleType = getGenericType(paramType);
+                       if (isStructClass(simpleType)) {
+                               writeStructMembersCplusSkeleton(simpleType, paramType, param, method, intDecl, i);
+                       } else {
+                               String prmType = returnGenericCallbackType(methPrmTypes.get(i));
+                               if (callbackClasses.contains(prmType)) {
+                                       isCallbackMethod = true;
+                                       callbackType = paramType;
+                                       writeCallbackCplusNumStubs(methParams, methPrmTypes, callbackType);
+                                       println("paramCls[pos] = \"int\";");
+                                       println("paramObj[pos++] = &numStubs" + i + ";");
+                               } else {        // Generate normal classes if it's not a callback object
+                                       String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i));
+                                       String prmTypeC = checkAndGetCplusArrayType(paramTypeC, methParams.get(i));
+                                       if (isEnumClass(getSimpleType(paramTypeC))) {   // Check if this is enum type
+                                               println("vector<int> paramEnumInt" + i + ";");
+                                       } else {
+                                               String methParamComplete = checkAndGetCplusArray(paramTypeC, methParams.get(i));
+                                               println(methParamComplete + ";");
+                                       }
+                                       println("paramCls[pos] = \"" + getEnumType(prmTypeC) + "\";");
+                                       if (isEnumClass(getSimpleType(paramType)))      // Check if this is enum type
+                                               println("paramObj[pos++] = &paramEnumInt" + i);
+                                       else
+                                               println("paramObj[pos++] = &" + getSimpleIdentifier(methParams.get(i)) + ";");
                                }
                        }
-                       println(");");
-                       checkAndWriteEnumRetTypeCplusSkeleton(retType);
-                       if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) // Enum type
-                               println("void* retObj = &retEnumInt;");
-                       else
-                               println("void* retObj = &retVal;");
-                       String retTypeC = checkAndGetCplusType(retType);
-                       println("rmiObj->sendReturnObj(retObj, \"" + getEnumType(checkAndGetCplusArrayType(retTypeC)) + "\");");
                }
+               // Write the return value part
+               writeMethodHelperReturnCplusSkeleton(intDecl, methParams, methPrmTypes, method, isCallbackMethod, 
+                       callbackType, methodId, callbackClasses);
        }
 
 
@@ -2708,19 +3864,119 @@ public class IoTCompiler {
 
                        List<String> methParams = intDecl.getMethodParams(method);
                        List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
-                       String methodId = intDecl.getMethodId(method);
-                       print("void ___");
-                       String helperMethod = methodId;
-                       if (uniqueMethodIds.contains(methodId))
-                               helperMethod = helperMethod + intDecl.getMethodNumId(method);
-                       else
-                               uniqueMethodIds.add(methodId);
-                       // Check if this is "void"
-                       String retType = intDecl.getMethodType(method);
-                       println(helperMethod + "() {");
-                       // Now, write the helper body of skeleton!
-                       writeStdMethodHelperBodyCplusSkeleton(intDecl, methParams, methPrmTypes, method, methodId, callbackClasses);
-                       println("}\n");
+                       if (isStructPresent(methParams, methPrmTypes)) {        // Treat struct differently
+                               String methodId = intDecl.getMethodId(method);
+                               print("void ___");
+                               String helperMethod = methodId;
+                               if (uniqueMethodIds.contains(methodId))
+                                       helperMethod = helperMethod + intDecl.getMethodNumId(method);
+                               else
+                                       uniqueMethodIds.add(methodId);
+                               String retType = intDecl.getMethodType(method);
+                               print(helperMethod + "(");
+                               boolean begin = true;
+                               for (int i = 0; i < methParams.size(); i++) { // Print size variables
+                                       String paramType = methPrmTypes.get(i);
+                                       String param = methParams.get(i);
+                                       String simpleType = getSimpleType(paramType);
+                                       if (isStructClass(simpleType)) {
+                                               if (!begin) {   // Generate comma for not the beginning variable
+                                                       print(", "); begin = false;
+                                               }
+                                               int methodNumId = intDecl.getMethodNumId(method);
+                                               print("int struct" + methodNumId + "Size" + i);
+                                       }
+                               }
+                               println(") {");
+                               writeMethodHelperStructCplusSkeleton(intDecl, methParams, methPrmTypes, method, methodId, callbackClasses);
+                               println("}\n");
+                       } else {
+                               String methodId = intDecl.getMethodId(method);
+                               print("void ___");
+                               String helperMethod = methodId;
+                               if (uniqueMethodIds.contains(methodId))
+                                       helperMethod = helperMethod + intDecl.getMethodNumId(method);
+                               else
+                                       uniqueMethodIds.add(methodId);
+                               // Check if this is "void"
+                               String retType = intDecl.getMethodType(method);
+                               println(helperMethod + "() {");
+                               // Now, write the helper body of skeleton!
+                               writeStdMethodHelperBodyCplusSkeleton(intDecl, methParams, methPrmTypes, method, methodId, callbackClasses);
+                               println("}\n");
+                       }
+               }
+               // Write method helper for structs
+               writeMethodHelperStructSetupCplusSkeleton(methods, intDecl);
+       }
+
+
+       /**
+        * HELPER: writeMethodHelperStructSetupCplusSkeleton() writes the method helper of struct in skeleton class
+        */
+       private void writeMethodHelperStructSetupCplusSkeleton(Collection<String> methods, 
+                       InterfaceDecl intDecl) {
+
+               // Use this set to handle two same methodIds
+               for (String method : methods) {
+
+                       List<String> methParams = intDecl.getMethodParams(method);
+                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                       // Check for params with structs
+                       for (int i = 0; i < methParams.size(); i++) {
+                               String paramType = methPrmTypes.get(i);
+                               String param = methParams.get(i);
+                               String simpleType = getSimpleType(paramType);
+                               if (isStructClass(simpleType)) {
+                                       int methodNumId = intDecl.getMethodNumId(method);
+                                       print("int ___");
+                                       String helperMethod = methodNumId + "struct" + i;
+                                       println(helperMethod + "() {");
+                                       // Now, write the helper body of skeleton!
+                                       println("string paramCls[] = { \"int\" };");
+                                       println("int numParam = 1;");
+                                       println("int param0 = 0;");
+                                       println("void* paramObj[] = { &param0 };");
+                                       println("rmiObj->getMethodParams(paramCls, numParam, paramObj);");
+                                       println("return param0;");
+                                       println("}\n");
+                               }
+                       }
+               }
+       }
+
+
+       /**
+        * HELPER: writeMethodHelperStructSetupCplusCallbackSkeleton() writes the method helper of struct in skeleton class
+        */
+       private void writeMethodHelperStructSetupCplusCallbackSkeleton(Collection<String> methods, 
+                       InterfaceDecl intDecl) {
+
+               // Use this set to handle two same methodIds
+               for (String method : methods) {
+
+                       List<String> methParams = intDecl.getMethodParams(method);
+                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                       // Check for params with structs
+                       for (int i = 0; i < methParams.size(); i++) {
+                               String paramType = methPrmTypes.get(i);
+                               String param = methParams.get(i);
+                               String simpleType = getSimpleType(paramType);
+                               if (isStructClass(simpleType)) {
+                                       int methodNumId = intDecl.getMethodNumId(method);
+                                       print("int ___");
+                                       String helperMethod = methodNumId + "struct" + i;
+                                       println(helperMethod + "(IoTRMIObject* rmiObj) {");
+                                       // Now, write the helper body of skeleton!
+                                       println("string paramCls[] = { \"int\" };");
+                                       println("int numParam = 1;");
+                                       println("int param0 = 0;");
+                                       println("void* paramObj[] = { &param0 };");
+                                       println("rmiObj->getMethodParams(paramCls, numParam, paramObj);");
+                                       println("return param0;");
+                                       println("}\n");
+                               }
+                       }
                }
        }
 
@@ -2740,11 +3996,11 @@ public class IoTCompiler {
                        println("cerr << \"Object with object Id: \" << _objectId << \"  is not allowed to access method: \" << methodId << endl;");
                        println("exit(-1);");
                        println("}");
+                       println("}");
                        println("else {");
                        println("cerr << \"Object Id: \" << _objectId << \" not recognized!\" << endl;");
                        println("exit(-1);");
                        println("}");
-                       println("}");
                }
        }
 
@@ -2758,6 +4014,7 @@ public class IoTCompiler {
                Set<String> uniqueMethodIds = new HashSet<String>();
                println("void ___waitRequestInvokeMethod() {");
                // Write variables here if we have callbacks or enums or structs
+               writeCountVarStructSkeleton(methods, intDecl);
                println("while (true) {");
                println("rmiObj->getMethodBytes();");
                println("int _objectId = rmiObj->getObjectId();");
@@ -2775,7 +4032,9 @@ public class IoTCompiler {
                                helperMethod = helperMethod + methodNumId;
                        else
                                uniqueMethodIds.add(methodId);
-                       println(helperMethod + "(); break;");
+                       print(helperMethod + "(");
+                       writeInputCountVarStructSkeleton(method, intDecl);
+                       println("); break;");
                }
                String method = "___initCallBack()";
                // Print case -9999 (callback handler) if callback exists
@@ -2783,6 +4042,7 @@ public class IoTCompiler {
                        int methodId = intDecl.getHelperMethodNumId(method);
                        println("case " + methodId + ": ___regCB(); break;");
                }
+               writeMethodCallStructSkeleton(methods, intDecl);
                println("default: ");
                println("cerr << \"Method Id \" << methodId << \" not recognized!\" << endl;");
                println("throw exception();");
@@ -2911,7 +4171,7 @@ public class IoTCompiler {
 
 
        /**
-        * HELPER: writeMethodHelperCplusCallbackSkeleton() writes the method helper of the callback skeleton class
+        * HELPER: writeMethodHelperCplusCallbackSkeleton() writes the method helper of callback skeleton class
         */
        private void writeMethodHelperCplusCallbackSkeleton(Collection<String> methods, InterfaceDecl intDecl, 
                        Set<String> callbackClasses) {
@@ -2922,25 +4182,55 @@ public class IoTCompiler {
 
                        List<String> methParams = intDecl.getMethodParams(method);
                        List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
-                       String methodId = intDecl.getMethodId(method);
-                       print("void ___");
-                       String helperMethod = methodId;
-                       if (uniqueMethodIds.contains(methodId))
-                               helperMethod = helperMethod + intDecl.getMethodNumId(method);
-                       else
-                               uniqueMethodIds.add(methodId);
-                       // Check if this is "void"
-                       String retType = intDecl.getMethodType(method);
-                       println(helperMethod + "(IoTRMIObject* rmiObj) {");
-                       // Now, write the helper body of skeleton!
-                       writeStdMethodHelperBodyCplusSkeleton(intDecl, methParams, methPrmTypes, method, methodId, callbackClasses);
-                       println("}\n");
+                       if (isStructPresent(methParams, methPrmTypes)) {        // Treat struct differently
+                               String methodId = intDecl.getMethodId(method);
+                               print("void ___");
+                               String helperMethod = methodId;
+                               if (uniqueMethodIds.contains(methodId))
+                                       helperMethod = helperMethod + intDecl.getMethodNumId(method);
+                               else
+                                       uniqueMethodIds.add(methodId);
+                               String retType = intDecl.getMethodType(method);
+                               print(helperMethod + "(");
+                               boolean begin = true;
+                               for (int i = 0; i < methParams.size(); i++) { // Print size variables
+                                       String paramType = methPrmTypes.get(i);
+                                       String param = methParams.get(i);
+                                       String simpleType = getSimpleType(paramType);
+                                       if (isStructClass(simpleType)) {
+                                               if (!begin) {   // Generate comma for not the beginning variable
+                                                       print(", "); begin = false;
+                                               }
+                                               int methodNumId = intDecl.getMethodNumId(method);
+                                               print("int struct" + methodNumId + "Size" + i);
+                                       }
+                               }
+                               println(", IoTRMIObject* rmiObj) {");
+                               writeMethodHelperStructCplusSkeleton(intDecl, methParams, methPrmTypes, method, methodId, callbackClasses);
+                               println("}\n");
+                       } else {
+                               String methodId = intDecl.getMethodId(method);
+                               print("void ___");
+                               String helperMethod = methodId;
+                               if (uniqueMethodIds.contains(methodId))
+                                       helperMethod = helperMethod + intDecl.getMethodNumId(method);
+                               else
+                                       uniqueMethodIds.add(methodId);
+                               // Check if this is "void"
+                               String retType = intDecl.getMethodType(method);
+                               println(helperMethod + "(IoTRMIObject* rmiObj) {");
+                               // Now, write the helper body of skeleton!
+                               writeStdMethodHelperBodyCplusSkeleton(intDecl, methParams, methPrmTypes, method, methodId, callbackClasses);
+                               println("}\n");
+                       }
                }
+               // Write method helper for structs
+               writeMethodHelperStructSetupCplusCallbackSkeleton(methods, intDecl);
        }
 
 
        /**
-        * HELPER: writeCplusCallbackWaitRequestInvokeMethod() writes the main loop of the skeleton class
+        * HELPER: writeCplusCallbackWaitRequestInvokeMethod() writes the request invoke method of the skeleton callback class
         */
        private void writeCplusCallbackWaitRequestInvokeMethod(Collection<String> methods, InterfaceDecl intDecl, 
                        boolean callbackExist) {
@@ -2949,6 +4239,8 @@ public class IoTCompiler {
                Set<String> uniqueMethodIds = new HashSet<String>();
                println("void invokeMethod(IoTRMIObject* rmiObj) {");
                // Write variables here if we have callbacks or enums or structs
+               writeCountVarStructSkeleton(methods, intDecl);
+               // Write variables here if we have callbacks or enums or structs
                println("int methodId = rmiObj->getMethodId();");
                // TODO: code the permission check here!
                println("switch (methodId) {");
@@ -2962,7 +4254,11 @@ public class IoTCompiler {
                                helperMethod = helperMethod + methodNumId;
                        else
                                uniqueMethodIds.add(methodId);
-                       println(helperMethod + "(rmiObj); break;");
+                       print(helperMethod + "(");
+                       if (writeInputCountVarStructSkeleton(method, intDecl))
+                               println(", rmiObj); break;");
+                       else
+                               println("rmiObj); break;");
                }
                String method = "___initCallBack()";
                // Print case -9999 (callback handler) if callback exists
@@ -2970,6 +4266,7 @@ public class IoTCompiler {
                        int methodId = intDecl.getHelperMethodNumId(method);
                        println("case " + methodId + ": ___regCB(rmiObj); break;");
                }
+               writeMethodCallStructCallbackSkeleton(methods, intDecl);
                println("default: ");
                println("cerr << \"Method Id \" << methodId << \" not recognized!\" << endl;");
                println("throw exception();");
@@ -2978,7 +4275,6 @@ public class IoTCompiler {
        }
 
 
-
        /**
         * generateCplusCallbackSkeletonClass() generate callback skeletons based on the methods list in C++
         */
@@ -3062,35 +4358,6 @@ public class IoTCompiler {
        }
 
 
-       /**
-        * generateReturnStmt() generate return statement based on methType
-        */
-       public String generateReturnStmt(String methType) {
-
-               // Generate dummy returns for now
-               if (methType.equals("short")||
-                       methType.equals("int")  ||
-                       methType.equals("long") ||
-                       methType.equals("float")||
-                       methType.equals("double")) {
-
-                       return "1";
-               } else if ( methType.equals("String")) {
-  
-                       return "\"a\"";
-               } else if ( methType.equals("char") ||
-                                       methType.equals("byte")) {
-
-                       return "\'a\'";
-               } else if ( methType.equals("boolean")) {
-
-                       return "true";
-               } else {
-                       return "null";
-               }
-       }
-
-
        /**
         * setDirectory() sets a new directory for stub files
         */
@@ -3144,7 +4411,7 @@ public class IoTCompiler {
 
 
        /**================
-        * Helper functions
+        * Basic helper functions
         **================
         */
        boolean newline=true;
@@ -3173,6 +4440,9 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * A collection of methods with print-to-file functionality
+        */
        private void println(String str) {
                if (newline) {
                        int tab = tablevel;
@@ -3243,7 +4513,7 @@ public class IoTCompiler {
        }
 
 
-       // Return parameter category, i.e. PRIMITIVES, NONPRIMITIVES, or USERDEFINED
+       // Return parameter category, i.e. PRIMITIVES, NONPRIMITIVES, USERDEFINED, ENUM, or STRUCT
        private ParamCategory getParamCategory(String paramType) {
 
                if (mapPrimitives.containsKey(paramType)) {
@@ -3261,7 +4531,7 @@ public class IoTCompiler {
 
 
        // Return full class name for non-primitives to generate Java import statements
-       // e.g. java.util.Set for Set, java.util.Map for Map
+       // e.g. java.util.Set for Set
        private String getNonPrimitiveJavaClass(String paramNonPrimitives) {
 
                return mapNonPrimitivesJava.get(paramNonPrimitives);
@@ -3269,7 +4539,7 @@ public class IoTCompiler {
 
 
        // Return full class name for non-primitives to generate Cplus include statements
-       // e.g. #include <set> for Set, #include <map> for Map
+       // e.g. #include <set> for Set
        private String getNonPrimitiveCplusClass(String paramNonPrimitives) {
 
                return mapNonPrimitivesCplus.get(paramNonPrimitives);
@@ -3319,7 +4589,7 @@ public class IoTCompiler {
        }
 
 
-       // Generate a set of standard classes for import statements
+       // Combine all classes for import statements
        private List<String> getAllLibClasses(Collection<String> stdLibClasses, Collection<String> libClasses) {
 
                List<String> allLibClasses = new ArrayList<String>(stdLibClasses);
@@ -3329,7 +4599,6 @@ public class IoTCompiler {
                                allLibClasses.add(str);
                        }
                }
-
                return allLibClasses;
        }
 
@@ -3405,9 +4674,14 @@ public class IoTCompiler {
        // Handle and return the correct struct declaration
        private String getStructType(String type) {
 
-               if (isStructClass(type)) {
-               // TODO: complete this method
-                       return type;
+               // Strips off array "[]" for return type
+               String pureType = getSimpleArrayType(type);
+               // Take the inner type of generic
+               if (getParamCategory(type) == ParamCategory.NONPRIMITIVES)
+                       pureType = getTypeOfGeneric(type)[0];
+               if (isStructClass(pureType)) {
+                       String structType = "int";
+                       return structType;
                } else
                        return type;
        }
@@ -3443,6 +4717,36 @@ public class IoTCompiler {
        }
 
 
+       // Return a struct declaration
+       private StructDecl getStructDecl(String type) {
+
+               // Just iterate over the set of interfaces
+               for (String intface : mapIntfacePTH.keySet()) {
+                       DeclarationHandler decHandler = mapIntDeclHand.get(intface);
+                       StructDecl structDecl = (StructDecl) decHandler.getStructDecl(intface);
+                       List<String> listStructDecl = structDecl.getStructTypes();
+                       if (listStructDecl.contains(type))
+                               return structDecl;
+               }
+               return null;
+       }
+
+
+       // Return number of members (-1 if not found)
+       private int getNumOfMembers(String type) {
+
+               // Just iterate over the set of interfaces
+               for (String intface : mapIntfacePTH.keySet()) {
+                       DeclarationHandler decHandler = mapIntDeclHand.get(intface);
+                       StructDecl structDecl = (StructDecl) decHandler.getStructDecl(intface);
+                       List<String> listStructDecl = structDecl.getStructTypes();
+                       if (listStructDecl.contains(type))
+                               return structDecl.getNumOfMembers(type);
+               }
+               return -1;
+       }
+
+
        // Generate a set of classes for include statements
        private Set<String> getIncludeClasses(Collection<String> methods, InterfaceDecl intDecl, String intface, boolean needExchange) {
 
@@ -3468,6 +4772,8 @@ public class IoTCompiler {
                                        }
                                } else if (getParamCategory(getSimpleArrayType(simpleType)) == ParamCategory.ENUM) {
                                        includeClasses.add("\"" + simpleType + ".hpp\"");
+                               } else if (getParamCategory(getSimpleArrayType(simpleType)) == ParamCategory.STRUCT) {
+                                       includeClasses.add("\"" + simpleType + ".hpp\"");
                                } else if (param.contains("[]")) {
                                // Check if this is array for C++; translate into vector
                                        includeClasses.add("<vector>");
@@ -3504,6 +4810,7 @@ public class IoTCompiler {
        }
 
 
+       // Print import statements into file
        private void printImportStatements(Collection<String> importClasses) {
 
                for(String cls : importClasses) {
@@ -3512,6 +4819,7 @@ public class IoTCompiler {
        }
 
 
+       // Print include statements into file
        private void printIncludeStatements(Collection<String> includeClasses) {
 
                for(String cls : includeClasses) {
@@ -3531,6 +4839,18 @@ public class IoTCompiler {
        }
 
 
+       // Gets generic type inside "<" and ">"
+       private String getGenericType(String type) {
+
+               // Handle <, >, and , for 2-type generic/template
+               if (getParamCategory(type) == ParamCategory.NONPRIMITIVES) {
+                       String[] substr = type.split("<")[1].split(">")[0].split(",");
+                       return substr[0];
+               } else
+                       return type;
+       }
+
+
        // This helper function strips off array declaration, e.g. int[] becomes int
        private String getSimpleArrayType(String type) {
 
@@ -3555,6 +4875,7 @@ public class IoTCompiler {
        }
 
 
+       // Checks and gets type in C++
        private String checkAndGetCplusType(String paramType) {
 
                if (getParamCategory(paramType) == ParamCategory.PRIMITIVES) {
@@ -3576,6 +4897,9 @@ public class IoTCompiler {
                                return cplusTemplate;
                        } else
                                return getNonPrimitiveCplusClass(paramType);
+               } else if(paramType.contains("[]")) {   // Array type (used for return type only)
+                       String cArray = "vector<" + getSimpleArrayType(paramType) + ">";
+                       return cArray;
                } else if(getParamCategory(paramType) == ParamCategory.USERDEFINED) {
                        return paramType + "*";
                } else
@@ -3671,7 +4995,8 @@ public class IoTCompiler {
        }
 
 
-       // Is array? For return type we put the return type as input parameter
+       // Is array? 
+       // For return type we use retType as input parameter
        private boolean isArray(String param) {
 
                // Check for array declaration
@@ -3829,5 +5154,3 @@ public class IoTCompiler {
 }
 
 
-
-