1 package iotcode.DoorlockActuator;
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 SmartthingsActuator_Skeleton implements SmartthingsActuator {
19 private SmartthingsActuator mainObj;
20 private int objectId = 1;
21 // Communications and synchronizations
22 private IoTRMIComm rmiComm;
23 private AtomicBoolean didAlreadyInitWaitInvoke;
24 private AtomicBoolean methodReceived;
25 private byte[] methodBytes = null;
27 private static Integer[] object1Permission = { 5, 7, 8, 2, 6, 4, 3, 0, 1 };
28 private static List<Integer> set1Allowed;
31 public SmartthingsActuator_Skeleton(SmartthingsActuator _mainObj, int _portSend, int _portRecv) throws Exception {
33 rmiComm = new IoTRMICommServer(_portSend, _portRecv);
34 set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
35 IoTRMIUtil.mapSkel.put(_mainObj, this);
36 IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
37 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
38 methodReceived = new AtomicBoolean(false);
39 rmiComm.registerSkeleton(objectId, methodReceived);
40 Thread thread1 = new Thread() {
43 ___waitRequestInvokeMethod();
54 public SmartthingsActuator_Skeleton(SmartthingsActuator _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
58 set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
59 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
60 methodReceived = new AtomicBoolean(false);
61 rmiComm.registerSkeleton(objectId, methodReceived);
64 public boolean didAlreadyInitWaitInvoke() {
65 return didAlreadyInitWaitInvoke.get();
72 public boolean actuate(int value) {
73 return mainObj.actuate(value);
76 public void requestStatus() {
77 mainObj.requestStatus();
80 public int getStatus() {
81 return mainObj.getStatus();
84 public boolean isActiveStatus() {
85 return mainObj.isActiveStatus();
88 public long getTimestampOfLastReading() {
89 return mainObj.getTimestampOfLastReading();
92 public void setId(int id) {
97 return mainObj.getId();
100 public void registerCallback(SmartthingsActuatorSmartCallback _callbackTo) {
101 mainObj.registerCallback(_callbackTo);
104 public void ___init() {
105 byte[] localMethodBytes = methodBytes;
106 rmiComm.setGetMethodBytes();
107 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
111 public void ___actuate() throws IOException {
112 byte[] localMethodBytes = methodBytes;
113 rmiComm.setGetMethodBytes();
114 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null }, localMethodBytes);
115 Object retObj = actuate((int) paramObj[0]);
116 rmiComm.sendReturnObj(retObj, localMethodBytes);
119 public void ___requestStatus() {
120 byte[] localMethodBytes = methodBytes;
121 rmiComm.setGetMethodBytes();
122 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
126 public void ___getStatus() throws IOException {
127 byte[] localMethodBytes = methodBytes;
128 rmiComm.setGetMethodBytes();
129 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
130 Object retObj = getStatus();
131 rmiComm.sendReturnObj(retObj, localMethodBytes);
134 public void ___isActiveStatus() throws IOException {
135 byte[] localMethodBytes = methodBytes;
136 rmiComm.setGetMethodBytes();
137 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
138 Object retObj = isActiveStatus();
139 rmiComm.sendReturnObj(retObj, localMethodBytes);
142 public void ___getTimestampOfLastReading() throws IOException {
143 byte[] localMethodBytes = methodBytes;
144 rmiComm.setGetMethodBytes();
145 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
146 Object retObj = getTimestampOfLastReading();
147 rmiComm.sendReturnObj(retObj, localMethodBytes);
150 public void ___setId() {
151 byte[] localMethodBytes = methodBytes;
152 rmiComm.setGetMethodBytes();
153 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null }, localMethodBytes);
154 setId((int) paramObj[0]);
157 public void ___getId() throws IOException {
158 byte[] localMethodBytes = methodBytes;
159 rmiComm.setGetMethodBytes();
160 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
161 Object retObj = getId();
162 rmiComm.sendReturnObj(retObj, localMethodBytes);
165 public void ___registerCallback() {
166 byte[] localMethodBytes = methodBytes;
167 rmiComm.setGetMethodBytes();
168 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
170 int[] stubIdArray0 = (int[]) paramObj[0];
171 int objIdRecv0 = stubIdArray0[0];
172 SmartthingsActuatorSmartCallback newStub0 = null;
173 if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
174 newStub0 = new SmartthingsActuatorSmartCallback_Stub(rmiComm, objIdRecv0);
175 IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
176 rmiComm.setObjectIdCounter(objIdRecv0);
177 rmiComm.decrementObjectIdCounter();
180 newStub0 = (SmartthingsActuatorSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
182 SmartthingsActuatorSmartCallback stub0 = newStub0;
183 registerCallback(stub0);
184 } catch(Exception ex) {
185 ex.printStackTrace();
186 throw new Error("Exception from callback object instantiation!");
190 public void ___waitRequestInvokeMethod() throws IOException {
191 didAlreadyInitWaitInvoke.compareAndSet(false, true);
193 if (!methodReceived.get()) {
196 methodBytes = rmiComm.getMethodBytes();
197 methodReceived.set(false);
198 int _objectId = IoTRMIComm.getObjectId(methodBytes);
199 int methodId = IoTRMIComm.getMethodId(methodBytes);
200 if (_objectId == objectId) {
201 if (!set1Allowed.contains(methodId)) {
202 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
215 catch (Exception ex) {
216 ex.printStackTrace();
227 catch (Exception ex) {
228 ex.printStackTrace();
239 catch (Exception ex) {
240 ex.printStackTrace();
251 catch (Exception ex) {
252 ex.printStackTrace();
263 catch (Exception ex) {
264 ex.printStackTrace();
273 ___getTimestampOfLastReading();
275 catch (Exception ex) {
276 ex.printStackTrace();
287 catch (Exception ex) {
288 ex.printStackTrace();
299 catch (Exception ex) {
300 ex.printStackTrace();
309 ___registerCallback();
311 catch (Exception ex) {
312 ex.printStackTrace();
318 throw new Error("Method Id " + methodId + " not recognized!");