1 package iotcode.GPSPhoneGateway;
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 GPSGateway_Skeleton implements GPSGateway {
19 private GPSGateway 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 = { 5, 6, 2, 1, 0, 3, 7, 4 };
28 private static List<Integer> set3Allowed;
31 public GPSGateway_Skeleton(GPSGateway _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 GPSGateway_Skeleton(GPSGateway _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 int getRoomID() {
81 return mainObj.getRoomID();
84 public boolean getRingStatus() {
85 return mainObj.getRingStatus();
88 public void setNewRoomIDAvailable(boolean bValue) {
89 mainObj.setNewRoomIDAvailable(bValue);
92 public void setNewRingStatusAvailable(boolean bValue) {
93 mainObj.setNewRingStatusAvailable(bValue);
96 public void registerCallback(GPSGatewaySmartCallback _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 ___getRoomID() throws IOException {
122 byte[] localMethodBytes = methodBytes;
123 rmiComm.setGetMethodBytes();
124 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
125 Object retObj = getRoomID();
126 rmiComm.sendReturnObj(retObj, localMethodBytes);
129 public void ___getRingStatus() throws IOException {
130 byte[] localMethodBytes = methodBytes;
131 rmiComm.setGetMethodBytes();
132 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
133 Object retObj = getRingStatus();
134 rmiComm.sendReturnObj(retObj, localMethodBytes);
137 public void ___setNewRoomIDAvailable() {
138 byte[] localMethodBytes = methodBytes;
139 rmiComm.setGetMethodBytes();
140 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { boolean.class }, new Class<?>[] { null }, localMethodBytes);
141 setNewRoomIDAvailable((boolean) paramObj[0]);
144 public void ___setNewRingStatusAvailable() {
145 byte[] localMethodBytes = methodBytes;
146 rmiComm.setGetMethodBytes();
147 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { boolean.class }, new Class<?>[] { null }, localMethodBytes);
148 setNewRingStatusAvailable((boolean) paramObj[0]);
151 public void ___registerCallback() {
152 byte[] localMethodBytes = methodBytes;
153 rmiComm.setGetMethodBytes();
154 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
156 int[] stubIdArray0 = (int[]) paramObj[0];
157 int objIdRecv0 = stubIdArray0[0];
158 GPSGatewaySmartCallback newStub0 = null;
159 if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
160 newStub0 = new GPSGatewaySmartCallback_Stub(rmiComm, objIdRecv0);
161 IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
162 rmiComm.setObjectIdCounter(objIdRecv0);
163 rmiComm.decrementObjectIdCounter();
166 newStub0 = (GPSGatewaySmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
168 GPSGatewaySmartCallback stub0 = newStub0;
169 registerCallback(stub0);
170 } catch(Exception ex) {
171 ex.printStackTrace();
172 throw new Error("Exception from callback object instantiation!");
176 public void ___waitRequestInvokeMethod() throws IOException {
177 didAlreadyInitWaitInvoke.compareAndSet(false, true);
179 if (!methodReceived.get()) {
182 methodBytes = rmiComm.getMethodBytes();
183 methodReceived.set(false);
184 int _objectId = IoTRMIComm.getObjectId(methodBytes);
185 int methodId = IoTRMIComm.getMethodId(methodBytes);
186 if (_objectId == objectId) {
187 if (!set3Allowed.contains(methodId)) {
188 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
201 catch (Exception ex) {
202 ex.printStackTrace();
213 catch (Exception ex) {
214 ex.printStackTrace();
225 catch (Exception ex) {
226 ex.printStackTrace();
237 catch (Exception ex) {
238 ex.printStackTrace();
249 catch (Exception ex) {
250 ex.printStackTrace();
259 ___setNewRoomIDAvailable();
261 catch (Exception ex) {
262 ex.printStackTrace();
271 ___setNewRingStatusAvailable();
273 catch (Exception ex) {
274 ex.printStackTrace();
283 ___registerCallback();
285 catch (Exception ex) {
286 ex.printStackTrace();
292 throw new Error("Method Id " + methodId + " not recognized!");