Initial version that handles multiple callback objects through 1 socket
[iot2.git] / iotjava / iotrmi / Java / IoTRMICall.java
index 433c6599513e921f02dc41fe4ecf2d0e1ac89908..8bd86c9207eb90a544dc6a193db0641c796e6e4a 100644 (file)
@@ -48,11 +48,11 @@ public class IoTRMICall {
        /**
         * remoteCall() calls a method remotely by passing in parameters and getting a return Object
         */
-       public Object remoteCall(String methodSign, Class<?> retType, Class<?> retGenTypeKey, 
+       public Object remoteCall(int objectId, String methodSign, Class<?> retType, Class<?> retGenTypeKey, 
                        Class<?> retGenTypeVal, Class<?>[] paramCls, Object[] paramObj) {
 
                // Send method info
-               byte[] methodBytes = methodToBytes(methodSign, paramCls, paramObj);
+               byte[] methodBytes = methodToBytes(objectId, methodSign, paramCls, paramObj);
                try {
                        rmiClient.sendBytes(methodBytes);
                } catch (IOException ex) {
@@ -78,15 +78,17 @@ public class IoTRMICall {
        /**
         * methodToBytes() returns byte representation of a method
         */
-       public byte[] methodToBytes(String methodSign, Class<?>[] paramCls, Object[] paramObj) {
+       public byte[] methodToBytes(int objectId, String methodSign, Class<?>[] paramCls, Object[] paramObj) {
 
+               // Initialized to the length of method ID
+               int methodLen = IoTRMIUtil.OBJECT_ID_LEN;
+               byte[] objId = IoTRMIUtil.intToByteArray(objectId);
                // Get method ID in bytes
                int methId = listMethodId.indexOf(methodSign);
                byte[] methodId = IoTRMIUtil.intToByteArray(methId);
-
                // Get byte arrays and calculate method bytes length
                int numbParam = paramObj.length;
-               int methodLen = IoTRMIUtil.METHOD_ID_LEN;       // Initialized to the length of method ID
+               methodLen = methodLen + IoTRMIUtil.METHOD_ID_LEN;
                byte[][] objBytesArr = new byte[numbParam][];
                for (int i = 0; i < numbParam; i++) {
                        // Get byte arrays for the objects
@@ -98,11 +100,12 @@ public class IoTRMICall {
                        }
                        methodLen = methodLen + objBytesArr[i].length;
                }
-
                // Construct method in byte array
                byte[] method = new byte[methodLen];
                int pos = 0;
-               System.arraycopy(methodId, 0, method, 0, methodId.length);
+               System.arraycopy(objId, 0, method, 0, IoTRMIUtil.METHOD_ID_LEN);
+               pos = pos + IoTRMIUtil.OBJECT_ID_LEN;
+               System.arraycopy(methodId, 0, method, pos, IoTRMIUtil.METHOD_ID_LEN);
                pos = pos + IoTRMIUtil.METHOD_ID_LEN;
                // Second iteration for copying bytes
                for (int i = 0; i < numbParam; i++) {