Updating the first benchmark with new stubs/skeletons; somehow motion detection is...
authorrtrimana <rtrimana@uci.edu>
Tue, 21 Feb 2017 23:21:38 +0000 (15:21 -0800)
committerrtrimana <rtrimana@uci.edu>
Tue, 21 Feb 2017 23:21:38 +0000 (15:21 -0800)
21 files changed:
benchmarks/Java/Lifxtest/LightBulbTest_Stub.java
benchmarks/Java/SmartLightsController/CameraCallback_CallbackSkeleton.java [deleted file]
benchmarks/Java/SmartLightsController/CameraCallback_Skeleton.java [new file with mode: 0644]
benchmarks/Java/SmartLightsController/CameraSmart_Stub.java
benchmarks/Java/SmartLightsController/LightBulbSmart_Stub.java
benchmarks/Java/SmartLightsController/MotionDetection.java
benchmarks/Java/SmartLightsController/RoomSmart_Stub.java
benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.cpp
benchmarks/drivers/Java/AmcrestCamera/AmcrestCamera.java
benchmarks/drivers/Java/AmcrestCamera/CameraSmartCallback_CallbackStub.java [deleted file]
benchmarks/drivers/Java/AmcrestCamera/CameraSmartCallback_Stub.java [new file with mode: 0644]
benchmarks/drivers/Java/AmcrestCamera/Camera_Skeleton.java
benchmarks/drivers/Java/LabRoom/Room_Skeleton.java
benchmarks/drivers/Java/LifxLightBulb/LightBulb_Skeleton.java
benchmarks/interfaces/CameraCallback.java
benchmarks/interfaces/CameraSmartCallback.java
iotjava/Makefile
iotjava/iotrmi/Java/IoTRMIComm.java
iotjava/iotrmi/Java/IoTRMICommClient.java
iotjava/iotrmi/Java/IoTRMICommServer.java
iotjava/iotrmi/Java/IoTSocket.java

