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);
+++ /dev/null
-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!");
- }
- }
-
-}
--- /dev/null
+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!");
+ }
+ }
+ }
+
+}
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() {
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;
}
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;
}
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;
}
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;
}
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() {
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() {
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;
}
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;
}
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!");
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() {
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;
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() {
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() {
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;
}
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() {
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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() {
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() {
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;
}
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;
}
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);
}
}
*
* @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) {
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
// 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) + "%)");
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() {
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;
}
// 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;
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)
}
-/*int main(int argc, char *argv[])
+int main(int argc, char *argv[])
{
string macAddress1 = "D073D5128E300000";
//string macAddress = "D073D50241DA0000";
// delete llb1;
return 0;
-}*/
+}
for (CameraSmartCallback c : callbackList) {
- c.newCameraFrameAvailable(this.getLatestFrame(), this.getTimestamp());
+ //c.newCameraFrameAvailable(this.getLatestFrame(), this.getTimestamp());
+ c.newCameraFrameAvailable(this);
}
} else {
+++ /dev/null
-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);
- }
-
-}
--- /dev/null
+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);
+ }
+
+}
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() {
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];
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();
}
}
- 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!");
}
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() {
}
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!");
}
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;
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);
}
public interface CameraSmartCallback {
- public void newCameraFrameAvailable(byte latestFrame[], long timeStamp);
+ //public void newCameraFrameAvailable(byte latestFrame[], long timeStamp);
+ public void newCameraFrameAvailable(Camera _camera);
}
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:
// 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;
// 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;
}
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);
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) {
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);
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) {
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();
}
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);
}
// 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;