+++ /dev/null
-package IrrigationController;
-
-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 IrrigationController;
+
+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 = 3;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object3Permission = { 0 };
+ private static List<Integer> set3Allowed;
+
+
+ public CameraCallback_Skeleton(CameraCallback _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
+ 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;
+ set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
+ didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+ methodReceived = new AtomicBoolean(false);
+ rmiComm.registerSkeleton(objectId, methodReceived);
+ }
+
+ public boolean didAlreadyInitWaitInvoke() {
+ return didAlreadyInitWaitInvoke.get();
+ }
+
+ public void newCameraFrameAvailable(byte latestFrame[], long timeStamp) {
+ mainObj.newCameraFrameAvailable(latestFrame, timeStamp);
+ }
+
+ public void ___newCameraFrameAvailable() {
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { byte[].class, long.class }, new Class<?>[] { null, null }, localMethodBytes);
+ newCameraFrameAvailable((byte[]) paramObj[0], (long) paramObj[1]);
+ }
+
+ 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 (!set3Allowed.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();
+ }
+ }
+ }.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 = 2;
+ 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.*;
public class LawnSmart_Stub implements LawnSmart {
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private final static int objectId = 0;
+ private int objectId = 1;
+ private IoTRMIComm rmiComm;
+ // Synchronization variables
- public LawnSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
- callbackAddress = _callbackAddress;
- ports = _ports;
- rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
+ public LawnSmart_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 LawnSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ rmiComm = _rmiComm;
+ objectId = _objectId;
}
}
+++ /dev/null
-package IrrigationController;
-
-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 MoistureSensorCallback_CallbackSkeleton implements MoistureSensorCallback {
-
- private MoistureSensorCallback mainObj;
- private int objectId = 0;
- private String callbackAddress;
-
-
- public MoistureSensorCallback_CallbackSkeleton(MoistureSensorCallback _mainObj, String _callbackAddress, int _objectId) throws Exception {
- callbackAddress = _callbackAddress;
- mainObj = _mainObj;
- objectId = _objectId;
- }
-
- public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading) {
- mainObj.newReadingAvailable(sensorId, moisture, timeStampOfLastReading);
- }
-
- public void ___newReadingAvailable(IoTRMIObject rmiObj) {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, float.class, long.class },
- new Class<?>[] { null, null, null });
- newReadingAvailable((int) paramObj[0], (float) paramObj[1], (long) paramObj[2]);
- }
-
- public void invokeMethod(IoTRMIObject rmiObj) throws IOException {
- int methodId = rmiObj.getMethodId();
- switch (methodId) {
- case 0: ___newReadingAvailable(rmiObj); break;
- default:
- throw new Error("Method Id " + methodId + " not recognized!");
- }
- }
-
-}
--- /dev/null
+package IrrigationController;
+
+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 MoistureSensorCallback_Skeleton implements MoistureSensorCallback {
+
+ private MoistureSensorCallback mainObj;
+ private int objectId = 6;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object6Permission = { 0 };
+ private static List<Integer> set6Allowed;
+
+
+ public MoistureSensorCallback_Skeleton(MoistureSensorCallback _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set6Allowed = new ArrayList<Integer>(Arrays.asList(object6Permission));
+ 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 MoistureSensorCallback_Skeleton(MoistureSensorCallback _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set6Allowed = new ArrayList<Integer>(Arrays.asList(object6Permission));
+ didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+ methodReceived = new AtomicBoolean(false);
+ rmiComm.registerSkeleton(objectId, methodReceived);
+ }
+
+ public boolean didAlreadyInitWaitInvoke() {
+ return didAlreadyInitWaitInvoke.get();
+ }
+
+ public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading) {
+ mainObj.newReadingAvailable(sensorId, moisture, timeStampOfLastReading);
+ }
+
+ public void ___newReadingAvailable() {
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class, float.class, long.class }, new Class<?>[] { null, null, null }, localMethodBytes);
+ newReadingAvailable((int) paramObj[0], (float) paramObj[1], (long) paramObj[2]);
+ }
+
+ 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 (!set6Allowed.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 {
+ ___newReadingAvailable();
+ }
+ 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.*;
public class MoistureSensorSmart_Stub implements MoistureSensorSmart {
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private final static int objectId = 0;
- // Callback properties
- private IoTRMIObject rmiObj;
- List<MoistureSensorCallback> listCallbackObj;
- private int objIdCnt = 0;
- private final static int object0Id = 0; //MoistureSensorSmartCallback
- private static Integer[] object0Permission = { 0 };
- private static List<Integer> set0Allowed;
+ private int objectId = 5;
+ private IoTRMIComm rmiComm;
+ // Synchronization variables
+ private AtomicBoolean retValueReceived2 = new AtomicBoolean(false);
+ private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
+ private AtomicBoolean retValueReceived1 = new AtomicBoolean(false);
- public MoistureSensorSmart_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<MoistureSensorCallback>();
- set0Allowed.add(-9999);
- ___initCallBack();
+ public MoistureSensorSmart_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, 2, retValueReceived2);
+ rmiComm.registerStub(objectId, 4, retValueReceived4);
+ rmiComm.registerStub(objectId, 1, retValueReceived1);
+ IoTRMIUtil.mapStub.put(objectId, this);
+ }
+
+ public MoistureSensorSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ rmiComm.registerStub(objectId, 2, retValueReceived2);
+ rmiComm.registerStub(objectId, 4, retValueReceived4);
+ rmiComm.registerStub(objectId, 1, retValueReceived1);
}
public long getTimestampOfLastReading() {
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 (!retValueReceived2.get());
+ Object retObj = rmiComm.getReturnValue(retType, null);
+ retValueReceived2.set(false);
+ rmiComm.setGetReturnBytes();
+
return (long)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 (!retValueReceived4.get());
+ Object retObj = rmiComm.getReturnValue(retType, null);
+ retValueReceived4.set(false);
+ rmiComm.setGetReturnBytes();
+
return (int)retObj;
}
public void registerCallback(MoistureSensorCallback _callbackTo) {
+ int[] objIdSent0 = new int[1];
try {
- MoistureSensorCallback_CallbackSkeleton skel0 = new MoistureSensorCallback_CallbackSkeleton(_callbackTo, callbackAddress, objIdCnt++);
- listCallbackObj.add(skel0);
+ if (!IoTRMIUtil.mapSkel.containsKey(_callbackTo)) {
+ int newObjIdSent = rmiComm.getObjectIdCounter();
+ objIdSent0[0] = newObjIdSent;
+ rmiComm.decrementObjectIdCounter();
+ MoistureSensorCallback_Skeleton skel0 = new MoistureSensorCallback_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 MoistureSensorCallback_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 = 5;
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);
- MoistureSensorCallback_CallbackSkeleton skel = (MoistureSensorCallback_CallbackSkeleton) listCallbackObj.get(objId);
- if (skel != null) {
- int methodId = IoTRMIObject.getMethodId(method);
- if (!set0Allowed.contains(methodId)) {
- throw new Error("Callback object for MoistureSensorCallback is not allowed to access method: " + methodId);
- }
- skel.invokeMethod(rmiObj);
- } else {
- throw new Error("MoistureSensorCallback: Object with Id " + objId + " not found!");
- }
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- throw new Error("Error instantiating class MoistureSensorCallback_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 float getMoisture() {
Class<?> retType = float.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 (!retValueReceived1.get());
+ Object retObj = rmiComm.getReturnValue(retType, null);
+ retValueReceived1.set(false);
+ rmiComm.setGetReturnBytes();
+
return (float)retObj;
}
Class<?> retType = void.class;
Class<?>[] paramCls = new Class<?>[] { int.class };
Object[] paramObj = new Object[] { id };
- 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);
}
}
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 SprinklerSmart_Stub implements SprinklerSmart {
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private final static int objectId = 0;
+ private int objectId = 6;
+ private IoTRMIComm rmiComm;
+ // Synchronization variables
+ private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
+ private AtomicBoolean retValueReceived2 = new AtomicBoolean(false);
+ private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
- public SprinklerSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
- callbackAddress = _callbackAddress;
- ports = _ports;
- rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
+ public SprinklerSmart_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, 4, retValueReceived4);
+ rmiComm.registerStub(objectId, 2, retValueReceived2);
+ rmiComm.registerStub(objectId, 3, retValueReceived3);
+ IoTRMIUtil.mapStub.put(objectId, this);
+ }
+
+ public SprinklerSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ rmiComm.registerStub(objectId, 4, retValueReceived4);
+ rmiComm.registerStub(objectId, 2, retValueReceived2);
+ rmiComm.registerStub(objectId, 3, retValueReceived3);
}
public boolean doesHaveZoneTimers() {
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 (!retValueReceived4.get());
+ Object retObj = rmiComm.getReturnValue(retType, null);
+ retValueReceived4.set(false);
+ rmiComm.setGetReturnBytes();
+
return (boolean)retObj;
}
Class<?> retType = int.class;
Class<?>[] paramCls = new Class<?>[] { };
Object[] paramObj = new Object[] { };
- Object retLenObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- int retLen = (int) retLenObj;
+ rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+ // Waiting for return value
+ while (!retValueReceived2.get());
+ Object retObj = rmiComm.getReturnValue(retType, null);
+ retValueReceived2.set(false);
+ rmiComm.setGetReturnBytes();
+
+ int retLen = (int) retObj;
Class<?>[] retCls = new Class<?>[3*retLen];
Class<?>[] retClsVal = new Class<?>[3*retLen];
int retPos = 0;
retCls[retPos] = int.class;
retClsVal[retPos++] = null;
}
- Object[] retObj = rmiCall.getStructObjects(retCls, retClsVal);
+ // Waiting for return value
+ while (!retValueReceived2.get());
+ Object[] retActualObj = rmiComm.getStructObjects(retCls, retClsVal);
+ retValueReceived2.set(false);
+ rmiComm.setGetReturnBytes();
+
List<ZoneState> structRet = new ArrayList<ZoneState>();
int retObjPos = 0;
for(int i = 0; i < retLen; i++) {
ZoneState structRetMem = new ZoneState();
- structRetMem.zoneNumber = (int) retObj[retObjPos++];
- structRetMem.onOffState = (boolean) retObj[retObjPos++];
- structRetMem.duration = (int) retObj[retObjPos++];
+ structRetMem.zoneNumber = (int) retActualObj[retObjPos++];
+ structRetMem.onOffState = (boolean) retActualObj[retObjPos++];
+ structRetMem.duration = (int) retActualObj[retObjPos++];
structRet.add(structRetMem);
}
return structRet;
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 setZone(int _zone, boolean _onOff, int _onDurationSeconds) {
Class<?> retType = void.class;
Class<?>[] paramCls = new Class<?>[] { int.class, boolean.class, int.class };
Object[] paramObj = new Object[] { _zone, _onOff, _onDurationSeconds };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+ rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
}
public int getNumberOfZones() {
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 (!retValueReceived3.get());
+ Object retObj = rmiComm.getReturnValue(retType, null);
+ retValueReceived3.set(false);
+ rmiComm.setGetReturnBytes();
+
return (int)retObj;
}
+++ /dev/null
-package IrrigationController;
-
-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 WeatherGatewayCallback_CallbackSkeleton implements WeatherGatewayCallback {
-
- private WeatherGatewayCallback mainObj;
- private int objectId = 0;
- private String callbackAddress;
-
-
- public WeatherGatewayCallback_CallbackSkeleton(WeatherGatewayCallback _mainObj, String _callbackAddress, int _objectId) throws Exception {
- callbackAddress = _callbackAddress;
- mainObj = _mainObj;
- objectId = _objectId;
- }
-
- public void informationRetrieved(double _inchesPerWeek, int _weatherZipCode, int _daysToWaterOn, double _inchesPerMinute) {
- mainObj.informationRetrieved(_inchesPerWeek, _weatherZipCode, _daysToWaterOn, _inchesPerMinute);
- }
-
- public void ___informationRetrieved(IoTRMIObject rmiObj) {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { double.class, int.class, int.class, double.class },
- new Class<?>[] { null, null, null, null });
- informationRetrieved((double) paramObj[0], (int) paramObj[1], (int) paramObj[2], (double) paramObj[3]);
- }
-
- public void invokeMethod(IoTRMIObject rmiObj) throws IOException {
- int methodId = rmiObj.getMethodId();
- switch (methodId) {
- case 0: ___informationRetrieved(rmiObj); break;
- default:
- throw new Error("Method Id " + methodId + " not recognized!");
- }
- }
-
-}
--- /dev/null
+package IrrigationController;
+
+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 WeatherGatewayCallback_Skeleton implements WeatherGatewayCallback {
+
+ private WeatherGatewayCallback mainObj;
+ private int objectId = 4;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object4Permission = { 0 };
+ private static List<Integer> set4Allowed;
+
+
+ public WeatherGatewayCallback_Skeleton(WeatherGatewayCallback _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
+ 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 WeatherGatewayCallback_Skeleton(WeatherGatewayCallback _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
+ didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+ methodReceived = new AtomicBoolean(false);
+ rmiComm.registerSkeleton(objectId, methodReceived);
+ }
+
+ public boolean didAlreadyInitWaitInvoke() {
+ return didAlreadyInitWaitInvoke.get();
+ }
+
+ public void informationRetrieved(double _inchesPerWeek, int _weatherZipCode, int _daysToWaterOn, double _inchesPerMinute) {
+ mainObj.informationRetrieved(_inchesPerWeek, _weatherZipCode, _daysToWaterOn, _inchesPerMinute);
+ }
+
+ public void ___informationRetrieved() {
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { double.class, int.class, int.class, double.class }, new Class<?>[] { null, null, null, null }, localMethodBytes);
+ informationRetrieved((double) paramObj[0], (int) paramObj[1], (int) paramObj[2], (double) paramObj[3]);
+ }
+
+ 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 (!set4Allowed.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 {
+ ___informationRetrieved();
+ }
+ 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.*;
public class WeatherGatewaySmart_Stub implements WeatherGatewaySmart {
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private final static int objectId = 0;
- // Callback properties
- private IoTRMIObject rmiObj;
- List<WeatherGatewayCallback> listCallbackObj;
- private int objIdCnt = 0;
- private final static int object0Id = 0; //WeatherGatewaySmartCallback
- private static Integer[] object0Permission = { 0 };
- private static List<Integer> set0Allowed;
+ private int objectId = 3;
+ private IoTRMIComm rmiComm;
+ // Synchronization variables
+ private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
+ private AtomicBoolean retValueReceived6 = new AtomicBoolean(false);
+ private AtomicBoolean retValueReceived5 = new AtomicBoolean(false);
+ private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
- public WeatherGatewaySmart_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<WeatherGatewayCallback>();
- set0Allowed.add(-9999);
- ___initCallBack();
+ public WeatherGatewaySmart_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, 3, retValueReceived3);
+ rmiComm.registerStub(objectId, 6, retValueReceived6);
+ rmiComm.registerStub(objectId, 5, retValueReceived5);
+ rmiComm.registerStub(objectId, 4, retValueReceived4);
+ IoTRMIUtil.mapStub.put(objectId, this);
+ }
+
+ public WeatherGatewaySmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ rmiComm.registerStub(objectId, 3, retValueReceived3);
+ rmiComm.registerStub(objectId, 6, retValueReceived6);
+ rmiComm.registerStub(objectId, 5, retValueReceived5);
+ rmiComm.registerStub(objectId, 4, retValueReceived4);
}
public double getInchesPerWeek() {
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 (!retValueReceived3.get());
+ Object retObj = rmiComm.getReturnValue(retType, null);
+ retValueReceived3.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 (!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 (!retValueReceived5.get());
+ Object retObj = rmiComm.getReturnValue(retType, null);
+ retValueReceived5.set(false);
+ rmiComm.setGetReturnBytes();
+
return (int)retObj;
}
public void registerCallback(WeatherGatewayCallback _callbackTo) {
+ int[] objIdSent0 = new int[1];
try {
- WeatherGatewayCallback_CallbackSkeleton skel0 = new WeatherGatewayCallback_CallbackSkeleton(_callbackTo, callbackAddress, objIdCnt++);
- listCallbackObj.add(skel0);
+ if (!IoTRMIUtil.mapSkel.containsKey(_callbackTo)) {
+ int newObjIdSent = rmiComm.getObjectIdCounter();
+ objIdSent0[0] = newObjIdSent;
+ rmiComm.decrementObjectIdCounter();
+ WeatherGatewayCallback_Skeleton skel0 = new WeatherGatewayCallback_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 WeatherGatewayCallback_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 = 7;
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);
- WeatherGatewayCallback_CallbackSkeleton skel = (WeatherGatewayCallback_CallbackSkeleton) listCallbackObj.get(objId);
- if (skel != null) {
- int methodId = IoTRMIObject.getMethodId(method);
- if (!set0Allowed.contains(methodId)) {
- throw new Error("Callback object for WeatherGatewayCallback is not allowed to access method: " + methodId);
- }
- skel.invokeMethod(rmiObj);
- } else {
- throw new Error("WeatherGatewayCallback: Object with Id " + objId + " not found!");
- }
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- throw new Error("Error instantiating class WeatherGatewayCallback_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 void stop() {
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 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 int getWeatherZipCode() {
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 (!retValueReceived4.get());
+ Object retObj = rmiComm.getReturnValue(retType, null);
+ retValueReceived4.set(false);
+ rmiComm.setGetReturnBytes();
+
return (int)retObj;
}
+++ /dev/null
-package SpeakerController;
-
-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 GPSGatewayCallback_CallbackSkeleton implements GPSGatewayCallback {
-
- private GPSGatewayCallback mainObj;
- private int objectId = 0;
- private String callbackAddress;
-
-
- public GPSGatewayCallback_CallbackSkeleton(GPSGatewayCallback _mainObj, String _callbackAddress, int _objectId) throws Exception {
- callbackAddress = _callbackAddress;
- mainObj = _mainObj;
- objectId = _objectId;
- }
-
- public void newRoomIDRetrieved(int _roomIdentifier) {
- mainObj.newRoomIDRetrieved(_roomIdentifier);
- }
-
- public void newRingStatusRetrieved(boolean _ringStatus) {
- mainObj.newRingStatusRetrieved(_ringStatus);
- }
-
- public void ___newRoomIDRetrieved(IoTRMIObject rmiObj) {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
- new Class<?>[] { null });
- newRoomIDRetrieved((int) paramObj[0]);
- }
-
- public void ___newRingStatusRetrieved(IoTRMIObject rmiObj) {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { boolean.class },
- new Class<?>[] { null });
- newRingStatusRetrieved((boolean) paramObj[0]);
- }
-
- public void invokeMethod(IoTRMIObject rmiObj) throws IOException {
- int methodId = rmiObj.getMethodId();
- switch (methodId) {
- case 0: ___newRoomIDRetrieved(rmiObj); break;
- case 1: ___newRingStatusRetrieved(rmiObj); break;
- default:
- throw new Error("Method Id " + methodId + " not recognized!");
- }
- }
-
-}
+++ /dev/null
-package SpeakerController;
-
-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 SpeakerCallback_CallbackSkeleton implements SpeakerCallback {
-
- private SpeakerCallback mainObj;
- private int objectId = 0;
- private String callbackAddress;
-
-
- public SpeakerCallback_CallbackSkeleton(SpeakerCallback _mainObj, String _callbackAddress, int _objectId) throws Exception {
- callbackAddress = _callbackAddress;
- mainObj = _mainObj;
- objectId = _objectId;
- }
-
- public void speakerDone() {
- mainObj.speakerDone();
- }
-
- public void ___speakerDone(IoTRMIObject rmiObj) {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
- speakerDone();
- }
-
- public void invokeMethod(IoTRMIObject rmiObj) throws IOException {
- int methodId = rmiObj.getMethodId();
- switch (methodId) {
- case 0: ___speakerDone(rmiObj); 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 final static int object0Id = 0; //RoomSmart
- private static Integer[] object0Permission = { 0 };
- private static List<Integer> set0Allowed;
+ private int objectId = 4;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object4Permission = { 0 };
+ private static List<Integer> set4Allowed;
- public Room_Skeleton(Room _mainObj, String _callbackAddress, int _port) throws Exception {
+ public Room_Skeleton(Room _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
+ 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;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- ___waitRequestInvokeMethod();
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
+ 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 (!set0Allowed.contains(methodId)) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
+ if (!set4Allowed.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!");
}
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 Sprinkler_Skeleton implements Sprinkler {
private Sprinkler mainObj;
- private IoTRMIObject rmiObj;
-
- private String callbackAddress;
- private final static int object0Id = 0; //SprinklerSmart
- private static Integer[] object0Permission = { 4, 2, 0, 1, 3 };
- private static List<Integer> set0Allowed;
+ private int objectId = 6;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object2Permission = { 4, 2, 0, 1, 3 };
+ private static List<Integer> set2Allowed;
- public Sprinkler_Skeleton(Sprinkler _mainObj, String _callbackAddress, int _port) throws Exception {
+ public Sprinkler_Skeleton(Sprinkler _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
+ 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 Sprinkler_Skeleton(Sprinkler _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
mainObj = _mainObj;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- ___waitRequestInvokeMethod();
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
+ didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+ methodReceived = new AtomicBoolean(false);
+ rmiComm.registerSkeleton(objectId, methodReceived);
+ }
+
+ public boolean didAlreadyInitWaitInvoke() {
+ return didAlreadyInitWaitInvoke.get();
}
public void init() {
}
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 ___setZone() {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, boolean.class, int.class },
- new Class<?>[] { null, null, null });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class, boolean.class, int.class }, new Class<?>[] { null, null, null }, localMethodBytes);
setZone((int) paramObj[0], (boolean) paramObj[1], (int) paramObj[2]);
}
public void ___getZoneStates() 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<ZoneState> retStruct = getZoneStates();
int retLen = retStruct.size();
Object retLenObj = retLen;
- rmiObj.sendReturnObj(retLenObj);
+ rmiComm.sendReturnObj(retLenObj, localMethodBytes);
Class<?>[] retCls = new Class<?>[3*retLen];
Object[] retObj = new Object[3*retLen];
int retPos = 0;
retCls[retPos] = int.class;
retObj[retPos++] = retStruct.get(i).duration;
}
- rmiObj.sendReturnObj(retCls, retObj);
+ rmiComm.sendReturnObj(retCls, retObj, localMethodBytes);
}
public void ___getNumberOfZones() 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 = getNumberOfZones();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___doesHaveZoneTimers() 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 = doesHaveZoneTimers();
- 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 (!set0Allowed.contains(methodId)) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
+ if (!set2Allowed.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: ___setZone(); break;
- case 2: ___getZoneStates(); break;
- case 3: ___getNumberOfZones(); break;
- case 4: ___doesHaveZoneTimers(); 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 {
+ ___setZone();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 2:
+ new Thread() {
+ public void run() {
+ try {
+ ___getZoneStates();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 3:
+ new Thread() {
+ public void run() {
+ try {
+ ___getNumberOfZones();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 4:
+ new Thread() {
+ public void run() {
+ try {
+ ___doesHaveZoneTimers();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
default:
throw new Error("Method Id " + methodId + " not recognized!");
}
+++ /dev/null
-package iotcode.GPSPhoneGateway;
-
-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 GPSGatewaySmartCallback_CallbackStub implements GPSGatewaySmartCallback {
-
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private int objectId = 0;
-
-
- public GPSGatewaySmartCallback_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
- callbackAddress = _callbackAddress;
- objectId = _objectId;
- rmiCall = _rmiCall;
- ports = _ports;
- }
-
- public void newRoomIDRetrieved(int _roomIdentifier) {
- int methodId = 0;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { int.class };
- Object[] paramObj = new Object[] { _roomIdentifier };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
- public void newRingStatusRetrieved(boolean _ringStatus) {
- int methodId = 1;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { boolean.class };
- Object[] paramObj = new Object[] { _ringStatus };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
-}
--- /dev/null
+package iotcode.GPSPhoneGateway;
+
+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 GPSGatewaySmartCallback_Stub implements GPSGatewaySmartCallback {
+
+ private int objectId = 4;
+ private IoTRMIComm rmiComm;
+ // Synchronization variables
+
+
+ public GPSGatewaySmartCallback_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 GPSGatewaySmartCallback_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ }
+
+ public void newRoomIDRetrieved(int _roomIdentifier) {
+ int methodId = 0;
+ Class<?> retType = void.class;
+ Class<?>[] paramCls = new Class<?>[] { int.class };
+ Object[] paramObj = new Object[] { _roomIdentifier };
+ rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
+ }
+
+ public void newRingStatusRetrieved(boolean _ringStatus) {
+ int methodId = 1;
+ Class<?> retType = void.class;
+ Class<?>[] paramCls = new Class<?>[] { boolean.class };
+ Object[] paramObj = new Object[] { _ringStatus };
+ 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 GPSGateway_Skeleton implements GPSGateway {
private GPSGateway mainObj;
- private IoTRMIObject rmiObj;
-
- private String callbackAddress;
- private int objIdCnt = 0;
- private IoTRMICall rmiCall;
- private int[] ports;
-
- private final static int object0Id = 0; //GPSGatewaySmart
- private static Integer[] object0Permission = { 5, 6, 2, 1, 0, 3, 7, 4 };
- private static List<Integer> set0Allowed;
+ private int objectId = 3;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object3Permission = { 5, 6, 2, 1, 0, 3, 7, 4 };
+ private static List<Integer> set3Allowed;
- public GPSGateway_Skeleton(GPSGateway _mainObj, String _callbackAddress, int _port) throws Exception {
+ public GPSGateway_Skeleton(GPSGateway _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
+ 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 GPSGateway_Skeleton(GPSGateway _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
mainObj = _mainObj;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- set0Allowed.add(-9998);
- ___waitRequestInvokeMethod();
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
+ 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 ___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);
}
public void ___getRingStatus() 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 = getRingStatus();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___setNewRoomIDAvailable() {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { boolean.class },
- new Class<?>[] { null });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { boolean.class }, new Class<?>[] { null }, localMethodBytes);
setNewRoomIDAvailable((boolean) paramObj[0]);
}
public void ___setNewRingStatusAvailable() {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { boolean.class },
- new Class<?>[] { null });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { boolean.class }, new Class<?>[] { null }, localMethodBytes);
setNewRingStatusAvailable((boolean) paramObj[0]);
}
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 {
- GPSGatewaySmartCallback stub0 = new GPSGatewaySmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
- objIdCnt++;
+ int[] stubIdArray0 = (int[]) paramObj[0];
+ int objIdRecv0 = stubIdArray0[0];
+ GPSGatewaySmartCallback newStub0 = null;
+ if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
+ newStub0 = new GPSGatewaySmartCallback_Stub(rmiComm, objIdRecv0);
+ IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
+ rmiComm.setObjectIdCounter(objIdRecv0);
+ rmiComm.decrementObjectIdCounter();
+ }
+ else {
+ newStub0 = (GPSGatewaySmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
+ }
+ GPSGatewaySmartCallback 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 (!set0Allowed.contains(methodId)) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
+ if (!set3Allowed.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: ___getRoomID(); break;
- case 4: ___getRingStatus(); break;
- case 5: ___setNewRoomIDAvailable(); break;
- case 6: ___setNewRingStatusAvailable(); break;
- case 7: ___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 {
+ ___getRoomID();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 4:
+ new Thread() {
+ public void run() {
+ try {
+ ___getRingStatus();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 5:
+ new Thread() {
+ public void run() {
+ try {
+ ___setNewRoomIDAvailable();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 6:
+ new Thread() {
+ public void run() {
+ try {
+ ___setNewRingStatusAvailable();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 7:
+ 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.*;
public class Lawn_Skeleton implements Lawn {
private Lawn mainObj;
- private IoTRMIObject rmiObj;
-
- private String callbackAddress;
- private final static int object0Id = 0; //LawnSmart
- private static Integer[] object0Permission = { };
- private static List<Integer> set0Allowed;
+ private int objectId = 1;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object1Permission = { };
+ private static List<Integer> set1Allowed;
- public Lawn_Skeleton(Lawn _mainObj, String _callbackAddress, int _port) throws Exception {
+ public Lawn_Skeleton(Lawn _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
+ 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 Lawn_Skeleton(Lawn _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
mainObj = _mainObj;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- ___waitRequestInvokeMethod();
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
+ didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+ methodReceived = new AtomicBoolean(false);
+ rmiComm.registerSkeleton(objectId, methodReceived);
}
- private void ___waitRequestInvokeMethod() throws IOException {
+ public boolean didAlreadyInitWaitInvoke() {
+ return didAlreadyInitWaitInvoke.get();
+ }
+
+ 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 (!set0Allowed.contains(methodId)) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
+ if (!set1Allowed.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) {
default:
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 final static int object0Id = 0; //RoomSmart
- private static Integer[] object0Permission = { 0 };
- private static List<Integer> set0Allowed;
+ private int objectId = 4;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object4Permission = { 0 };
+ private static List<Integer> set4Allowed;
- public Room_Skeleton(Room _mainObj, String _callbackAddress, int _port) throws Exception {
+ public Room_Skeleton(Room _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
+ 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;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- ___waitRequestInvokeMethod();
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
+ 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 (!set0Allowed.contains(methodId)) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
+ if (!set4Allowed.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!");
}
+++ /dev/null
-package iotcode.IHome;
-
-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 SpeakerSmartCallback_CallbackStub implements SpeakerSmartCallback {
-
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private int objectId = 0;
-
-
- public SpeakerSmartCallback_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
- callbackAddress = _callbackAddress;
- objectId = _objectId;
- rmiCall = _rmiCall;
- ports = _ports;
- }
-
- public void speakerDone() {
- int methodId = 0;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { };
- Object[] paramObj = new Object[] { };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
-}
--- /dev/null
+package iotcode.IHome;
+
+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 SpeakerSmartCallback_Stub implements SpeakerSmartCallback {
+
+ private int objectId = 2;
+ private IoTRMIComm rmiComm;
+ // Synchronization variables
+
+
+ public SpeakerSmartCallback_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 SpeakerSmartCallback_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ }
+
+ public void speakerDone() {
+ int methodId = 0;
+ Class<?> retType = void.class;
+ Class<?>[] paramCls = new Class<?>[] { };
+ Object[] paramObj = new Object[] { };
+ 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 Speaker_Skeleton implements Speaker {
private Speaker mainObj;
- private IoTRMIObject rmiObj;
-
- private String callbackAddress;
- private int objIdCnt = 0;
- private IoTRMICall rmiCall;
- private int[] ports;
-
- private final static int object0Id = 0; //SpeakerSmart
- private static Integer[] object0Permission = { 6, 2, 9, 1, 3, 4, 5, 7, 8, 0, 10 };
- private static List<Integer> set0Allowed;
+ private int objectId = 1;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object1Permission = { 6, 2, 9, 1, 3, 4, 5, 7, 8, 0, 10 };
+ private static List<Integer> set1Allowed;
- public Speaker_Skeleton(Speaker _mainObj, String _callbackAddress, int _port) throws Exception {
+ public Speaker_Skeleton(Speaker _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
+ 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 Speaker_Skeleton(Speaker _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
mainObj = _mainObj;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- set0Allowed.add(-9998);
- ___waitRequestInvokeMethod();
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
+ didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+ methodReceived = new AtomicBoolean(false);
+ rmiComm.registerSkeleton(objectId, methodReceived);
+ }
+
+ public boolean didAlreadyInitWaitInvoke() {
+ return didAlreadyInitWaitInvoke.get();
}
public void init() {
mainObj.registerCallback(_cb);
}
- 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 ___startPlayback() 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 = startPlayback();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___stopPlayback() 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 = stopPlayback();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getPlaybackState() 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 = getPlaybackState();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___setVolume() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { float.class },
- new Class<?>[] { null });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { float.class }, new Class<?>[] { null }, localMethodBytes);
Object retObj = setVolume((float) paramObj[0]);
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getVolume() 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 = getVolume();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getPosition() 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 = getPosition();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___setPosition() {
- 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);
setPosition((int) paramObj[0]);
}
public void ___loadData() {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { short[].class, int.class, int.class },
- new Class<?>[] { null, null, null });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { short[].class, int.class, int.class }, new Class<?>[] { null, null, null }, localMethodBytes);
loadData((short[]) paramObj[0], (int) paramObj[1], (int) paramObj[2]);
}
public void ___clearData() {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
clearData();
}
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 {
- SpeakerSmartCallback stub0 = new SpeakerSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
- objIdCnt++;
+ int[] stubIdArray0 = (int[]) paramObj[0];
+ int objIdRecv0 = stubIdArray0[0];
+ SpeakerSmartCallback newStub0 = null;
+ if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
+ newStub0 = new SpeakerSmartCallback_Stub(rmiComm, objIdRecv0);
+ IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
+ rmiComm.setObjectIdCounter(objIdRecv0);
+ rmiComm.decrementObjectIdCounter();
+ }
+ else {
+ newStub0 = (SpeakerSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
+ }
+ SpeakerSmartCallback 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 (!set0Allowed.contains(methodId)) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
+ if (!set1Allowed.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: ___startPlayback(); break;
- case 2: ___stopPlayback(); break;
- case 3: ___getPlaybackState(); break;
- case 4: ___setVolume(); break;
- case 5: ___getVolume(); break;
- case 6: ___getPosition(); break;
- case 7: ___setPosition(); break;
- case 8: ___loadData(); break;
- case 9: ___clearData(); 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 {
+ ___startPlayback();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 2:
+ new Thread() {
+ public void run() {
+ try {
+ ___stopPlayback();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 3:
+ new Thread() {
+ public void run() {
+ try {
+ ___getPlaybackState();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 4:
+ new Thread() {
+ public void run() {
+ try {
+ ___setVolume();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 5:
+ new Thread() {
+ public void run() {
+ try {
+ ___getVolume();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 6:
+ new Thread() {
+ public void run() {
+ try {
+ ___getPosition();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 7:
+ new Thread() {
+ public void run() {
+ try {
+ ___setPosition();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 8:
+ new Thread() {
+ public void run() {
+ try {
+ ___loadData();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 9:
+ new Thread() {
+ public void run() {
+ try {
+ ___clearData();
+ }
+ 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!");
}
+++ /dev/null
-package iotcode.MotionSensor;
-
-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 SmartthingsSensorSmartCallback_CallbackStub implements SmartthingsSensorSmartCallback {
-
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private int objectId = 0;
-
-
- public SmartthingsSensorSmartCallback_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
- callbackAddress = _callbackAddress;
- objectId = _objectId;
- rmiCall = _rmiCall;
- ports = _ports;
- }
-
- public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
- int methodId = 0;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { int.class, int.class, boolean.class };
- Object[] paramObj = new Object[] { _sensorId, _value, _activeValue };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
-}
--- /dev/null
+package iotcode.MotionSensor;
+
+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 SmartthingsSensorSmartCallback_Stub implements SmartthingsSensorSmartCallback {
+
+ private int objectId = 3;
+ private IoTRMIComm rmiComm;
+ // Synchronization variables
+
+
+ public SmartthingsSensorSmartCallback_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 SmartthingsSensorSmartCallback_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ }
+
+ public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
+ int methodId = 0;
+ Class<?> retType = void.class;
+ Class<?>[] paramCls = new Class<?>[] { int.class, int.class, boolean.class };
+ Object[] paramObj = new Object[] { _sensorId, _value, _activeValue };
+ 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 SmartthingsSensor_Skeleton implements SmartthingsSensor {
private SmartthingsSensor mainObj;
- private IoTRMIObject rmiObj;
-
- private String callbackAddress;
- private int objIdCnt = 0;
- private IoTRMICall rmiCall;
- private int[] ports;
-
- private final static int object0Id = 0; //SmartthingsSensorSmart
- private static Integer[] object0Permission = { 3, 2, 5, 6, 1, 4, 0 };
- private static List<Integer> set0Allowed;
+ private int objectId = 2;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object2Permission = { 3, 2, 5, 6, 1, 4, 0 };
+ private static List<Integer> set2Allowed;
- public SmartthingsSensor_Skeleton(SmartthingsSensor _mainObj, String _callbackAddress, int _port) throws Exception {
+ public SmartthingsSensor_Skeleton(SmartthingsSensor _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
+ 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 SmartthingsSensor_Skeleton(SmartthingsSensor _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
mainObj = _mainObj;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- set0Allowed.add(-9998);
- ___waitRequestInvokeMethod();
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
+ 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 ___getValue() 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 = getValue();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___isActiveValue() 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 = isActiveValue();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getTimestampOfLastReading() 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 = getTimestampOfLastReading();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___setId() {
- 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);
setId((int) paramObj[0]);
}
public void ___getId() 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 = getId();
- 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 {
- SmartthingsSensorSmartCallback stub0 = new SmartthingsSensorSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
- objIdCnt++;
+ int[] stubIdArray0 = (int[]) paramObj[0];
+ int objIdRecv0 = stubIdArray0[0];
+ SmartthingsSensorSmartCallback newStub0 = null;
+ if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
+ newStub0 = new SmartthingsSensorSmartCallback_Stub(rmiComm, objIdRecv0);
+ IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
+ rmiComm.setObjectIdCounter(objIdRecv0);
+ rmiComm.decrementObjectIdCounter();
+ }
+ else {
+ newStub0 = (SmartthingsSensorSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
+ }
+ SmartthingsSensorSmartCallback 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 (!set0Allowed.contains(methodId)) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
+ if (!set2Allowed.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: ___getValue(); break;
- case 2: ___isActiveValue(); break;
- case 3: ___getTimestampOfLastReading(); break;
- case 4: ___setId(); break;
- case 5: ___getId(); break;
- case 6: ___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 {
+ ___getValue();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 2:
+ new Thread() {
+ public void run() {
+ try {
+ ___isActiveValue();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 3:
+ new Thread() {
+ public void run() {
+ try {
+ ___getTimestampOfLastReading();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 4:
+ new Thread() {
+ public void run() {
+ try {
+ ___setId();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 5:
+ new Thread() {
+ public void run() {
+ try {
+ ___getId();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 6:
+ new Thread() {
+ public void run() {
+ try {
+ ___registerCallback();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
default:
throw new Error("Method Id " + methodId + " not recognized!");
}
+++ /dev/null
-package iotcode.MultipurposeSensor;
-
-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 SmartthingsSensorSmartCallback_CallbackStub implements SmartthingsSensorSmartCallback {
-
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private int objectId = 0;
-
-
- public SmartthingsSensorSmartCallback_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
- callbackAddress = _callbackAddress;
- objectId = _objectId;
- rmiCall = _rmiCall;
- ports = _ports;
- }
-
- public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
- int methodId = 0;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { int.class, int.class, boolean.class };
- Object[] paramObj = new Object[] { _sensorId, _value, _activeValue };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
-}
--- /dev/null
+package iotcode.MultipurposeSensor;
+
+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 SmartthingsSensorSmartCallback_Stub implements SmartthingsSensorSmartCallback {
+
+ private int objectId = 3;
+ private IoTRMIComm rmiComm;
+ // Synchronization variables
+
+
+ public SmartthingsSensorSmartCallback_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 SmartthingsSensorSmartCallback_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ }
+
+ public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
+ int methodId = 0;
+ Class<?> retType = void.class;
+ Class<?>[] paramCls = new Class<?>[] { int.class, int.class, boolean.class };
+ Object[] paramObj = new Object[] { _sensorId, _value, _activeValue };
+ 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 SmartthingsSensor_Skeleton implements SmartthingsSensor {
private SmartthingsSensor mainObj;
- private IoTRMIObject rmiObj;
-
- private String callbackAddress;
- private int objIdCnt = 0;
- private IoTRMICall rmiCall;
- private int[] ports;
-
- private final static int object0Id = 0; //SmartthingsSensorSmart
- private static Integer[] object0Permission = { 3, 2, 5, 6, 1, 4, 0 };
- private static List<Integer> set0Allowed;
+ private int objectId = 2;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object2Permission = { 3, 2, 5, 6, 1, 4, 0 };
+ private static List<Integer> set2Allowed;
- public SmartthingsSensor_Skeleton(SmartthingsSensor _mainObj, String _callbackAddress, int _port) throws Exception {
+ public SmartthingsSensor_Skeleton(SmartthingsSensor _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
+ 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 SmartthingsSensor_Skeleton(SmartthingsSensor _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
mainObj = _mainObj;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- set0Allowed.add(-9998);
- ___waitRequestInvokeMethod();
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
+ 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 ___getValue() 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 = getValue();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___isActiveValue() 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 = isActiveValue();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getTimestampOfLastReading() 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 = getTimestampOfLastReading();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___setId() {
- 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);
setId((int) paramObj[0]);
}
public void ___getId() 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 = getId();
- 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 {
- SmartthingsSensorSmartCallback stub0 = new SmartthingsSensorSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
- objIdCnt++;
+ int[] stubIdArray0 = (int[]) paramObj[0];
+ int objIdRecv0 = stubIdArray0[0];
+ SmartthingsSensorSmartCallback newStub0 = null;
+ if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
+ newStub0 = new SmartthingsSensorSmartCallback_Stub(rmiComm, objIdRecv0);
+ IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
+ rmiComm.setObjectIdCounter(objIdRecv0);
+ rmiComm.decrementObjectIdCounter();
+ }
+ else {
+ newStub0 = (SmartthingsSensorSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
+ }
+ SmartthingsSensorSmartCallback 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 (!set0Allowed.contains(methodId)) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
+ if (!set2Allowed.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: ___getValue(); break;
- case 2: ___isActiveValue(); break;
- case 3: ___getTimestampOfLastReading(); break;
- case 4: ___setId(); break;
- case 5: ___getId(); break;
- case 6: ___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 {
+ ___getValue();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 2:
+ new Thread() {
+ public void run() {
+ try {
+ ___isActiveValue();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 3:
+ new Thread() {
+ public void run() {
+ try {
+ ___getTimestampOfLastReading();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 4:
+ new Thread() {
+ public void run() {
+ try {
+ ___setId();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 5:
+ new Thread() {
+ public void run() {
+ try {
+ ___getId();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 6:
+ new Thread() {
+ public void run() {
+ try {
+ ___registerCallback();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
default:
throw new Error("Method Id " + methodId + " not recognized!");
}
+++ /dev/null
-package iotcode.SpruceSensor;
-
-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 MoistureSensorSmartCallback_CallbackStub implements MoistureSensorSmartCallback {
-
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private int objectId = 0;
-
-
- public MoistureSensorSmartCallback_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
- callbackAddress = _callbackAddress;
- objectId = _objectId;
- rmiCall = _rmiCall;
- ports = _ports;
- }
-
- public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading) {
- int methodId = 0;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { int.class, float.class, long.class };
- Object[] paramObj = new Object[] { sensorId, moisture, timeStampOfLastReading };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
-}
--- /dev/null
+package iotcode.SpruceSensor;
+
+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 MoistureSensorSmartCallback_Stub implements MoistureSensorSmartCallback {
+
+ private int objectId = 6;
+ private IoTRMIComm rmiComm;
+ // Synchronization variables
+
+
+ public MoistureSensorSmartCallback_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 MoistureSensorSmartCallback_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ }
+
+ public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading) {
+ int methodId = 0;
+ Class<?> retType = void.class;
+ Class<?>[] paramCls = new Class<?>[] { int.class, float.class, long.class };
+ Object[] paramObj = new Object[] { sensorId, moisture, timeStampOfLastReading };
+ 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 MoistureSensor_Skeleton implements MoistureSensor {
private MoistureSensor mainObj;
- private IoTRMIObject rmiObj;
-
- private String callbackAddress;
- private int objIdCnt = 0;
- private IoTRMICall rmiCall;
- private int[] ports;
-
- private final static int object0Id = 0; //MoistureSensorSmart
- private static Integer[] object0Permission = { 2, 4, 5, 1, 3, 0 };
- private static List<Integer> set0Allowed;
+ private int objectId = 5;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object5Permission = { 2, 4, 5, 1, 3, 0 };
+ private static List<Integer> set5Allowed;
- public MoistureSensor_Skeleton(MoistureSensor _mainObj, String _callbackAddress, int _port) throws Exception {
+ public MoistureSensor_Skeleton(MoistureSensor _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set5Allowed = new ArrayList<Integer>(Arrays.asList(object5Permission));
+ 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 MoistureSensor_Skeleton(MoistureSensor _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
mainObj = _mainObj;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- set0Allowed.add(-9998);
- ___waitRequestInvokeMethod();
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set5Allowed = new ArrayList<Integer>(Arrays.asList(object5Permission));
+ 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 ___getMoisture() 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 = getMoisture();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getTimestampOfLastReading() 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 = getTimestampOfLastReading();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___setId() {
- 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);
setId((int) paramObj[0]);
}
public void ___getId() 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 = getId();
- 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 {
- MoistureSensorSmartCallback stub0 = new MoistureSensorSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
- objIdCnt++;
+ int[] stubIdArray0 = (int[]) paramObj[0];
+ int objIdRecv0 = stubIdArray0[0];
+ MoistureSensorSmartCallback newStub0 = null;
+ if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
+ newStub0 = new MoistureSensorSmartCallback_Stub(rmiComm, objIdRecv0);
+ IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
+ rmiComm.setObjectIdCounter(objIdRecv0);
+ rmiComm.decrementObjectIdCounter();
+ }
+ else {
+ newStub0 = (MoistureSensorSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
+ }
+ MoistureSensorSmartCallback 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 (!set0Allowed.contains(methodId)) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
+ if (!set5Allowed.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: ___getMoisture(); break;
- case 2: ___getTimestampOfLastReading(); break;
- case 3: ___setId(); break;
- case 4: ___getId(); break;
- case 5: ___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 {
+ ___getMoisture();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 2:
+ new Thread() {
+ public void run() {
+ try {
+ ___getTimestampOfLastReading();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 3:
+ new Thread() {
+ public void run() {
+ try {
+ ___setId();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 4:
+ new Thread() {
+ public void run() {
+ try {
+ ___getId();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 5:
+ new Thread() {
+ public void run() {
+ try {
+ ___registerCallback();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
default:
throw new Error("Method Id " + methodId + " not recognized!");
}
+++ /dev/null
-package iotcode.WaterLeakSensor;
-
-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 SmartthingsSensorSmartCallback_CallbackStub implements SmartthingsSensorSmartCallback {
-
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private int objectId = 0;
-
-
- public SmartthingsSensorSmartCallback_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
- callbackAddress = _callbackAddress;
- objectId = _objectId;
- rmiCall = _rmiCall;
- ports = _ports;
- }
-
- public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
- int methodId = 0;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { int.class, int.class, boolean.class };
- Object[] paramObj = new Object[] { _sensorId, _value, _activeValue };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
-}
--- /dev/null
+package iotcode.WaterLeakSensor;
+
+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 SmartthingsSensorSmartCallback_Stub implements SmartthingsSensorSmartCallback {
+
+ private int objectId = 3;
+ private IoTRMIComm rmiComm;
+ // Synchronization variables
+
+
+ public SmartthingsSensorSmartCallback_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 SmartthingsSensorSmartCallback_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ }
+
+ public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
+ int methodId = 0;
+ Class<?> retType = void.class;
+ Class<?>[] paramCls = new Class<?>[] { int.class, int.class, boolean.class };
+ Object[] paramObj = new Object[] { _sensorId, _value, _activeValue };
+ 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 SmartthingsSensor_Skeleton implements SmartthingsSensor {
private SmartthingsSensor mainObj;
- private IoTRMIObject rmiObj;
-
- private String callbackAddress;
- private int objIdCnt = 0;
- private IoTRMICall rmiCall;
- private int[] ports;
-
- private final static int object0Id = 0; //SmartthingsSensorSmart
- private static Integer[] object0Permission = { 3, 2, 5, 6, 1, 4, 0 };
- private static List<Integer> set0Allowed;
+ private int objectId = 2;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object2Permission = { 3, 2, 5, 6, 1, 4, 0 };
+ private static List<Integer> set2Allowed;
- public SmartthingsSensor_Skeleton(SmartthingsSensor _mainObj, String _callbackAddress, int _port) throws Exception {
+ public SmartthingsSensor_Skeleton(SmartthingsSensor _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
+ 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 SmartthingsSensor_Skeleton(SmartthingsSensor _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
mainObj = _mainObj;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- set0Allowed.add(-9998);
- ___waitRequestInvokeMethod();
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
+ 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 ___getValue() 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 = getValue();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___isActiveValue() 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 = isActiveValue();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getTimestampOfLastReading() 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 = getTimestampOfLastReading();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___setId() {
- 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);
setId((int) paramObj[0]);
}
public void ___getId() 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 = getId();
- 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 {
- SmartthingsSensorSmartCallback stub0 = new SmartthingsSensorSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
- objIdCnt++;
+ int[] stubIdArray0 = (int[]) paramObj[0];
+ int objIdRecv0 = stubIdArray0[0];
+ SmartthingsSensorSmartCallback newStub0 = null;
+ if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
+ newStub0 = new SmartthingsSensorSmartCallback_Stub(rmiComm, objIdRecv0);
+ IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
+ rmiComm.setObjectIdCounter(objIdRecv0);
+ rmiComm.decrementObjectIdCounter();
+ }
+ else {
+ newStub0 = (SmartthingsSensorSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
+ }
+ SmartthingsSensorSmartCallback 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 (!set0Allowed.contains(methodId)) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
+ if (!set2Allowed.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: ___getValue(); break;
- case 2: ___isActiveValue(); break;
- case 3: ___getTimestampOfLastReading(); break;
- case 4: ___setId(); break;
- case 5: ___getId(); break;
- case 6: ___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 {
+ ___getValue();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 2:
+ new Thread() {
+ public void run() {
+ try {
+ ___isActiveValue();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 3:
+ new Thread() {
+ public void run() {
+ try {
+ ___getTimestampOfLastReading();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 4:
+ new Thread() {
+ public void run() {
+ try {
+ ___setId();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 5:
+ new Thread() {
+ public void run() {
+ try {
+ ___getId();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 6:
+ new Thread() {
+ public void run() {
+ try {
+ ___registerCallback();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
default:
throw new Error("Method Id " + methodId + " not recognized!");
}
+++ /dev/null
-package iotcode.WeatherPhoneGateway;
-
-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 WeatherGatewaySmartCallback_CallbackStub implements WeatherGatewaySmartCallback {
-
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private int objectId = 0;
-
-
- public WeatherGatewaySmartCallback_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
- callbackAddress = _callbackAddress;
- objectId = _objectId;
- rmiCall = _rmiCall;
- ports = _ports;
- }
-
- public void informationRetrieved(double _inchesPerWeek, int _weatherZipCode, int _daysToWaterOn, double _inchesPerMinute) {
- int methodId = 0;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { double.class, int.class, int.class, double.class };
- Object[] paramObj = new Object[] { _inchesPerWeek, _weatherZipCode, _daysToWaterOn, _inchesPerMinute };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
-}
--- /dev/null
+package iotcode.WeatherPhoneGateway;
+
+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 WeatherGatewaySmartCallback_Stub implements WeatherGatewaySmartCallback {
+
+ private int objectId = 4;
+ private IoTRMIComm rmiComm;
+ // Synchronization variables
+
+
+ public WeatherGatewaySmartCallback_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 WeatherGatewaySmartCallback_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ }
+
+ public void informationRetrieved(double _inchesPerWeek, int _weatherZipCode, int _daysToWaterOn, double _inchesPerMinute) {
+ int methodId = 0;
+ Class<?> retType = void.class;
+ Class<?>[] paramCls = new Class<?>[] { double.class, int.class, int.class, double.class };
+ Object[] paramObj = new Object[] { _inchesPerWeek, _weatherZipCode, _daysToWaterOn, _inchesPerMinute };
+ 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 WeatherGateway_Skeleton implements WeatherGateway {
private WeatherGateway mainObj;
- private IoTRMIObject rmiObj;
-
- private String callbackAddress;
- private int objIdCnt = 0;
- private IoTRMICall rmiCall;
- private int[] ports;
-
- private final static int object0Id = 0; //WeatherGatewaySmart
- private static Integer[] object0Permission = { 3, 6, 5, 7, 2, 1, 0, 4 };
- private static List<Integer> set0Allowed;
+ private int objectId = 3;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
+ private static Integer[] object3Permission = { 3, 6, 5, 7, 2, 1, 0, 4 };
+ private static List<Integer> set3Allowed;
- public WeatherGateway_Skeleton(WeatherGateway _mainObj, String _callbackAddress, int _port) throws Exception {
+ public WeatherGateway_Skeleton(WeatherGateway _mainObj, int _portSend, int _portRecv) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
+ set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
+ 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 WeatherGateway_Skeleton(WeatherGateway _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
mainObj = _mainObj;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- set0Allowed.add(-9998);
- ___waitRequestInvokeMethod();
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
+ 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 ___getInchesPerWeek() 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 = getInchesPerWeek();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getWeatherZipCode() 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 = getWeatherZipCode();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getDaysToWaterOn() 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 = getDaysToWaterOn();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getInchesPerMinute() 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 = getInchesPerMinute();
- 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 {
- WeatherGatewaySmartCallback stub0 = new WeatherGatewaySmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
- objIdCnt++;
+ int[] stubIdArray0 = (int[]) paramObj[0];
+ int objIdRecv0 = stubIdArray0[0];
+ WeatherGatewaySmartCallback newStub0 = null;
+ if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
+ newStub0 = new WeatherGatewaySmartCallback_Stub(rmiComm, objIdRecv0);
+ IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
+ rmiComm.setObjectIdCounter(objIdRecv0);
+ rmiComm.decrementObjectIdCounter();
+ }
+ else {
+ newStub0 = (WeatherGatewaySmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
+ }
+ WeatherGatewaySmartCallback 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 (!set0Allowed.contains(methodId)) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
+ if (!set3Allowed.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: ___getInchesPerWeek(); break;
- case 4: ___getWeatherZipCode(); break;
- case 5: ___getDaysToWaterOn(); break;
- case 6: ___getInchesPerMinute(); break;
- case 7: ___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 {
+ ___getInchesPerWeek();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 4:
+ new Thread() {
+ public void run() {
+ try {
+ ___getWeatherZipCode();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 5:
+ new Thread() {
+ public void run() {
+ try {
+ ___getDaysToWaterOn();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 6:
+ new Thread() {
+ public void run() {
+ try {
+ ___getInchesPerMinute();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 7:
+ new Thread() {
+ public void run() {
+ try {
+ ___registerCallback();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
default:
throw new Error("Method Id " + methodId + " not recognized!");
}
cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler testclasspolicy_callbacks.pol testclassrequires_callbacks.pol callbackpolicy.pol callbackrequires.pol -cplus Cplus -java Java
#cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler testclasspolicy_callbacks_three.pol testclassrequires_callbacks_three.pol callbackpolicy.pol callbackrequires.pol callbackpolicy_two.pol callbackrequires_two.pol -cplus Cplus -java Java
-PHONY += run-compiler-smartlight
-run-compiler-smartlight:
- cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
- cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
- cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler lifxlightbulb.pol smartlightsbulb.req amcrestcamera.pol smartlightscam.req motiondetection.pol motiondetection.req room.pol roomsmart.req -java Java
-
+
PHONY += run-compiler-lbtest
run-compiler-lbtest:
cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler lifxlightbulb.pol lifxtest.req -cplus Cplus
# SmartLightsController
+PHONY += run-compiler-smartlight
+run-compiler-smartlight:
+ cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
+ cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
+ cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler lifxlightbulb.pol smartlightsbulb.req amcrestcamera.pol smartlightscam.req motiondetection.pol motiondetection.req room.pol roomsmart.req -java Java
+
PHONY += run-compiler-lifx
run-compiler-lifx:
cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler amcrestcamera.pol smartlightscam.req motiondetection.pol motiondetection.req -java Java
# IrrigationController
+PHONY += run-compiler-irrigation
+run-compiler-irrigation:
+ cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
+ cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
+ cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler greenlawn.pol smartlawn.req espsprinkler.pol smartsprinkler.req weatherphonegateway.pol smartweathergateway.req weathergatewaycallback.pol smartweathergatewaycallback.req sprucesensor.pol smartsensor.req moisturesensorcallback.pol moisturesensorcallback.req -java Java
+
PHONY += run-compiler-lawn
run-compiler-lawn:
cp ../localconfig/iotpolicy/GreenLawn/*.pol $(BIN_DIR)/iotpolicy/
cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler sprucesensor.pol smartsensor.req moisturesensorcallback.pol moisturesensorcallback.req -java Java
# SpeakerController
+PHONY += run-compiler-speaker
+run-compiler-speaker:
+ cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
+ cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
+ cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler ihome.pol smartspeaker.req speakercallback.pol smartspeakercallback.req gpsphonegateway.pol smartgpsgateway.req gpsgatewaycallback.pol smartgpsgatewaycallback.req -java Java
+
PHONY += run-compiler-spkr
run-compiler-spkr:
cp ../localconfig/iotpolicy/IHome/*.pol $(BIN_DIR)/iotpolicy/
cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler gpsphonegateway.pol smartgpsgateway.req gpsgatewaycallback.pol smartgpsgatewaycallback.req -java Java
# HomeSecurityController
+PHONY += run-compiler-homesec
+run-compiler-homesec:
+ cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
+ cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
+ cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler espalarm.pol smartalarm.req smartthingssensor.pol smartthingssensor.req smartthingssensorcallback.pol smartthingssensorcallback.req -java Java
+
PHONY += run-compiler-alarm
run-compiler-alarm:
cp ../localconfig/iotpolicy/EspAlarm/*.pol $(BIN_DIR)/iotpolicy/
MONITORING_HOST=74:da:38:68:72:8a
#Zigbee gateway information
-ZIGBEE_GATEWAY_ADDRESS=c0:4a:00:10:9c:b3
+#ZIGBEE_GATEWAY_ADDRESS=c0:4a:00:10:9c:b3
+ZIGBEE_GATEWAY_ADDRESS=74:da:38:0d:05:56
ZIGBEE_GATEWAY_PORT=5005
ZIGBEE_IOTMASTER_PORT=12345