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 final static int object0Id = 0; //LightBulbSmart
28 private static Integer[] object0Permission = { 2, 10, 1, 3, 11, 8, 12, 7, 13, 9, 6, 16, 17, 4, 0, 14, 15, 5 };
29 private static List<Integer> set0Allowed;
32 public LightBulb_Skeleton(LightBulb _mainObj, int _portSend, int _portRecv) throws Exception {
34 rmiComm = new IoTRMICommServer(_portSend, _portRecv);
35 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
36 IoTRMIUtil.mapSkel.put(_mainObj, this);
37 IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
38 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
39 methodReceived = new AtomicBoolean(false);
40 rmiComm.registerSkeleton(objectId, methodReceived);
41 Thread thread1 = new Thread() {
44 ___waitRequestInvokeMethod();
55 public LightBulb_Skeleton(LightBulb _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
59 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
60 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
61 methodReceived = new AtomicBoolean(false);
62 rmiComm.registerSkeleton(objectId, methodReceived);
65 public boolean didAlreadyInitWaitInvoke() {
66 return didAlreadyInitWaitInvoke.get();
73 public void turnOff() {
77 public void turnOn() {
81 public boolean getState() {
82 return mainObj.getState();
85 public void setColor(double _hue, double _saturation, double _brightness) {
86 mainObj.setColor(_hue, _saturation, _brightness);
89 public void setTemperature(int _temperature) {
90 mainObj.setTemperature(_temperature);
93 public double getBrightness() {
94 return mainObj.getBrightness();
97 public double getHue() {
98 return mainObj.getHue();
101 public double getSaturation() {
102 return mainObj.getSaturation();
105 public int getTemperature() {
106 return mainObj.getTemperature();
109 public double getBrightnessRangeLowerBound() {
110 return mainObj.getBrightnessRangeLowerBound();
113 public double getBrightnessRangeUpperBound() {
114 return mainObj.getBrightnessRangeUpperBound();
117 public double getHueRangeLowerBound() {
118 return mainObj.getHueRangeLowerBound();
121 public double getHueRangeUpperBound() {
122 return mainObj.getHueRangeUpperBound();
125 public double getSaturationRangeLowerBound() {
126 return mainObj.getSaturationRangeLowerBound();
129 public double getSaturationRangeUpperBound() {
130 return mainObj.getSaturationRangeUpperBound();
133 public int getTemperatureRangeLowerBound() {
134 return mainObj.getTemperatureRangeLowerBound();
137 public int getTemperatureRangeUpperBound() {
138 return mainObj.getTemperatureRangeUpperBound();
141 public void ___init() {
142 byte[] localMethodBytes = methodBytes;
143 rmiComm.setGetMethodBytes();
144 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
148 public void ___turnOff() {
149 byte[] localMethodBytes = methodBytes;
150 rmiComm.setGetMethodBytes();
151 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
155 public void ___turnOn() {
156 byte[] localMethodBytes = methodBytes;
157 rmiComm.setGetMethodBytes();
158 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
162 public void ___getState() throws IOException {
163 byte[] localMethodBytes = methodBytes;
164 rmiComm.setGetMethodBytes();
165 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
166 Object retObj = getState();
167 rmiComm.sendReturnObj(retObj, localMethodBytes);
170 public void ___setColor() {
171 byte[] localMethodBytes = methodBytes;
172 rmiComm.setGetMethodBytes();
173 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { double.class, double.class, double.class }, new Class<?>[] { null, null, null }, localMethodBytes);
174 setColor((double) paramObj[0], (double) paramObj[1], (double) paramObj[2]);
177 public void ___setTemperature() {
178 byte[] localMethodBytes = methodBytes;
179 rmiComm.setGetMethodBytes();
180 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null }, localMethodBytes);
181 setTemperature((int) paramObj[0]);
184 public void ___getBrightness() throws IOException {
185 byte[] localMethodBytes = methodBytes;
186 rmiComm.setGetMethodBytes();
187 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
188 Object retObj = getBrightness();
189 rmiComm.sendReturnObj(retObj, localMethodBytes);
192 public void ___getHue() throws IOException {
193 byte[] localMethodBytes = methodBytes;
194 rmiComm.setGetMethodBytes();
195 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
196 Object retObj = getHue();
197 rmiComm.sendReturnObj(retObj, localMethodBytes);
200 public void ___getSaturation() throws IOException {
201 byte[] localMethodBytes = methodBytes;
202 rmiComm.setGetMethodBytes();
203 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
204 Object retObj = getSaturation();
205 rmiComm.sendReturnObj(retObj, localMethodBytes);
208 public void ___getTemperature() throws IOException {
209 byte[] localMethodBytes = methodBytes;
210 rmiComm.setGetMethodBytes();
211 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
212 Object retObj = getTemperature();
213 rmiComm.sendReturnObj(retObj, localMethodBytes);
216 public void ___getBrightnessRangeLowerBound() throws IOException {
217 byte[] localMethodBytes = methodBytes;
218 rmiComm.setGetMethodBytes();
219 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
220 Object retObj = getBrightnessRangeLowerBound();
221 rmiComm.sendReturnObj(retObj, localMethodBytes);
224 public void ___getBrightnessRangeUpperBound() throws IOException {
225 byte[] localMethodBytes = methodBytes;
226 rmiComm.setGetMethodBytes();
227 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
228 Object retObj = getBrightnessRangeUpperBound();
229 rmiComm.sendReturnObj(retObj, localMethodBytes);
232 public void ___getHueRangeLowerBound() throws IOException {
233 byte[] localMethodBytes = methodBytes;
234 rmiComm.setGetMethodBytes();
235 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
236 Object retObj = getHueRangeLowerBound();
237 rmiComm.sendReturnObj(retObj, localMethodBytes);
240 public void ___getHueRangeUpperBound() throws IOException {
241 byte[] localMethodBytes = methodBytes;
242 rmiComm.setGetMethodBytes();
243 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
244 Object retObj = getHueRangeUpperBound();
245 rmiComm.sendReturnObj(retObj, localMethodBytes);
248 public void ___getSaturationRangeLowerBound() throws IOException {
249 byte[] localMethodBytes = methodBytes;
250 rmiComm.setGetMethodBytes();
251 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
252 Object retObj = getSaturationRangeLowerBound();
253 rmiComm.sendReturnObj(retObj, localMethodBytes);
256 public void ___getSaturationRangeUpperBound() throws IOException {
257 byte[] localMethodBytes = methodBytes;
258 rmiComm.setGetMethodBytes();
259 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
260 Object retObj = getSaturationRangeUpperBound();
261 rmiComm.sendReturnObj(retObj, localMethodBytes);
264 public void ___getTemperatureRangeLowerBound() throws IOException {
265 byte[] localMethodBytes = methodBytes;
266 rmiComm.setGetMethodBytes();
267 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
268 Object retObj = getTemperatureRangeLowerBound();
269 rmiComm.sendReturnObj(retObj, localMethodBytes);
272 public void ___getTemperatureRangeUpperBound() throws IOException {
273 byte[] localMethodBytes = methodBytes;
274 rmiComm.setGetMethodBytes();
275 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
276 Object retObj = getTemperatureRangeUpperBound();
277 rmiComm.sendReturnObj(retObj, localMethodBytes);
280 public void ___waitRequestInvokeMethod() throws IOException {
281 didAlreadyInitWaitInvoke.compareAndSet(false, true);
283 if (!methodReceived.get()) {
286 methodBytes = rmiComm.getMethodBytes();
287 methodReceived.set(false);
288 int _objectId = IoTRMIComm.getObjectId(methodBytes);
289 int methodId = IoTRMIComm.getMethodId(methodBytes);
290 if (_objectId == objectId) {
291 if (!set0Allowed.contains(methodId)) {
292 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
305 catch (Exception ex) {
306 ex.printStackTrace();
317 catch (Exception ex) {
318 ex.printStackTrace();
329 catch (Exception ex) {
330 ex.printStackTrace();
341 catch (Exception ex) {
342 ex.printStackTrace();
353 catch (Exception ex) {
354 ex.printStackTrace();
365 catch (Exception ex) {
366 ex.printStackTrace();
377 catch (Exception ex) {
378 ex.printStackTrace();
389 catch (Exception ex) {
390 ex.printStackTrace();
401 catch (Exception ex) {
402 ex.printStackTrace();
413 catch (Exception ex) {
414 ex.printStackTrace();
423 ___getBrightnessRangeLowerBound();
425 catch (Exception ex) {
426 ex.printStackTrace();
435 ___getBrightnessRangeUpperBound();
437 catch (Exception ex) {
438 ex.printStackTrace();
447 ___getHueRangeLowerBound();
449 catch (Exception ex) {
450 ex.printStackTrace();
459 ___getHueRangeUpperBound();
461 catch (Exception ex) {
462 ex.printStackTrace();
471 ___getSaturationRangeLowerBound();
473 catch (Exception ex) {
474 ex.printStackTrace();
483 ___getSaturationRangeUpperBound();
485 catch (Exception ex) {
486 ex.printStackTrace();
495 ___getTemperatureRangeLowerBound();
497 catch (Exception ex) {
498 ex.printStackTrace();
507 ___getTemperatureRangeUpperBound();
509 catch (Exception ex) {
510 ex.printStackTrace();
516 throw new Error("Method Id " + methodId + " not recognized!");