Exchanging cameras between benchmarks; updating database
[iot2.git] / benchmarks / Java / HomeSecurityController / RoomSmart_Stub.java
index 0c04049..9d2c37a 100644 (file)
@@ -4,24 +4,39 @@ import java.io.IOException;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
-import iotrmi.Java.IoTRMICall;
-import iotrmi.Java.IoTRMIObject;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import iotrmi.Java.IoTRMIComm;
+import iotrmi.Java.IoTRMICommClient;
+import iotrmi.Java.IoTRMICommServer;
+import iotrmi.Java.IoTRMIUtil;
 
-import iotcode.interfaces.RoomSmart;
+import iotcode.interfaces.*;
 
 public class RoomSmart_Stub implements RoomSmart {
 
-       private IoTRMICall rmiCall;
-       private String callbackAddress;
-       private int[] ports;
-
-       private final static int objectId = 0;
+       private int objectId = 4;
+       private IoTRMIComm rmiComm;
+       // Synchronization variables
+       private AtomicBoolean retValueReceived0 = new AtomicBoolean(false);
        
 
-       public RoomSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
-               callbackAddress = _callbackAddress;
-               ports = _ports;
-               rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
+       public RoomSmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
+               if (_localPortSend != 0 && _localPortRecv != 0) {
+                       rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
+               } else
+               {
+                       rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
+               }
+               rmiComm.registerStub(objectId, 0, retValueReceived0);
+               IoTRMIUtil.mapStub.put(objectId, this);
+       }
+
+       public RoomSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               rmiComm.registerStub(objectId, 0, retValueReceived0);
        }
 
        public int getRoomID() {
@@ -29,7 +44,13 @@ public class RoomSmart_Stub implements RoomSmart {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived0.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived0.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }