+package HomeSecurityController;
+
+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 SmartthingsSensorCallback_Skeleton implements SmartthingsSensorCallback {
+
+ private SmartthingsSensorCallback 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 SmartthingsSensorCallback_Skeleton(SmartthingsSensorCallback _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 SmartthingsSensorCallback_Skeleton(SmartthingsSensorCallback _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 newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
+ mainObj.newReadingAvailable(_sensorId, _value, _activeValue);
+ }
+
+ public void ___newReadingAvailable() {
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class, int.class, boolean.class }, new Class<?>[] { null, null, null }, localMethodBytes);
+ newReadingAvailable((int) paramObj[0], (int) paramObj[1], (boolean) 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 (!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 {
+ ___newReadingAvailable();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ default:
+ throw new Error("Method Id " + methodId + " not recognized!");
+ }
+ }
+ }
+
+}