1 package iotcode.WeatherPhoneGateway;
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 WeatherGateway_Skeleton implements WeatherGateway {
19 private WeatherGateway mainObj;
20 private int objectId = 3;
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[] object3Permission = { 3, 6, 5, 7, 2, 1, 0, 4 };
28 private static List<Integer> set3Allowed;
31 public WeatherGateway_Skeleton(WeatherGateway _mainObj, int _portSend, int _portRecv) throws Exception {
33 rmiComm = new IoTRMICommServer(_portSend, _portRecv);
34 set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
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 WeatherGateway_Skeleton(WeatherGateway _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
58 set3Allowed = new ArrayList<Integer>(Arrays.asList(object3Permission));
59 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
60 methodReceived = new AtomicBoolean(false);
61 rmiComm.registerSkeleton(objectId, methodReceived);
64 public boolean didAlreadyInitWaitInvoke() {
65 return didAlreadyInitWaitInvoke.get();
80 public double getInchesPerWeek() {
81 return mainObj.getInchesPerWeek();
84 public int getWeatherZipCode() {
85 return mainObj.getWeatherZipCode();
88 public int getDaysToWaterOn() {
89 return mainObj.getDaysToWaterOn();
92 public double getInchesPerMinute() {
93 return mainObj.getInchesPerMinute();
96 public void registerCallback(WeatherGatewaySmartCallback _callbackTo) {
97 mainObj.registerCallback(_callbackTo);
100 public void ___init() {
101 byte[] localMethodBytes = methodBytes;
102 rmiComm.setGetMethodBytes();
103 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
107 public void ___start() {
108 byte[] localMethodBytes = methodBytes;
109 rmiComm.setGetMethodBytes();
110 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
114 public void ___stop() {
115 byte[] localMethodBytes = methodBytes;
116 rmiComm.setGetMethodBytes();
117 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
121 public void ___getInchesPerWeek() throws IOException {
122 byte[] localMethodBytes = methodBytes;
123 rmiComm.setGetMethodBytes();
124 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
125 Object retObj = getInchesPerWeek();
126 rmiComm.sendReturnObj(retObj, localMethodBytes);
129 public void ___getWeatherZipCode() throws IOException {
130 byte[] localMethodBytes = methodBytes;
131 rmiComm.setGetMethodBytes();
132 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
133 Object retObj = getWeatherZipCode();
134 rmiComm.sendReturnObj(retObj, localMethodBytes);
137 public void ___getDaysToWaterOn() throws IOException {
138 byte[] localMethodBytes = methodBytes;
139 rmiComm.setGetMethodBytes();
140 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
141 Object retObj = getDaysToWaterOn();
142 rmiComm.sendReturnObj(retObj, localMethodBytes);
145 public void ___getInchesPerMinute() throws IOException {
146 byte[] localMethodBytes = methodBytes;
147 rmiComm.setGetMethodBytes();
148 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
149 Object retObj = getInchesPerMinute();
150 rmiComm.sendReturnObj(retObj, localMethodBytes);
153 public void ___registerCallback() {
154 byte[] localMethodBytes = methodBytes;
155 rmiComm.setGetMethodBytes();
156 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
158 int[] stubIdArray0 = (int[]) paramObj[0];
159 int objIdRecv0 = stubIdArray0[0];
160 WeatherGatewaySmartCallback newStub0 = null;
161 if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
162 newStub0 = new WeatherGatewaySmartCallback_Stub(rmiComm, objIdRecv0);
163 IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
164 rmiComm.setObjectIdCounter(objIdRecv0);
165 rmiComm.decrementObjectIdCounter();
168 newStub0 = (WeatherGatewaySmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
170 WeatherGatewaySmartCallback stub0 = newStub0;
171 registerCallback(stub0);
172 } catch(Exception ex) {
173 ex.printStackTrace();
174 throw new Error("Exception from callback object instantiation!");
178 public void ___waitRequestInvokeMethod() throws IOException {
179 didAlreadyInitWaitInvoke.compareAndSet(false, true);
181 if (!methodReceived.get()) {
184 methodBytes = rmiComm.getMethodBytes();
185 methodReceived.set(false);
186 int _objectId = IoTRMIComm.getObjectId(methodBytes);
187 int methodId = IoTRMIComm.getMethodId(methodBytes);
188 if (_objectId == objectId) {
189 if (!set3Allowed.contains(methodId)) {
190 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
203 catch (Exception ex) {
204 ex.printStackTrace();
215 catch (Exception ex) {
216 ex.printStackTrace();
227 catch (Exception ex) {
228 ex.printStackTrace();
237 ___getInchesPerWeek();
239 catch (Exception ex) {
240 ex.printStackTrace();
249 ___getWeatherZipCode();
251 catch (Exception ex) {
252 ex.printStackTrace();
261 ___getDaysToWaterOn();
263 catch (Exception ex) {
264 ex.printStackTrace();
273 ___getInchesPerMinute();
275 catch (Exception ex) {
276 ex.printStackTrace();
285 ___registerCallback();
287 catch (Exception ex) {
288 ex.printStackTrace();
294 throw new Error("Method Id " + methodId + " not recognized!");