1 package HomeSecurityController;
3 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.Arrays;
8 import java.util.HashMap;
9 import java.util.concurrent.atomic.AtomicBoolean;
10 import iotrmi.Java.IoTRMIComm;
11 import iotrmi.Java.IoTRMICommClient;
12 import iotrmi.Java.IoTRMICommServer;
13 import iotrmi.Java.IoTRMIUtil;
15 import iotcode.interfaces.*;
17 public class SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
19 private int objectId = 3;
20 private IoTRMIComm rmiComm;
21 // Synchronization variables
22 private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
23 private AtomicBoolean retValueReceived2 = new AtomicBoolean(false);
24 private AtomicBoolean retValueReceived5 = new AtomicBoolean(false);
25 private AtomicBoolean retValueReceived1 = new AtomicBoolean(false);
28 public SmartthingsSensorSmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
29 if (_localPortSend != 0 && _localPortRecv != 0) {
30 rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
33 rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
35 rmiComm.registerStub(objectId, 3, retValueReceived3);
36 rmiComm.registerStub(objectId, 2, retValueReceived2);
37 rmiComm.registerStub(objectId, 5, retValueReceived5);
38 rmiComm.registerStub(objectId, 1, retValueReceived1);
39 IoTRMIUtil.mapStub.put(objectId, this);
42 public SmartthingsSensorSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
45 rmiComm.registerStub(objectId, 3, retValueReceived3);
46 rmiComm.registerStub(objectId, 2, retValueReceived2);
47 rmiComm.registerStub(objectId, 5, retValueReceived5);
48 rmiComm.registerStub(objectId, 1, retValueReceived1);
51 public long getTimestampOfLastReading() {
53 Class<?> retType = long.class;
54 Class<?>[] paramCls = new Class<?>[] { };
55 Object[] paramObj = new Object[] { };
56 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
57 // Waiting for return value
58 while (!retValueReceived3.get());
59 Object retObj = rmiComm.getReturnValue(retType, null);
60 retValueReceived3.set(false);
61 rmiComm.setGetReturnBytes();
66 public boolean isActiveValue() {
68 Class<?> retType = boolean.class;
69 Class<?>[] paramCls = new Class<?>[] { };
70 Object[] paramObj = new Object[] { };
71 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
72 // Waiting for return value
73 while (!retValueReceived2.get());
74 Object retObj = rmiComm.getReturnValue(retType, null);
75 retValueReceived2.set(false);
76 rmiComm.setGetReturnBytes();
78 return (boolean)retObj;
83 Class<?> retType = int.class;
84 Class<?>[] paramCls = new Class<?>[] { };
85 Object[] paramObj = new Object[] { };
86 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
87 // Waiting for return value
88 while (!retValueReceived5.get());
89 Object retObj = rmiComm.getReturnValue(retType, null);
90 retValueReceived5.set(false);
91 rmiComm.setGetReturnBytes();
96 public void registerCallback(SmartthingsSensorCallback _callbackTo) {
97 int[] objIdSent0 = new int[1];
99 if (!IoTRMIUtil.mapSkel.containsKey(_callbackTo)) {
100 int newObjIdSent = rmiComm.getObjectIdCounter();
101 objIdSent0[0] = newObjIdSent;
102 rmiComm.decrementObjectIdCounter();
103 SmartthingsSensorCallback_Skeleton skel0 = new SmartthingsSensorCallback_Skeleton(_callbackTo, rmiComm, newObjIdSent);
104 IoTRMIUtil.mapSkel.put(_callbackTo, skel0);
105 IoTRMIUtil.mapSkelId.put(_callbackTo, newObjIdSent);
106 Thread thread = new Thread() {
109 skel0.___waitRequestInvokeMethod();
110 } catch (Exception ex) {
111 ex.printStackTrace();
112 throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for SmartthingsSensorCallback_Skeleton!");
117 while(!skel0.didAlreadyInitWaitInvoke());
121 int newObjIdSent = IoTRMIUtil.mapSkelId.get(_callbackTo);
122 objIdSent0[0] = newObjIdSent;
124 } catch (Exception ex) {
125 ex.printStackTrace();
126 throw new Error("Exception when generating skeleton objects!");
130 Class<?> retType = void.class;
131 Class<?>[] paramCls = new Class<?>[] { int[].class };
132 Object[] paramObj = new Object[] { objIdSent0 };
133 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
136 public int getValue() {
138 Class<?> retType = int.class;
139 Class<?>[] paramCls = new Class<?>[] { };
140 Object[] paramObj = new Object[] { };
141 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
142 // Waiting for return value
143 while (!retValueReceived1.get());
144 Object retObj = rmiComm.getReturnValue(retType, null);
145 retValueReceived1.set(false);
146 rmiComm.setGetReturnBytes();
151 public void setId(int id) {
153 Class<?> retType = void.class;
154 Class<?>[] paramCls = new Class<?>[] { int.class };
155 Object[] paramObj = new Object[] { id };
156 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
161 Class<?> retType = void.class;
162 Class<?>[] paramCls = new Class<?>[] { };
163 Object[] paramObj = new Object[] { };
164 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);