index 60f9829..82af4c1 100644 (file)
@@ -16,7 +16,7 @@ import iotcode.interfaces.LightBulbTest;
 
 public class LightBulbTest_Stub implements LightBulbTest {
 
-       private int objectId = 0;
+       private int objectId = 1;
        private IoTRMIComm rmiComm;
        // Synchronization variables
        private AtomicBoolean retValueReceived6 = new AtomicBoolean(false);
diff --git a/benchmarks/Java/SmartLightsController/CameraCallback_CallbackSkeleton.java b/benchmarks/Java/SmartLightsController/CameraCallback_CallbackSkeleton.java
deleted file mode 100644 (file)
index 4c4f592..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-package SmartLightsController;
-
-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 iotcode.interfaces.*;
-
-public class CameraCallback_CallbackSkeleton implements CameraCallback {
-
-       private CameraCallback mainObj;
-       private int objectId = 0;
-       private String callbackAddress;
-       
-
-       public CameraCallback_CallbackSkeleton(CameraCallback _mainObj, String _callbackAddress, int _objectId) throws Exception {
-               callbackAddress = _callbackAddress;
-               mainObj = _mainObj;
-               objectId = _objectId;
-       }
-
-       public void newCameraFrameAvailable(byte latestFrame[], long timeStamp) {
-               mainObj.newCameraFrameAvailable(latestFrame, timeStamp);
-       }
-
-       public void ___newCameraFrameAvailable(IoTRMIObject rmiObj) {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { byte[].class, long.class }, 
-               new Class<?>[] { null, null });
-               newCameraFrameAvailable((byte[]) paramObj[0], (long) paramObj[1]);
-       }
-
-       public void invokeMethod(IoTRMIObject rmiObj) throws IOException {
-               int methodId = rmiObj.getMethodId();
-               switch (methodId) {
-                       case 0: ___newCameraFrameAvailable(rmiObj); break;
-                       default: 
-                       throw new Error("Method Id " + methodId + " not recognized!");
-               }
-       }
-
-}
diff --git a/benchmarks/Java/SmartLightsController/CameraCallback_Skeleton.java b/benchmarks/Java/SmartLightsController/CameraCallback_Skeleton.java
new file mode 100644 (file)
index 0000000..0e4b30d
--- /dev/null
@@ -0,0 +1,136 @@
+package SmartLightsController;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+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.*;
+
+public class CameraCallback_Skeleton implements CameraCallback {
+
+       private CameraCallback mainObj;
+       private int objectId = 0;
+       // Communications and synchronizations
+       private IoTRMIComm rmiComm;
+       private AtomicBoolean didAlreadyInitWaitInvoke;
+       private AtomicBoolean methodReceived;
+       private byte[] methodBytes = null;
+       // Permissions
+       private final static int object0Id = 0; //CameraSmartCallback
+       private static Integer[] object0Permission = { 0 };
+       private static List<Integer> set0Allowed;
+       
+
+       public CameraCallback_Skeleton(CameraCallback _mainObj, int _portSend, int _portRecv) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               IoTRMIUtil.mapSkel.put(_mainObj, this);
+               IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+               Thread thread1 = new Thread() {
+                       public void run() {
+                               try {
+                                       ___waitRequestInvokeMethod();
+                               }
+                               catch (Exception ex)
+                               {
+                                       ex.printStackTrace();
+                               }
+                       }
+               };
+               thread1.start();
+       }
+
+       public CameraCallback_Skeleton(CameraCallback _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+       }
+
+       public boolean didAlreadyInitWaitInvoke() {
+               return didAlreadyInitWaitInvoke.get();
+       }
+
+       public void newCameraFrameAvailable(CameraSmart _camera) {
+               mainObj.newCameraFrameAvailable(_camera);
+       }
+
+       public void ___newCameraFrameAvailable() {
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
+               try {
+                       int[] stubIdArray0 = (int[]) paramObj[0];
+                       int objIdRecv0 = stubIdArray0[0];
+                       CameraSmart newStub0 = null;
+                       if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
+                               newStub0 = new CameraSmart_Stub(rmiComm, objIdRecv0);
+                               IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
+                               rmiComm.setObjectIdCounter(objIdRecv0);
+                               rmiComm.decrementObjectIdCounter();
+                       }
+                       else {
+                               newStub0 = (CameraSmart_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
+                       }
+                       CameraSmart stub0 = newStub0;
+                       newCameraFrameAvailable(stub0);
+               } catch(Exception ex) {
+                       ex.printStackTrace();
+                       throw new Error("Exception from callback object instantiation!");
+               }
+       }
+
+       public void ___waitRequestInvokeMethod() throws IOException {
+               didAlreadyInitWaitInvoke.compareAndSet(false, true);
+               while (true) {
+                       if (!methodReceived.get()) {
+                               continue;
+                       }
+                       methodBytes = rmiComm.getMethodBytes();
+                       methodReceived.set(false);
+                       int _objectId = IoTRMIComm.getObjectId(methodBytes);
+                       int methodId = IoTRMIComm.getMethodId(methodBytes);
+                       if (_objectId == objectId) {
+                               if (!set0Allowed.contains(methodId)) {
+                                       throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
+                               }
+                       }
+                       else {
+                               continue;
+                       }
+                       switch (methodId) {
+                               case 0:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___newCameraFrameAvailable();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                               //System.out.println("Thread done!");
+                                       }
+                               }.start();
+                               break;
+                               default: 
+                               throw new Error("Method Id " + methodId + " not recognized!");
+                       }
+               }
+       }
+
+}
index 87d836a..48fe2f9 100644 (file)
@@ -4,35 +4,57 @@ 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.*;
 
 public class CameraSmart_Stub implements CameraSmart {
 
-       private IoTRMICall rmiCall;
-       private String callbackAddress;
-       private int[] ports;
-
-       private final static int objectId = 0;
-       // Callback properties
-       private IoTRMIObject rmiObj;
-       List<CameraCallback> listCallbackObj;
-       private static int objIdCnt = 0;
-       private final static int object0Id = 0; //CameraSmartCallback
-       private static Integer[] object0Permission = { 0 };
-       private static List<Integer> set0Allowed;
+       private int objectId = 0;
+       private IoTRMIComm rmiComm;
+       // Synchronization variables
+       private AtomicBoolean retValueReceived8 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived7 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived9 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived6 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived5 = new AtomicBoolean(false);
        
 
-       public CameraSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
-               callbackAddress = _callbackAddress;
-               ports = _ports;
-               rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
-               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
-               listCallbackObj = new ArrayList<CameraCallback>();
-               set0Allowed.add(-9999);
-               ___initCallBack();
+       public CameraSmart_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, 8, retValueReceived8);
+               rmiComm.registerStub(objectId, 7, retValueReceived7);
+               rmiComm.registerStub(objectId, 9, retValueReceived9);
+               rmiComm.registerStub(objectId, 6, retValueReceived6);
+               rmiComm.registerStub(objectId, 4, retValueReceived4);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 5, retValueReceived5);
+               IoTRMIUtil.mapStub.put(objectId, this);
+       }
+
+       public CameraSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               rmiComm.registerStub(objectId, 8, retValueReceived8);
+               rmiComm.registerStub(objectId, 7, retValueReceived7);
+               rmiComm.registerStub(objectId, 9, retValueReceived9);
+               rmiComm.registerStub(objectId, 6, retValueReceived6);
+               rmiComm.registerStub(objectId, 4, retValueReceived4);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 5, retValueReceived5);
        }
 
        public int getMaxFPS() {
@@ -40,7 +62,13 @@ public class CameraSmart_Stub implements CameraSmart {
                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 (!retValueReceived8.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived8.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
@@ -49,7 +77,13 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = boolean.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { _fps };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived7.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived7.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (boolean)retObj;
        }
 
@@ -58,7 +92,13 @@ public class CameraSmart_Stub implements CameraSmart {
                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 (!retValueReceived9.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived9.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
@@ -69,7 +109,13 @@ public class CameraSmart_Stub implements CameraSmart {
                paramEnum0[0] = _res.ordinal();
                Class<?>[] paramCls = new Class<?>[] { int[].class };
                Object[] paramObj = new Object[] { paramEnum0 };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+               // Waiting for return value
+               while (!retValueReceived6.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived6.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (boolean)retObj;
        }
 
@@ -78,7 +124,7 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void start() {
@@ -86,7 +132,7 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public long getTimestamp() {
@@ -94,7 +140,13 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = long.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 (!retValueReceived4.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived4.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (long)retObj;
        }
 
@@ -103,7 +155,13 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = byte[].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 (!retValueReceived3.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived3.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (byte[])retObj;
        }
 
@@ -112,13 +170,37 @@ public class CameraSmart_Stub implements CameraSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void registerCallback(CameraCallback _callbackTo) {
+               int[] objIdSent0 = new int[1];
                try {
-                       CameraCallback_CallbackSkeleton skel0 = new CameraCallback_CallbackSkeleton(_callbackTo, callbackAddress, objIdCnt++);
-                       listCallbackObj.add(skel0);
+                       if (!IoTRMIUtil.mapSkel.containsKey(_callbackTo)) {
+                               int newObjIdSent = rmiComm.getObjectIdCounter();
+                               objIdSent0[0] = newObjIdSent;
+                               rmiComm.decrementObjectIdCounter();
+                               CameraCallback_Skeleton skel0 = new CameraCallback_Skeleton(_callbackTo, rmiComm, newObjIdSent);
+                               IoTRMIUtil.mapSkel.put(_callbackTo, skel0);
+                               IoTRMIUtil.mapSkelId.put(_callbackTo, newObjIdSent);
+                               Thread thread = new Thread() {
+                                       public void run() {
+                                               try {
+                                                       skel0.___waitRequestInvokeMethod();
+                                                       } catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                                       throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for CameraCallback_Skeleton!");
+                                               }
+                                       }
+                               };
+                               thread.start();
+                               while(!skel0.didAlreadyInitWaitInvoke());
+                       }
+                       else
+                       {
+                               int newObjIdSent = IoTRMIUtil.mapSkelId.get(_callbackTo);
+                               objIdSent0[0] = newObjIdSent;
+                       }
                } catch (Exception ex) {
                        ex.printStackTrace();
                        throw new Error("Exception when generating skeleton objects!");
@@ -126,43 +208,9 @@ public class CameraSmart_Stub implements CameraSmart {
 
                int methodId = 10;
                Class<?> retType = void.class;
-               Class<?>[] paramCls = new Class<?>[] { int.class };
-               Object[] paramObj = new Object[] { new Integer(1) };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
-       }
-
-       public void ___initCallBack() {
-               Thread thread = new Thread() {
-                       public void run() {
-                               try {
-                                       rmiObj = new IoTRMIObject(ports[0]);
-                                       while (true) {
-                                               byte[] method = rmiObj.getMethodBytes();
-                                               int objId = IoTRMIObject.getObjectId(method);
-                                               CameraCallback_CallbackSkeleton skel = (CameraCallback_CallbackSkeleton) listCallbackObj.get(objId);
-                                               if (skel != null) {
-                                                       int methodId = IoTRMIObject.getMethodId(method);
-                                                       if (!set0Allowed.contains(methodId)) {
-                                                               throw new Error("Callback object for CameraCallback is not allowed to access method: " + methodId);
-                                                       }
-                                                       skel.invokeMethod(rmiObj);
-                                               } else {
-                                                       throw new Error("CameraCallback: Object with Id " + objId + " not found!");
-                                               }
-                                       }
-                               } catch (Exception ex) {
-                                       ex.printStackTrace();
-                                       throw new Error("Error instantiating class CameraCallback_CallbackSkeleton!");
-                               }
-                       }
-               };
-               thread.start();
-
-               int methodId = -9998;
-               Class<?> retType = void.class;
-               Class<?>[] paramCls = new Class<?>[] { int[].class, String.class, int.class };
-               Object[] paramObj = new Object[] { ports, callbackAddress, 0 };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               Class<?>[] paramCls = new Class<?>[] { int[].class };
+               Object[] paramObj = new Object[] { objIdSent0 };
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public List<Resolution> getSupportedResolutions() {
@@ -170,7 +218,13 @@ public class CameraSmart_Stub implements CameraSmart {
                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 (!retValueReceived5.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived5.set(false);
+               rmiComm.setGetReturnBytes();
+
                int[] retEnum = (int[]) retObj;
                Resolution[] enumVals = Resolution.values();
                int retLen = retEnum.length;
index ecfccf9..ef0c4bc 100644 (file)
@@ -4,23 +4,75 @@ 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.LightBulbSmart;
 
 public class LightBulbSmart_Stub implements LightBulbSmart {
 
-       private IoTRMICall rmiCall;
-       private String callbackAddress;
-       private int[] ports;
-       private final static int objectId = 0;
+       private int objectId = 1;
+       private IoTRMIComm rmiComm;
+       // Synchronization variables
+       private AtomicBoolean retValueReceived10 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived11 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived8 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived12 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived7 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived13 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived9 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived6 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived16 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived17 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived14 = new AtomicBoolean(false);
+       private AtomicBoolean retValueReceived15 = new AtomicBoolean(false);
        
 
-       public LightBulbSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
-               callbackAddress = _callbackAddress;
-               ports = _ports;
-               rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
+       public LightBulbSmart_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, 10, retValueReceived10);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 11, retValueReceived11);
+               rmiComm.registerStub(objectId, 8, retValueReceived8);
+               rmiComm.registerStub(objectId, 12, retValueReceived12);
+               rmiComm.registerStub(objectId, 7, retValueReceived7);
+               rmiComm.registerStub(objectId, 13, retValueReceived13);
+               rmiComm.registerStub(objectId, 9, retValueReceived9);
+               rmiComm.registerStub(objectId, 6, retValueReceived6);
+               rmiComm.registerStub(objectId, 16, retValueReceived16);
+               rmiComm.registerStub(objectId, 17, retValueReceived17);
+               rmiComm.registerStub(objectId, 14, retValueReceived14);
+               rmiComm.registerStub(objectId, 15, retValueReceived15);
+               IoTRMIUtil.mapStub.put(objectId, this);
+       }
+
+       public LightBulbSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               rmiComm.registerStub(objectId, 10, retValueReceived10);
+               rmiComm.registerStub(objectId, 3, retValueReceived3);
+               rmiComm.registerStub(objectId, 11, retValueReceived11);
+               rmiComm.registerStub(objectId, 8, retValueReceived8);
+               rmiComm.registerStub(objectId, 12, retValueReceived12);
+               rmiComm.registerStub(objectId, 7, retValueReceived7);
+               rmiComm.registerStub(objectId, 13, retValueReceived13);
+               rmiComm.registerStub(objectId, 9, retValueReceived9);
+               rmiComm.registerStub(objectId, 6, retValueReceived6);
+               rmiComm.registerStub(objectId, 16, retValueReceived16);
+               rmiComm.registerStub(objectId, 17, retValueReceived17);
+               rmiComm.registerStub(objectId, 14, retValueReceived14);
+               rmiComm.registerStub(objectId, 15, retValueReceived15);
        }
 
        public void turnOn() {
@@ -28,7 +80,7 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public double getBrightnessRangeLowerBound() {
@@ -36,7 +88,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived10.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived10.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -45,7 +103,7 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public boolean getState() {
@@ -53,7 +111,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = boolean.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 (!retValueReceived3.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived3.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (boolean)retObj;
        }
 
@@ -62,7 +126,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived11.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived11.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -71,7 +141,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived8.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived8.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -80,7 +156,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived12.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived12.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -89,7 +171,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived7.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived7.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -98,7 +186,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived13.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived13.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -107,7 +201,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                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 (!retValueReceived9.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived9.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
@@ -116,7 +216,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived6.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived6.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -125,7 +231,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                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 (!retValueReceived16.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived16.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
@@ -134,7 +246,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                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 (!retValueReceived17.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived17.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (int)retObj;
        }
 
@@ -143,7 +261,7 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { double.class, double.class, double.class };
                Object[] paramObj = new Object[] { _hue, _saturation, _brightness };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public void init() {
@@ -151,7 +269,7 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] {  };
                Object[] paramObj = new Object[] {  };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
        public double getSaturationRangeLowerBound() {
@@ -159,7 +277,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived14.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived14.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -168,7 +292,13 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = double.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 (!retValueReceived15.get());
+               Object retObj = rmiComm.getReturnValue(retType, null);
+               retValueReceived15.set(false);
+               rmiComm.setGetReturnBytes();
+
                return (double)retObj;
        }
 
@@ -177,7 +307,7 @@ public class LightBulbSmart_Stub implements LightBulbSmart {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { _temperature };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
        }
 
 }
index bd47350..4aa0dc8 100644 (file)
@@ -257,13 +257,16 @@ class MotionDetection implements CameraCallback {
         *
         *   @return [void] None.
         */
-       public void newCameraFrameAvailable(byte[] latestFrame, long timeStamp) {
+       //public void newCameraFrameAvailable(byte[] latestFrame, long timeStamp) {
+       public void newCameraFrameAvailable(CameraSmart _camera) {
                BufferedImage img = null;
 
+               // Parse the byte array into a Buffered Image
+               byte[] newImg = _camera.getLatestFrame();
                try {
-                       // Parse the byte array into a Buffered Image
                        //InputStream in = new ByteArrayInputStream(_camera.getLatestFrame());
-                       InputStream in = new ByteArrayInputStream(latestFrame);
+                       //InputStream in = new ByteArrayInputStream(latestFrame);
+                       InputStream in = new ByteArrayInputStream(newImg);
                        img = ImageIO.read(in);
 
                } catch (RemoteException e) {
@@ -281,7 +284,9 @@ class MotionDetection implements CameraCallback {
                latestImage = img;              // image into image buffer
 
                // timestamp from camera into timestamp buffer
-               long dateLong = timeStamp;
+               //long dateLong = timeStamp;
+               long dateLong = _camera.getTimestamp();
+               //System.out.println("dateLong: " + dateLong + " - newImage size: " + newImg.length);
                possibleDate = new Date(dateLong);
 
                imageWriteLock.unlock();        // Never forget to unlock
@@ -367,13 +372,16 @@ class MotionDetection implements CameraCallback {
 
                // calculate the percentage of the image that was in motion
                double percentMotion = (countMotion / count) * 100.0;
+               System.out.println("countMotion: " + countMotion);
+               System.out.println("count: " + count);
+               System.out.println("Percent motion: " + percentMotion);
 
                // Check if a high enough percentage of the image was in motion to say that there was motion in this frame of data
                if (percentMotion > MOTION_DETECTED_THRESHOLD_PERCENTAGE) {
 
                        // Motion detected so save timestamp of this frame to another buffer
                        timestampWriteLock.lock();
-                       timestampOfLastMotion = (Date)tmpDate.clone();                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          // clone to a different buffer
+                       timestampOfLastMotion = (Date)tmpDate.clone();// clone to a different buffer
                        timestampWriteLock.unlock();
 
                        System.out.println("Motion Detected (with percentage: " + Double.toString(percentMotion) + "%)");
index 71bcc3f..b1e7b41 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;
 
 public class RoomSmart_Stub implements RoomSmart {
 
-       private IoTRMICall rmiCall;
-       private String callbackAddress;
-       private int[] ports;
-
-       private final static int objectId = 0;
+       private int objectId = 2;
+       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;
        }
 
index fbb295b..38edcff 100644 (file)
@@ -139,8 +139,8 @@ void LifxLightBulb::init() {
        //              NOTE: "this" pointer is passed into the detached thread because it does not belong
        //                      to this object anymore so if it executes certain methods of "this" object, then it needs
        //                      the correct references to stuff
-//     thread th1 (&LifxLightBulb::workerFunction, this, this);
-//     th1.detach();
+       thread th1 (&LifxLightBulb::workerFunction, this, this);
+       th1.detach();
 
        //cout << "Initialized LifxLightBulb!" << endl;
        log << "Initialized LifxLightBulb!" << endl;
@@ -403,6 +403,8 @@ void LifxLightBulb::workerFunction(LifxLightBulb* llb) {
        int64_t lastSentGetBulbVersionRequest = 0;      // time last request sent
        char dat[1024];
 
+       llb->log << "Turning off and entering while loop!" << endl;
+
        while (true) {
                // Check if we got the bulb version yet
                // could have requested it but message could have gotten lost (UDP)
@@ -1217,7 +1219,7 @@ void adjustBright(LifxLightBulb *llb) {
 }
 
 
-/*int main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
        string macAddress1 = "D073D5128E300000";
        //string macAddress = "D073D50241DA0000";
@@ -1241,4 +1243,4 @@ void adjustBright(LifxLightBulb *llb) {
 //     delete llb1;
 
        return 0;
-}*/
+}
index 686089f..7d2bb47 100644 (file)
@@ -464,7 +464,8 @@ public class AmcrestCamera implements Camera {
 
                                for (CameraSmartCallback c : callbackList) {
 
-                                       c.newCameraFrameAvailable(this.getLatestFrame(), this.getTimestamp());
+                                       //c.newCameraFrameAvailable(this.getLatestFrame(), this.getTimestamp());
+                                       c.newCameraFrameAvailable(this);
                                }
                        } else {
 
diff --git a/benchmarks/drivers/Java/AmcrestCamera/CameraSmartCallback_CallbackStub.java b/benchmarks/drivers/Java/AmcrestCamera/CameraSmartCallback_CallbackStub.java
deleted file mode 100644 (file)
index 5913de2..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-package iotcode.AmcrestCamera;
-
-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 iotcode.interfaces.*;
-
-public class CameraSmartCallback_CallbackStub implements CameraSmartCallback {
-
-       private IoTRMICall rmiCall;
-       private String callbackAddress;
-       private int[] ports;
-
-       private int objectId = 0;
-       
-
-       public CameraSmartCallback_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
-               callbackAddress = _callbackAddress;
-               objectId = _objectId;
-               rmiCall = _rmiCall;
-               ports = _ports;
-       }
-
-       public void newCameraFrameAvailable(byte latestFrame[], long timeStamp) {
-               int methodId = 0;
-               Class<?> retType = void.class;
-               Class<?>[] paramCls = new Class<?>[] { byte[].class, long.class };
-               Object[] paramObj = new Object[] { latestFrame, timeStamp };
-               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
-       }
-
-}
diff --git a/benchmarks/drivers/Java/AmcrestCamera/CameraSmartCallback_Stub.java b/benchmarks/drivers/Java/AmcrestCamera/CameraSmartCallback_Stub.java
new file mode 100644 (file)
index 0000000..f5270a2
--- /dev/null
@@ -0,0 +1,79 @@
+package iotcode.AmcrestCamera;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+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.*;
+
+public class CameraSmartCallback_Stub implements CameraSmartCallback {
+
+       private int objectId = 0;
+       private IoTRMIComm rmiComm;
+       // Synchronization variables
+       
+
+       public CameraSmartCallback_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);
+               }
+               IoTRMIUtil.mapStub.put(objectId, this);
+       }
+
+       public CameraSmartCallback_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+       }
+
+       public void newCameraFrameAvailable(Camera _camera) {
+               int[] objIdSent0 = new int[1];
+               try {
+                       if (!IoTRMIUtil.mapSkel.containsKey(_camera)) {
+                               int newObjIdSent = rmiComm.getObjectIdCounter();
+                               objIdSent0[0] = newObjIdSent;
+                               rmiComm.decrementObjectIdCounter();
+                               Camera_Skeleton skel0 = new Camera_Skeleton(_camera, rmiComm, newObjIdSent);
+                               IoTRMIUtil.mapSkel.put(_camera, skel0);
+                               IoTRMIUtil.mapSkelId.put(_camera, newObjIdSent);
+                               Thread thread = new Thread() {
+                                       public void run() {
+                                               try {
+                                                       skel0.___waitRequestInvokeMethod();
+                                                       } catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                                       throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for Camera_Skeleton!");
+                                               }
+                                       }
+                               };
+                               thread.start();
+                               while(!skel0.didAlreadyInitWaitInvoke());
+                       }
+                       else
+                       {
+                               int newObjIdSent = IoTRMIUtil.mapSkelId.get(_camera);
+                               objIdSent0[0] = newObjIdSent;
+                       }
+               } catch (Exception ex) {
+                       ex.printStackTrace();
+                       throw new Error("Exception when generating skeleton objects!");
+               }
+
+               int methodId = 0;
+               Class<?> retType = void.class;
+               Class<?>[] paramCls = new Class<?>[] { int[].class };
+               Object[] paramObj = new Object[] { objIdSent0 };
+               rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+       }
+
+}
index e0daeec..cbb98bf 100644 (file)
@@ -4,33 +4,66 @@ 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.*;
 
 public class Camera_Skeleton implements Camera {
 
        private Camera mainObj;
-       private IoTRMIObject rmiObj;
-
-       private String callbackAddress;
-       private static int objIdCnt = 0;
-       private IoTRMICall rmiCall;
-       private int[] ports;
-
+       private int objectId = 0;
+       // Communications and synchronizations
+       private IoTRMIComm rmiComm;
+       private AtomicBoolean didAlreadyInitWaitInvoke;
+       private AtomicBoolean methodReceived;
+       private byte[] methodBytes = null;
+       // Permissions
        private final static int object0Id = 0; //CameraSmart
        private static Integer[] object0Permission = { 8, 7, 9, 6, 2, 1, 4, 3, 0, 10, 5 };
        private static List<Integer> set0Allowed;
        
 
-       public Camera_Skeleton(Camera _mainObj, String _callbackAddress, int _port) throws Exception {
+       public Camera_Skeleton(Camera _mainObj, int _portSend, int _portRecv) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               IoTRMIUtil.mapSkel.put(_mainObj, this);
+               IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+               Thread thread1 = new Thread() {
+                       public void run() {
+                               try {
+                                       ___waitRequestInvokeMethod();
+                               }
+                               catch (Exception ex)
+                               {
+                                       ex.printStackTrace();
+                               }
+                       }
+               };
+               thread1.start();
+       }
+
+       public Camera_Skeleton(Camera _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
                mainObj = _mainObj;
-               callbackAddress = _callbackAddress;
-               rmiObj = new IoTRMIObject(_port);
+               rmiComm = _rmiComm;
+               objectId = _objectId;
                set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
-               set0Allowed.add(-9998);
-               ___waitRequestInvokeMethod();
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+       }
+
+       public boolean didAlreadyInitWaitInvoke() {
+               return didAlreadyInitWaitInvoke.get();
        }
 
        public void init() {
@@ -77,47 +110,47 @@ public class Camera_Skeleton implements Camera {
                mainObj.registerCallback(_callbackTo);
        }
 
-       public void ___regCB() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class, String.class, int.class },new Class<?>[] { null, null, null });
-               ports = (int[]) paramObj[0];
-               rmiCall = new IoTRMICall(ports[0], (String) paramObj[1], (int) paramObj[2]);
-       }
-
        public void ___init() {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                init();
        }
 
        public void ___start() {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                start();
        }
 
        public void ___stop() {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                stop();
        }
 
        public void ___getLatestFrame() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                Object retObj = getLatestFrame();
-               rmiObj.sendReturnObj(retObj);
+               rmiComm.sendReturnObj(retObj, localMethodBytes);
        }
 
        public void ___getTimestamp() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                Object retObj = getTimestamp();
-               rmiObj.sendReturnObj(retObj);
+               rmiComm.sendReturnObj(retObj, localMethodBytes);
        }
 
        public void ___getSupportedResolutions() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                List<Resolution> retEnum = getSupportedResolutions();
                int retLen = retEnum.size();
                int[] retEnumVal = new int[retLen];
@@ -125,46 +158,62 @@ public class Camera_Skeleton implements Camera {
                        retEnumVal[i] = retEnum.get(i).ordinal();
                }
                Object retObj = retEnumVal;
-               rmiObj.sendReturnObj(retObj);
+               rmiComm.sendReturnObj(retObj, localMethodBytes);
        }
 
        public void ___setResolution() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class }, 
-               new Class<?>[] { null });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
                int paramInt0[] = (int[]) paramObj[0];
                Resolution[] enumVals = Resolution.values();
                Resolution paramEnum0 = enumVals[paramInt0[0]];
                Object retObj = setResolution(paramEnum0);
-               rmiObj.sendReturnObj(retObj);
+               rmiComm.sendReturnObj(retObj, localMethodBytes);
        }
 
        public void ___setFPS() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-               new Class<?>[] { null });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null }, localMethodBytes);
                Object retObj = setFPS((int) paramObj[0]);
-               rmiObj.sendReturnObj(retObj);
+               rmiComm.sendReturnObj(retObj, localMethodBytes);
        }
 
        public void ___getMaxFPS() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                Object retObj = getMaxFPS();
-               rmiObj.sendReturnObj(retObj);
+               rmiComm.sendReturnObj(retObj, localMethodBytes);
        }
 
        public void ___getMinFPS() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                Object retObj = getMinFPS();
-               rmiObj.sendReturnObj(retObj);
+               rmiComm.sendReturnObj(retObj, localMethodBytes);
        }
 
        public void ___registerCallback() {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-               new Class<?>[] { null });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
                try {
-                       CameraSmartCallback stub0 = new CameraSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
-                       objIdCnt++;
+                       int[] stubIdArray0 = (int[]) paramObj[0];
+                       int objIdRecv0 = stubIdArray0[0];
+                       CameraSmartCallback newStub0 = null;
+                       if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
+                               newStub0 = new CameraSmartCallback_Stub(rmiComm, objIdRecv0);
+                               IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
+                               rmiComm.setObjectIdCounter(objIdRecv0);
+                               rmiComm.decrementObjectIdCounter();
+                       }
+                       else {
+                               newStub0 = (CameraSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
+                       }
+                       CameraSmartCallback stub0 = newStub0;
                        registerCallback(stub0);
                } catch(Exception ex) {
                        ex.printStackTrace();
@@ -172,32 +221,157 @@ public class Camera_Skeleton implements Camera {
                }
        }
 
-       private void ___waitRequestInvokeMethod() throws IOException {
+       public void ___waitRequestInvokeMethod() throws IOException {
+               didAlreadyInitWaitInvoke.compareAndSet(false, true);
                while (true) {
-                       rmiObj.getMethodBytes();
-                       int _objectId = rmiObj.getObjectId();
-                       int methodId = rmiObj.getMethodId();
-                       if (_objectId == object0Id) {
+                       if (!methodReceived.get()) {
+                               continue;
+                       }
+                       methodBytes = rmiComm.getMethodBytes();
+                       methodReceived.set(false);
+                       int _objectId = IoTRMIComm.getObjectId(methodBytes);
+                       int methodId = IoTRMIComm.getMethodId(methodBytes);
+                       if (_objectId == objectId) {
                                if (!set0Allowed.contains(methodId)) {
                                        throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
                                }
                        }
                        else {
-                               throw new Error("Object Id: " + _objectId + " not recognized!");
+                               continue;
                        }
                        switch (methodId) {
-                               case 0: ___init(); break;
-                               case 1: ___start(); break;
-                               case 2: ___stop(); break;
-                               case 3: ___getLatestFrame(); break;
-                               case 4: ___getTimestamp(); break;
-                               case 5: ___getSupportedResolutions(); break;
-                               case 6: ___setResolution(); break;
-                               case 7: ___setFPS(); break;
-                               case 8: ___getMaxFPS(); break;
-                               case 9: ___getMinFPS(); break;
-                               case 10: ___registerCallback(); break;
-                               case -9998: ___regCB(); break;
+                               case 0:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___init();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 1:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___start();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 2:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___stop();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 3:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___getLatestFrame();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 4:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___getTimestamp();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 5:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___getSupportedResolutions();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 6:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___setResolution();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 7:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___setFPS();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 8:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___getMaxFPS();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 9:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___getMinFPS();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
+                               case 10:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___registerCallback();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
                                default: 
                                throw new Error("Method Id " + methodId + " not recognized!");
                        }
index 04da3ed..015af4a 100644 (file)
@@ -4,28 +4,66 @@ 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.Room;
 
 public class Room_Skeleton implements Room {
 
        private Room mainObj;
-       private IoTRMIObject rmiObj;
-
-       private String callbackAddress;
+       private int objectId = 2;
+       // Communications and synchronizations
+       private IoTRMIComm rmiComm;
+       private AtomicBoolean didAlreadyInitWaitInvoke;
+       private AtomicBoolean methodReceived;
+       private byte[] methodBytes = null;
+       // Permissions
        private final static int object0Id = 0; //RoomSmart
        private static Integer[] object0Permission = { 0 };
        private static List<Integer> set0Allowed;
        
 
-       public Room_Skeleton(Room _mainObj, String _callbackAddress, int _port) throws Exception {
+       public Room_Skeleton(Room _mainObj, int _portSend, int _portRecv) throws Exception {
                mainObj = _mainObj;
-               callbackAddress = _callbackAddress;
-               rmiObj = new IoTRMIObject(_port);
+               rmiComm = new IoTRMICommServer(_portSend, _portRecv);
                set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
-               ___waitRequestInvokeMethod();
+               IoTRMIUtil.mapSkel.put(_mainObj, this);
+               IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+               Thread thread1 = new Thread() {
+                       public void run() {
+                               try {
+                                       ___waitRequestInvokeMethod();
+                               }
+                               catch (Exception ex)
+                               {
+                                       ex.printStackTrace();
+                               }
+                       }
+               };
+               thread1.start();
+       }
+
+       public Room_Skeleton(Room _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
+               mainObj = _mainObj;
+               rmiComm = _rmiComm;
+               objectId = _objectId;
+               set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+               didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+               methodReceived = new AtomicBoolean(false);
+               rmiComm.registerSkeleton(objectId, methodReceived);
+       }
+
+       public boolean didAlreadyInitWaitInvoke() {
+               return didAlreadyInitWaitInvoke.get();
        }
 
        public int getRoomID() {
@@ -33,27 +71,44 @@ public class Room_Skeleton implements Room {
        }
 
        public void ___getRoomID() throws IOException {
-               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
-               new Class<?>[] {  });
+               byte[] localMethodBytes = methodBytes;
+               rmiComm.setGetMethodBytes();
+               Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
                Object retObj = getRoomID();
-               rmiObj.sendReturnObj(retObj);
+               rmiComm.sendReturnObj(retObj, localMethodBytes);
        }
 
-       private void ___waitRequestInvokeMethod() throws IOException {
+       public void ___waitRequestInvokeMethod() throws IOException {
+               didAlreadyInitWaitInvoke.compareAndSet(false, true);
                while (true) {
-                       rmiObj.getMethodBytes();
-                       int _objectId = rmiObj.getObjectId();
-                       int methodId = rmiObj.getMethodId();
-                       if (_objectId == object0Id) {
+                       if (!methodReceived.get()) {
+                               continue;
+                       }
+                       methodBytes = rmiComm.getMethodBytes();
+                       methodReceived.set(false);
+                       int _objectId = IoTRMIComm.getObjectId(methodBytes);
+                       int methodId = IoTRMIComm.getMethodId(methodBytes);
+                       if (_objectId == objectId) {
                                if (!set0Allowed.contains(methodId)) {
                                        throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
                                }
                        }
                        else {
-                               throw new Error("Object Id: " + _objectId + " not recognized!");
+                               continue;
                        }
                        switch (methodId) {
-                               case 0: ___getRoomID(); break;
+                               case 0:
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       ___getRoomID();
+                                               }
+                                               catch (Exception ex) {
+                                                       ex.printStackTrace();
+                                               }
+                                       }
+                               }.start();
+                               break;
                                default: 
                                throw new Error("Method Id " + methodId + " not recognized!");
                        }
index 8e77dd5..af9d817 100644 (file)
@@ -17,7 +17,7 @@ import iotcode.interfaces.LightBulb;
 public class LightBulb_Skeleton implements LightBulb {
 
        private LightBulb mainObj;
-       private int objectId = 0;
+       private int objectId = 1;
        // Communications and synchronizations
        private IoTRMIComm rmiComm;
        private AtomicBoolean didAlreadyInitWaitInvoke;
index 583c126..d7b225c 100644 (file)
@@ -1,5 +1,6 @@
 package iotcode.interfaces;
 
 public interface CameraCallback {
-       public void newCameraFrameAvailable(byte latestFrame[], long timeStamp);
+       //public void newCameraFrameAvailable(byte latestFrame[], long timeStamp);
+       public void newCameraFrameAvailable(CameraSmart _camera);
 }
index 6c584cf..1f10ecb 100644 (file)
@@ -2,5 +2,6 @@ package iotcode.interfaces;
 
 public interface CameraSmartCallback {
 
-       public void newCameraFrameAvailable(byte latestFrame[], long timeStamp);
+       //public void newCameraFrameAvailable(byte latestFrame[], long timeStamp);
+       public void newCameraFrameAvailable(Camera _camera);
 }
index 6d74c11..40c2436 100644 (file)
@@ -47,8 +47,8 @@ PHONY += run-compiler-room
 run-compiler-room:
        cp ../localconfig/iotpolicy/Room/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/Room/*.req $(BIN_DIR)/iotpolicy/
-       #cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler room.pol roomsmart.req -java Java
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler room.pol roomsmart.req -cplus C++
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler room.pol roomsmart.req -java Java
+       #cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler room.pol roomsmart.req -cplus C++
 
 PHONY += run-compiler-cam
 run-compiler-cam:
index 16f84cb..b3cc9f5 100644 (file)
@@ -95,7 +95,7 @@ public abstract class IoTRMIComm {
                                        // Take the current method from the queue and wake up the correct thread
                                        retValueBytes = returnQueue.poll();
                                        if (retValueBytes != null) {    // If there is method bytes
-                                               System.out.println("retValBytes in wake up thread: " + Arrays.toString(retValueBytes));
+                                               //System.out.println("retValBytes in wake up thread: " + Arrays.toString(retValueBytes));
                                                int objectId = getObjectId(retValueBytes);
                                                int methodId = getMethodId(retValueBytes);
                                                String strKey = objectId + "-" + methodId;
@@ -401,11 +401,23 @@ public abstract class IoTRMIComm {
                // Receive return value and return it to caller
                // Now just strip off the object ID and method ID
                int headerLen = IoTRMIUtil.OBJECT_ID_LEN + IoTRMIUtil.METHOD_ID_LEN + IoTRMIUtil.PACKET_TYPE_LEN;
+               //if (retValueBytes == null)
+               //      System.out.println("retValueBytes is null!");
+
                int valByteLen = retValueBytes.length - headerLen;
                byte[] retValBytes = new byte[valByteLen];
                // Method Id is positioned after object Id in the byte array
-               System.arraycopy(retValueBytes, headerLen, retValBytes, 0, valByteLen);
-               Object retObj = IoTRMIUtil.getParamObject(retType, retGenTypeVal, retValBytes);
+
+               //System.out.println("Val byte len: " + valByteLen);
+               //System.out.println("Length retValBytes: " + retValBytes.length);
+
+               //System.arraycopy(retValueBytes, headerLen, retValBytes, 0, valByteLen);
+               //Object retObj = IoTRMIUtil.getParamObject(retType, retGenTypeVal, retValBytes);
+               Object retObj = null;
+               if (valByteLen != 0) {
+                       System.arraycopy(retValueBytes, headerLen, retValBytes, 0, valByteLen);
+                       retObj = IoTRMIUtil.getParamObject(retType, retGenTypeVal, retValBytes);
+               }
                // This means the right object and method have gotten the return value, so we set this back to false
                return retObj;
        }
index bf2f7c1..3f61ba5 100644 (file)
@@ -73,10 +73,10 @@ public class IoTRMICommClient extends IoTRMIComm {
                                                if (packetBytes != null) {
                                                        int packetType = IoTRMIComm.getPacketType(packetBytes);
                                                        if (packetType == IoTRMIUtil.METHOD_TYPE) {
-                                                               System.out.println("Method packet: " + Arrays.toString(packetBytes));
+                                                               //System.out.println("Method packet: " + Arrays.toString(packetBytes));
                                                                methodQueue.offer(packetBytes);
                                                        } else if (packetType == IoTRMIUtil.RET_VAL_TYPE) {
-                                                               System.out.println("Return value packet: " + Arrays.toString(packetBytes));
+                                                               //System.out.println("Return value packet: " + Arrays.toString(packetBytes));
                                                                returnQueue.offer(packetBytes);
                                                        } else
                                                                throw new Error("IoTRMICommClient: Packet type is unknown: " + packetType);
@@ -100,18 +100,27 @@ public class IoTRMICommClient extends IoTRMIComm {
        public synchronized void sendReturnObj(Object retObj, byte[] methodBytes) {
 
                // Send back return value
-               byte[] retObjBytes = IoTRMIUtil.getObjectBytes(retObj);
+               //byte[] retObjBytes = IoTRMIUtil.getObjectBytes(retObj);
+               byte[] retObjBytes = null;
+               if (retObj != null)     // Handle nullness
+                       retObjBytes = IoTRMIUtil.getObjectBytes(retObj);
                // Send return value together with OBJECT_ID and METHOD_ID for arbitration
                int objMethIdLen = IoTRMIUtil.OBJECT_ID_LEN + IoTRMIUtil.METHOD_ID_LEN;
                int headerLen = objMethIdLen + IoTRMIUtil.PACKET_TYPE_LEN;
-               byte[] retAllBytes = new byte[headerLen + retObjBytes.length];
+               //byte[] retAllBytes = new byte[headerLen + retObjBytes.length];
+               byte[] retAllBytes = null;
+               if (retObj == null)     // Handle nullness
+                       retAllBytes = new byte[headerLen];
+               else
+                       retAllBytes = new byte[headerLen + retObjBytes.length];
                // Copy OBJECT_ID and METHOD_ID
                System.arraycopy(methodBytes, 0, retAllBytes, 0, objMethIdLen);
                int packetType = IoTRMIUtil.RET_VAL_TYPE;       // This is a return value
                byte[] packetTypeBytes = IoTRMIUtil.intToByteArray(packetType);
                System.arraycopy(packetTypeBytes, 0, retAllBytes, objMethIdLen, IoTRMIUtil.PACKET_TYPE_LEN);
                // Copy array of bytes (return object)
-               System.arraycopy(retObjBytes, 0, retAllBytes, headerLen, retObjBytes.length);
+               if (retObj != null)
+                       System.arraycopy(retObjBytes, 0, retAllBytes, headerLen, retObjBytes.length);
                try {
                        rmiClientSend.sendBytes(retAllBytes);
                } catch (IOException ex) {
index 6668745..f8cffa4 100644 (file)
@@ -106,13 +106,13 @@ public class IoTRMICommServer extends IoTRMIComm {
                                        try {
                                                packetBytes = rmiServerRecv.receiveBytes(packetBytes);
                                                if (packetBytes != null) {
-                                                       System.out.println("Packet received: " + Arrays.toString(packetBytes));
+                                                       //System.out.println("Packet received: " + Arrays.toString(packetBytes));
                                                        int packetType = IoTRMIComm.getPacketType(packetBytes);
                                                        if (packetType == IoTRMIUtil.METHOD_TYPE) {
-                                                               System.out.println("Method packet: " + Arrays.toString(packetBytes));
+                                                               //System.out.println("Method packet: " + Arrays.toString(packetBytes));
                                                                methodQueue.offer(packetBytes);
                                                        } else if (packetType == IoTRMIUtil.RET_VAL_TYPE) {
-                                                               System.out.println("Return value packet: " + Arrays.toString(packetBytes));
+                                                               //System.out.println("Return value packet: " + Arrays.toString(packetBytes));
                                                                returnQueue.offer(packetBytes);
                                                        } else
                                                                throw new Error("IoTRMICommServer: Packet type is unknown: " + packetType);
@@ -136,18 +136,27 @@ public class IoTRMICommServer extends IoTRMIComm {
        public synchronized void sendReturnObj(Object retObj, byte[] methodBytes) {
 
                // Send back return value
-               byte[] retObjBytes = IoTRMIUtil.getObjectBytes(retObj);
+               //byte[] retObjBytes = IoTRMIUtil.getObjectBytes(retObj);
+               byte[] retObjBytes = null;
+               if (retObj != null)     // Handle nullness
+                       retObjBytes = IoTRMIUtil.getObjectBytes(retObj);
                // Send return value together with OBJECT_ID and METHOD_ID for arbitration
                int objMethIdLen = IoTRMIUtil.OBJECT_ID_LEN + IoTRMIUtil.METHOD_ID_LEN;
                int headerLen = objMethIdLen + IoTRMIUtil.PACKET_TYPE_LEN;
-               byte[] retAllBytes = new byte[headerLen + retObjBytes.length];
+               //byte[] retAllBytes = new byte[headerLen + retObjBytes.length];
+               byte[] retAllBytes = null;
+               if (retObj == null)     // Handle nullness
+                       retAllBytes = new byte[headerLen];
+               else
+                       retAllBytes = new byte[headerLen + retObjBytes.length];
                // Copy OBJECT_ID and METHOD_ID
                System.arraycopy(methodBytes, 0, retAllBytes, 0, objMethIdLen);
                int packetType = IoTRMIUtil.RET_VAL_TYPE;       // This is a return value
                byte[] packetTypeBytes = IoTRMIUtil.intToByteArray(packetType);
                System.arraycopy(packetTypeBytes, 0, retAllBytes, objMethIdLen, IoTRMIUtil.PACKET_TYPE_LEN);
                // Copy array of bytes (return object)
-               System.arraycopy(retObjBytes, 0, retAllBytes, headerLen, retObjBytes.length);
+               if (retObj != null)
+                       System.arraycopy(retObjBytes, 0, retAllBytes, headerLen, retObjBytes.length);
                try {
                        rmiServerSend.sendBytes(retAllBytes);
                } catch (IOException ex) {
index 2cdb258..789c566 100644 (file)
@@ -72,15 +72,15 @@ public abstract class IoTSocket {
                ByteBuffer bb = ByteBuffer.allocate(MSG_LEN_SIZE);
                bb.putInt(len);
                output.write(bb.array(), 0, MSG_LEN_SIZE);
-               System.out.println("Sender about to send: " + Arrays.toString(bb.array()));
+               //System.out.println("Sender about to send: " + Arrays.toString(bb.array()));
                output.flush();
                // Write the byte array
                output.write(vals, 0, len);
-               System.out.println("Sender sending: " + len);
+               //System.out.println("Sender sending: " + len);
                output.flush();
-               System.out.println("Sender about to receive ACK!");
+               //System.out.println("Sender about to receive ACK!");
                receiveAck();
-               System.out.println("Sender about to send ACK!\n\n");
+               //System.out.println("Sender about to send ACK!\n\n");
                sendAck();
        }
 
@@ -99,13 +99,13 @@ public abstract class IoTSocket {
                        return null;
                }
 
-               System.out.println("Receiver about to receive: " + input.available());
+               //System.out.println("Receiver about to receive: " + input.available());
                // Read the maxlen first - read 4 bytes here
                byte[] lenBytes = new byte[MSG_LEN_SIZE];
                input.read(lenBytes, 0, MSG_LEN_SIZE);
-               System.out.println("Receiver lenBytes: " + Arrays.toString(lenBytes));
+               //System.out.println("Receiver lenBytes: " + Arrays.toString(lenBytes));
                int maxlen = ByteBuffer.wrap(lenBytes).getInt();
-               System.out.println("Receiver received length: " + maxlen);
+               //System.out.println("Receiver received length: " + maxlen);
                // Receive until maxlen
                if (maxlen>BUFFSIZE) {
                        System.out.println("IoTSocketClient/Server: Sending more bytes then will fit in buffer! Number of bytes: " + maxlen);
@@ -128,9 +128,9 @@ public abstract class IoTSocket {
                }
                // we now send an acknowledgement to the server to let them
                // know we've got it
-               System.out.println("Receiver about to send ACK!");
+               //System.out.println("Receiver about to send ACK!");
                sendAck();
-               System.out.println("Receiver about to receive ACK!\n\n");
+               //System.out.println("Receiver about to receive ACK!\n\n");
                receiveAck();
 
                return val;