1 package iotcode.LifxLightBulb;
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.LightBulb;
17 public class LightBulb_Skeleton implements LightBulb {
19 private LightBulb 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 = { 2, 10, 1, 3, 11, 8, 12, 7, 13, 9, 6, 16, 17, 4, 0, 14, 15, 5 };
28 private static List<Integer> set1Allowed;
31 public LightBulb_Skeleton(LightBulb _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 LightBulb_Skeleton(LightBulb _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 turnOff() {
76 public void turnOn() {
80 public boolean getState() {
81 return mainObj.getState();
84 public void setColor(double _hue, double _saturation, double _brightness) {
85 mainObj.setColor(_hue, _saturation, _brightness);
88 public void setTemperature(int _temperature) {
89 mainObj.setTemperature(_temperature);
92 public double getBrightness() {
93 return mainObj.getBrightness();
96 public double getHue() {
97 return mainObj.getHue();
100 public double getSaturation() {
101 return mainObj.getSaturation();
104 public int getTemperature() {
105 return mainObj.getTemperature();
108 public double getBrightnessRangeLowerBound() {
109 return mainObj.getBrightnessRangeLowerBound();
112 public double getBrightnessRangeUpperBound() {
113 return mainObj.getBrightnessRangeUpperBound();
116 public double getHueRangeLowerBound() {
117 return mainObj.getHueRangeLowerBound();
120 public double getHueRangeUpperBound() {
121 return mainObj.getHueRangeUpperBound();
124 public double getSaturationRangeLowerBound() {
125 return mainObj.getSaturationRangeLowerBound();
128 public double getSaturationRangeUpperBound() {
129 return mainObj.getSaturationRangeUpperBound();
132 public int getTemperatureRangeLowerBound() {
133 return mainObj.getTemperatureRangeLowerBound();
136 public int getTemperatureRangeUpperBound() {
137 return mainObj.getTemperatureRangeUpperBound();
140 public void ___init() {
141 byte[] localMethodBytes = methodBytes;
142 rmiComm.setGetMethodBytes();
143 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
147 public void ___turnOff() {
148 byte[] localMethodBytes = methodBytes;
149 rmiComm.setGetMethodBytes();
150 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
154 public void ___turnOn() {
155 byte[] localMethodBytes = methodBytes;
156 rmiComm.setGetMethodBytes();
157 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
161 public void ___getState() throws IOException {
162 byte[] localMethodBytes = methodBytes;
163 rmiComm.setGetMethodBytes();
164 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
165 Object retObj = getState();
166 rmiComm.sendReturnObj(retObj, localMethodBytes);
169 public void ___setColor() {
170 byte[] localMethodBytes = methodBytes;
171 rmiComm.setGetMethodBytes();
172 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { double.class, double.class, double.class }, new Class<?>[] { null, null, null }, localMethodBytes);
173 setColor((double) paramObj[0], (double) paramObj[1], (double) paramObj[2]);
176 public void ___setTemperature() {
177 byte[] localMethodBytes = methodBytes;
178 rmiComm.setGetMethodBytes();
179 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null }, localMethodBytes);
180 setTemperature((int) paramObj[0]);
183 public void ___getBrightness() throws IOException {
184 byte[] localMethodBytes = methodBytes;
185 rmiComm.setGetMethodBytes();
186 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
187 Object retObj = getBrightness();
188 rmiComm.sendReturnObj(retObj, localMethodBytes);
191 public void ___getHue() throws IOException {
192 byte[] localMethodBytes = methodBytes;
193 rmiComm.setGetMethodBytes();
194 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
195 Object retObj = getHue();
196 rmiComm.sendReturnObj(retObj, localMethodBytes);
199 public void ___getSaturation() throws IOException {
200 byte[] localMethodBytes = methodBytes;
201 rmiComm.setGetMethodBytes();
202 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
203 Object retObj = getSaturation();
204 rmiComm.sendReturnObj(retObj, localMethodBytes);
207 public void ___getTemperature() throws IOException {
208 byte[] localMethodBytes = methodBytes;
209 rmiComm.setGetMethodBytes();
210 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
211 Object retObj = getTemperature();
212 rmiComm.sendReturnObj(retObj, localMethodBytes);
215 public void ___getBrightnessRangeLowerBound() throws IOException {
216 byte[] localMethodBytes = methodBytes;
217 rmiComm.setGetMethodBytes();
218 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
219 Object retObj = getBrightnessRangeLowerBound();
220 rmiComm.sendReturnObj(retObj, localMethodBytes);
223 public void ___getBrightnessRangeUpperBound() throws IOException {
224 byte[] localMethodBytes = methodBytes;
225 rmiComm.setGetMethodBytes();
226 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
227 Object retObj = getBrightnessRangeUpperBound();
228 rmiComm.sendReturnObj(retObj, localMethodBytes);
231 public void ___getHueRangeLowerBound() throws IOException {
232 byte[] localMethodBytes = methodBytes;
233 rmiComm.setGetMethodBytes();
234 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
235 Object retObj = getHueRangeLowerBound();
236 rmiComm.sendReturnObj(retObj, localMethodBytes);
239 public void ___getHueRangeUpperBound() throws IOException {
240 byte[] localMethodBytes = methodBytes;
241 rmiComm.setGetMethodBytes();
242 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
243 Object retObj = getHueRangeUpperBound();
244 rmiComm.sendReturnObj(retObj, localMethodBytes);
247 public void ___getSaturationRangeLowerBound() throws IOException {
248 byte[] localMethodBytes = methodBytes;
249 rmiComm.setGetMethodBytes();
250 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
251 Object retObj = getSaturationRangeLowerBound();
252 rmiComm.sendReturnObj(retObj, localMethodBytes);
255 public void ___getSaturationRangeUpperBound() throws IOException {
256 byte[] localMethodBytes = methodBytes;
257 rmiComm.setGetMethodBytes();
258 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
259 Object retObj = getSaturationRangeUpperBound();
260 rmiComm.sendReturnObj(retObj, localMethodBytes);
263 public void ___getTemperatureRangeLowerBound() throws IOException {
264 byte[] localMethodBytes = methodBytes;
265 rmiComm.setGetMethodBytes();
266 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
267 Object retObj = getTemperatureRangeLowerBound();
268 rmiComm.sendReturnObj(retObj, localMethodBytes);
271 public void ___getTemperatureRangeUpperBound() throws IOException {
272 byte[] localMethodBytes = methodBytes;
273 rmiComm.setGetMethodBytes();
274 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
275 Object retObj = getTemperatureRangeUpperBound();
276 rmiComm.sendReturnObj(retObj, localMethodBytes);
279 public void ___waitRequestInvokeMethod() throws IOException {
280 didAlreadyInitWaitInvoke.compareAndSet(false, true);
282 if (!methodReceived.get()) {
285 methodBytes = rmiComm.getMethodBytes();
286 methodReceived.set(false);
287 int _objectId = IoTRMIComm.getObjectId(methodBytes);
288 int methodId = IoTRMIComm.getMethodId(methodBytes);
289 if (_objectId == objectId) {
290 if (!set1Allowed.contains(methodId)) {
291 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
304 catch (Exception ex) {
305 ex.printStackTrace();
316 catch (Exception ex) {
317 ex.printStackTrace();
328 catch (Exception ex) {
329 ex.printStackTrace();
340 catch (Exception ex) {
341 ex.printStackTrace();
352 catch (Exception ex) {
353 ex.printStackTrace();
364 catch (Exception ex) {
365 ex.printStackTrace();
376 catch (Exception ex) {
377 ex.printStackTrace();
388 catch (Exception ex) {
389 ex.printStackTrace();
400 catch (Exception ex) {
401 ex.printStackTrace();
412 catch (Exception ex) {
413 ex.printStackTrace();
422 ___getBrightnessRangeLowerBound();
424 catch (Exception ex) {
425 ex.printStackTrace();
434 ___getBrightnessRangeUpperBound();
436 catch (Exception ex) {
437 ex.printStackTrace();
446 ___getHueRangeLowerBound();
448 catch (Exception ex) {
449 ex.printStackTrace();
458 ___getHueRangeUpperBound();
460 catch (Exception ex) {
461 ex.printStackTrace();
470 ___getSaturationRangeLowerBound();
472 catch (Exception ex) {
473 ex.printStackTrace();
482 ___getSaturationRangeUpperBound();
484 catch (Exception ex) {
485 ex.printStackTrace();
494 ___getTemperatureRangeLowerBound();
496 catch (Exception ex) {
497 ex.printStackTrace();
506 ___getTemperatureRangeUpperBound();
508 catch (Exception ex) {
509 ex.printStackTrace();
515 throw new Error("Method Id " + methodId + " not recognized!");