1 package iotcode.SpruceSensor;
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 MoistureSensor_Skeleton implements MoistureSensor {
19 private MoistureSensor mainObj;
20 private int objectId = 5;
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[] object5Permission = { 2, 4, 5, 1, 3, 0 };
28 private static List<Integer> set5Allowed;
31 public MoistureSensor_Skeleton(MoistureSensor _mainObj, int _portSend, int _portRecv) throws Exception {
33 rmiComm = new IoTRMICommServer(_portSend, _portRecv);
34 set5Allowed = new ArrayList<Integer>(Arrays.asList(object5Permission));
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 MoistureSensor_Skeleton(MoistureSensor _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
58 set5Allowed = new ArrayList<Integer>(Arrays.asList(object5Permission));
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 float getMoisture() {
73 return mainObj.getMoisture();
76 public long getTimestampOfLastReading() {
77 return mainObj.getTimestampOfLastReading();
80 public void setId(int id) {
85 return mainObj.getId();
88 public void registerCallback(MoistureSensorSmartCallback _callbackTo) {
89 mainObj.registerCallback(_callbackTo);
92 public void ___init() {
93 byte[] localMethodBytes = methodBytes;
94 rmiComm.setGetMethodBytes();
95 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
99 public void ___getMoisture() throws IOException {
100 byte[] localMethodBytes = methodBytes;
101 rmiComm.setGetMethodBytes();
102 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
103 Object retObj = getMoisture();
104 rmiComm.sendReturnObj(retObj, localMethodBytes);
107 public void ___getTimestampOfLastReading() throws IOException {
108 byte[] localMethodBytes = methodBytes;
109 rmiComm.setGetMethodBytes();
110 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
111 Object retObj = getTimestampOfLastReading();
112 rmiComm.sendReturnObj(retObj, localMethodBytes);
115 public void ___setId() {
116 byte[] localMethodBytes = methodBytes;
117 rmiComm.setGetMethodBytes();
118 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null }, localMethodBytes);
119 setId((int) paramObj[0]);
122 public void ___getId() throws IOException {
123 byte[] localMethodBytes = methodBytes;
124 rmiComm.setGetMethodBytes();
125 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
126 Object retObj = getId();
127 rmiComm.sendReturnObj(retObj, localMethodBytes);
130 public void ___registerCallback() {
131 byte[] localMethodBytes = methodBytes;
132 rmiComm.setGetMethodBytes();
133 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
135 int[] stubIdArray0 = (int[]) paramObj[0];
136 int objIdRecv0 = stubIdArray0[0];
137 MoistureSensorSmartCallback newStub0 = null;
138 if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
139 newStub0 = new MoistureSensorSmartCallback_Stub(rmiComm, objIdRecv0);
140 IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
141 rmiComm.setObjectIdCounter(objIdRecv0);
142 rmiComm.decrementObjectIdCounter();
145 newStub0 = (MoistureSensorSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
147 MoistureSensorSmartCallback stub0 = newStub0;
148 registerCallback(stub0);
149 } catch(Exception ex) {
150 ex.printStackTrace();
151 throw new Error("Exception from callback object instantiation!");
155 public void ___waitRequestInvokeMethod() throws IOException {
156 didAlreadyInitWaitInvoke.compareAndSet(false, true);
158 if (!methodReceived.get()) {
161 methodBytes = rmiComm.getMethodBytes();
162 methodReceived.set(false);
163 int _objectId = IoTRMIComm.getObjectId(methodBytes);
164 int methodId = IoTRMIComm.getMethodId(methodBytes);
165 if (_objectId == objectId) {
166 if (!set5Allowed.contains(methodId)) {
167 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
180 catch (Exception ex) {
181 ex.printStackTrace();
192 catch (Exception ex) {
193 ex.printStackTrace();
202 ___getTimestampOfLastReading();
204 catch (Exception ex) {
205 ex.printStackTrace();
216 catch (Exception ex) {
217 ex.printStackTrace();
228 catch (Exception ex) {
229 ex.printStackTrace();
238 ___registerCallback();
240 catch (Exception ex) {
241 ex.printStackTrace();
247 throw new Error("Method Id " + methodId + " not recognized!");