Adjusting and cleaning up ZigbeeTest to install Vigilia ZigBee gateway and devices.
[iot2.git] / iotjava / iotrmi / Java / sample / CallBack_Skeleton.java
index 46e0df6fcffd56ff69640b5a3d59f223853779b8..77a3c815f452fb9d5aabb4a4b393789fea45bc75 100644 (file)
@@ -5,14 +5,9 @@ import java.util.Set;
 import java.util.Arrays;
 import iotrmi.Java.IoTRMIObject;
 
-public class CallBack_Skeleton {
-
-       private String[] methodSignatures = {
-
-               "intprintInt()",
-               "voidsetInt(int)"
-       };
+public class CallBack_Skeleton implements CallBackInterface {
 
+       private int objectId = 0;       // Default value is 0
        private CallBackInterface cb;
        private IoTRMIObject rmiObj;
 
@@ -26,37 +21,53 @@ public class CallBack_Skeleton {
 
                cb = _cb;
                System.out.println("Creating CallBack_Skeleton and waiting!");
-               rmiObj = new IoTRMIObject(_port, methodSignatures);
+               rmiObj = new IoTRMIObject(_port);
+               ___waitRequestInvokeMethod();
        }
 
 
-       public void waitRequestInvokeMethod() throws IOException {
+       public int printInt() {
+               return cb.printInt();
+       }
+       
+       
+       public void ___printInt() throws IOException {
+               Object retObj = printInt();
+               rmiObj.sendReturnObj(retObj);
+       }
+
+
+       public void setInt(int _i) {
+               cb.setInt(_i);
+       }
+       
+       
+       public void ___setInt() {
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
+                       new Class<?>[] { null });
+               setInt((int) paramObj[0]);
+       }
+       
+
+       private void ___waitRequestInvokeMethod() throws IOException {
 
                // Loop continuously waiting for incoming bytes
                while (true) {
 
                        rmiObj.getMethodBytes();
-                       String methodSign = rmiObj.getSignature();
-                       Object[] paramObj = null;
-                       Object retObj = null;
-                       System.out.println("Method sign: " + methodSign);
-
-                       if (methodSign.equals("intprintInt()")) {
-                               //paramObj = rmiObj.getMethodParams(new Class<?>[] { }, 
-                               //      new Class<?>[] { null }, new Class<?>[] { null });
-                               retObj = cb.printInt();
-                       } else if (methodSign.equals("voidsetInt(int)")) {
-                               paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                                       new Class<?>[] { null }, new Class<?>[] { null });
-                               cb.setInt((int) paramObj[0]);
-                       } else
-                               throw new Error("Signature un-recognized!");
-                       System.out.println("Return object: " + retObj);
-
-                       if (retObj != null) {
-                               rmiObj.sendReturnObj(retObj);
+                       int objId = rmiObj.getObjectId();
+                       if (objId == objectId) {
+                       // Multiplex based on object Id
+                               rmiObj.getMethodBytes();
+                               int methodId = rmiObj.getMethodId();
+
+                               switch (methodId) {
+                                       case 0: ___printInt(); break;
+                                       case 1: ___setInt(); break;
+                                       default:
+                                               throw new Error("Method Id not recognized!");
+                               }
                        }
-                       System.out.println("Servicing remote call for method: " + methodSign);
                }
        }
 
@@ -66,6 +77,6 @@ public class CallBack_Skeleton {
                int port = 5010;
                CallBack cb = new CallBack(23);
                CallBack_Skeleton cbSkel = new CallBack_Skeleton(cb, port);
-               cbSkel.waitRequestInvokeMethod();
+               //cbSkel.waitRequestInvokeMethod();
        }
 }