1 package iotcode.DlinkAlarm;
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 Alarm_Skeleton implements Alarm {
19 private Alarm 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 = { 4, 2, 0, 1, 3 };
28 private static List<Integer> set1Allowed;
31 public Alarm_Skeleton(Alarm _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 Alarm_Skeleton(Alarm _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 void setZone(int _zone, boolean _onOff, int _onDurationSeconds) {
73 mainObj.setZone(_zone, _onOff, _onDurationSeconds);
76 public List<ZoneState> getZoneStates() {
77 return mainObj.getZoneStates();
80 public int getNumberOfZones() {
81 return mainObj.getNumberOfZones();
84 public boolean doesHaveZoneTimers() {
85 return mainObj.doesHaveZoneTimers();
88 public void ___init() {
89 byte[] localMethodBytes = methodBytes;
90 rmiComm.setGetMethodBytes();
91 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
95 public void ___setZone() {
96 byte[] localMethodBytes = methodBytes;
97 rmiComm.setGetMethodBytes();
98 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class, boolean.class, int.class }, new Class<?>[] { null, null, null }, localMethodBytes);
99 setZone((int) paramObj[0], (boolean) paramObj[1], (int) paramObj[2]);
102 public void ___getZoneStates() throws IOException {
103 byte[] localMethodBytes = methodBytes;
104 rmiComm.setGetMethodBytes();
105 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
106 List<ZoneState> retStruct = getZoneStates();
107 int retLen = retStruct.size();
108 Object retLenObj = retLen;
109 rmiComm.sendReturnObj(retLenObj, localMethodBytes);
110 Class<?>[] retCls = new Class<?>[3*retLen];
111 Object[] retObj = new Object[3*retLen];
113 for(int i = 0; i < retLen; i++) {
114 retCls[retPos] = int.class;
115 retObj[retPos++] = retStruct.get(i).zoneNumber;
116 retCls[retPos] = boolean.class;
117 retObj[retPos++] = retStruct.get(i).onOffState;
118 retCls[retPos] = int.class;
119 retObj[retPos++] = retStruct.get(i).duration;
121 rmiComm.sendReturnObj(retCls, retObj, localMethodBytes);
124 public void ___getNumberOfZones() throws IOException {
125 byte[] localMethodBytes = methodBytes;
126 rmiComm.setGetMethodBytes();
127 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
128 Object retObj = getNumberOfZones();
129 rmiComm.sendReturnObj(retObj, localMethodBytes);
132 public void ___doesHaveZoneTimers() throws IOException {
133 byte[] localMethodBytes = methodBytes;
134 rmiComm.setGetMethodBytes();
135 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
136 Object retObj = doesHaveZoneTimers();
137 rmiComm.sendReturnObj(retObj, localMethodBytes);
140 public void ___waitRequestInvokeMethod() throws IOException {
141 didAlreadyInitWaitInvoke.compareAndSet(false, true);
143 if (!methodReceived.get()) {
146 methodBytes = rmiComm.getMethodBytes();
147 methodReceived.set(false);
148 int _objectId = IoTRMIComm.getObjectId(methodBytes);
149 int methodId = IoTRMIComm.getMethodId(methodBytes);
150 if (_objectId == objectId) {
151 if (!set1Allowed.contains(methodId)) {
152 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
165 catch (Exception ex) {
166 ex.printStackTrace();
177 catch (Exception ex) {
178 ex.printStackTrace();
189 catch (Exception ex) {
190 ex.printStackTrace();
199 ___getNumberOfZones();
201 catch (Exception ex) {
202 ex.printStackTrace();
211 ___doesHaveZoneTimers();
213 catch (Exception ex) {
214 ex.printStackTrace();
220 throw new Error("Method Id " + methodId + " not recognized!");