Sending int[] instead of a bunch of int for enum type transport; cleaning up method...
[iot2.git] / iotjava / iotrmi / Java / sample / TestClass_Skeleton.java
index 7147073ee1c56902922bf72739706b5283a1f4e1..753e238d4a70a97db00228ec767b3cc4b96a29c8 100644 (file)
@@ -16,22 +16,6 @@ public class TestClass_Skeleton implements TestClassInterface {
         */
        private int objectId = 0;       // Default value is 0
        private static int objIdCnt = 0; // Counter for callback object Ids
-       private final static String[] methodSignatures = {
-
-               "voidsetA(int)", // 0
-               "voidsetB(float)", // 1
-               "voidsetC(string)", // 2
-               "sumArray(string[])", // 3
-               "intsetAndGetA(int)", // 4
-               "intsetACAndGetA(string,int)", // 5
-               "intcallBack()", // 6
-               "voidregisterCallBack(CallBackInterface)", // 7
-               "voidregisterCallBack(CallBackInterface[])", // 8
-               "registercallback", // 9
-               "handleStruct(StructJ[])", // 10
-               "structsize" // 11
-       };
-
        private TestClassInterface tc;
        private int port;
        private IoTRMIObject rmiObj;
@@ -62,7 +46,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___setA() {
 
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                setA((int) paramObj[0]);
        }
        
@@ -76,7 +60,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___setB() {
 
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { float.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                setB((float) paramObj[0]);
        }
        
@@ -90,7 +74,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___setC() {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                setC((String) paramObj[0]);
        }
        
@@ -104,7 +88,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___sumArray() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { String[].class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                Object retObj = sumArray((String[]) paramObj[0]);
                rmiObj.sendReturnObj(retObj);
        }
@@ -119,7 +103,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___setAndGetA() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                Object retObj = setAndGetA((int) paramObj[0]);
                rmiObj.sendReturnObj(retObj);
        }
@@ -134,7 +118,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___setACAndGetA() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class, int.class }, 
-                       new Class<?>[] { null, null }, new Class<?>[] { null, null });
+                       new Class<?>[] { null, null });
                Object retObj = setACAndGetA((String) paramObj[0], (int) paramObj[1]);
                rmiObj.sendReturnObj(retObj);
        }
@@ -149,7 +133,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___registerCallback() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class }, 
-                       new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
+                       new Class<?>[] { null, null, null });
                CallBackInterface cbstub = new CallBack_Stub((int) paramObj[0], (String) paramObj[1], (int) paramObj[2]);
                registerCallback((CallBackInterface) cbstub);
        }
@@ -165,7 +149,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ____registerCallback() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                int numStubs = (int) paramObj[0];
                CallBackInterface[] stub = new CallBackInterface[numStubs];
                for (int objId = 0; objId < numStubs; objId++) {
@@ -179,7 +163,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___regCB() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class }, 
-                       new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
+                       new Class<?>[] { null, null, null });
                //String[] methodSignatures = CallBack_CBStub.getMethodSignatures();
                rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], (int) paramObj[2]);
                System.out.println("Creating a new IoTRMICall object");
@@ -208,7 +192,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public int ___structSize() {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                return (int) paramObj[0];
        }
        
@@ -216,22 +200,18 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___handleStruct(int structsize1) {
 
                Class<?>[] paramCls = new Class<?>[3*structsize1];
-               Class<?>[] paramClsTyp1 = new Class<?>[3*structsize1];
-               Class<?>[] paramClsTyp2 = new Class<?>[3*structsize1];
+               Class<?>[] paramClsVal = new Class<?>[3*structsize1];
                int pos = 0;
                for(int i=0; i < structsize1; i++) {
                        paramCls[pos] = String.class;
-                       paramClsTyp1[pos] = null;
-                       paramClsTyp2[pos++] = null;
+                       paramClsVal[pos++] = null;
                        paramCls[pos] = float.class;
-                       paramClsTyp1[pos] = null;
-                       paramClsTyp2[pos++] = null;
+                       paramClsVal[pos++] = null;
                        paramCls[pos] = int.class;
-                       paramClsTyp1[pos] = null;
-                       paramClsTyp2[pos++] = null;
+                       paramClsVal[pos++] = null;
                }
                Object[] paramObj = rmiObj.getMethodParams(paramCls, 
-                       paramClsTyp1, paramClsTyp2);
+                       paramClsVal);
                StructJ[] data = new StructJ[structsize1];
                for (int i=0; i < structsize1; i++) {
                        data[i] = new StructJ();
@@ -244,12 +224,46 @@ public class TestClass_Skeleton implements TestClassInterface {
                }
                tc.handleStruct(data);
        }
+
+
+       public EnumJ[] handleEnum(EnumJ[] en) {
+
+               return tc.handleEnum(en);
+       }
+
+
+       public void ___handleEnum() throws IOException {
+
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class }, 
+                       new Class<?>[] { null }); 
+               // Encoder/decoder
+               int paramInt[] = (int[]) paramObj[0];
+               int enumSize1 = paramInt.length;
+               EnumJ[] enumJ = EnumJ.values();
+               EnumJ[] data = new EnumJ[enumSize1];
+               for (int i=0; i < enumSize1; i++) {
+                       data[i] = enumJ[paramInt[i]];
+               }
+               // if void, just "handleEnum(data)"
+               // this is when we have return value EnumJ[]
+               EnumJ[] retEnum = handleEnum(data);
+               // Get length first
+               int enumSize2 = retEnum.length;
+               // Now send the array of integers
+               int[] retEnumInt = new int[enumSize2];
+               for (int i=0; i < enumSize2; i++) {
+                       retEnumInt[i] = retEnum[i].ordinal();
+               }
+               Object retObj = retEnumInt;
+               rmiObj.sendReturnObj(retObj);
+       }
        
 
        private void ___waitRequestInvokeMethod() throws IOException {
 
                // Struct size
-               int structsize1 = 0;
+               int structSize1 = 0;
+               int enumSize1 = 0;
                // Loop continuously waiting for incoming bytes
                while (true) {
 
@@ -272,21 +286,15 @@ public class TestClass_Skeleton implements TestClassInterface {
                                        // Special option to register callback
                                        case 9: ___regCB(); break;
                                        // Struct handling (3 is the size of the struct)
-                                       case 10: ___handleStruct(structsize1); break;
-                                       case 11: structsize1 = ___structSize(); break;
+                                       case 10: ___handleStruct(structSize1); break;
+                                       case 11: structSize1 = ___structSize(); break;
+                                       case 12: ___handleEnum(); break;
                                        default:
-                                               throw new Error("Signature not recognized!");
+                                               throw new Error("Method Id not recognized!");
                                }
                        }
                }
        }
-
-
-       // Return method signatures
-       public static String[] getMethodSignatures() {
-
-               return methodSignatures;
-       }
        
        
        public static void main(String[] args) throws Exception {