Updating stub and skeleton for Lifxtest
[iot2.git] / benchmarks / drivers / Java / LifxLightBulb / LightBulb_Skeleton.java
1 package iotcode.LifxLightBulb;
2
3 import java.io.IOException;
4 import java.util.List;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import java.util.Map;
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;
14
15 import iotcode.interfaces.LightBulb;
16
17 public class LightBulb_Skeleton implements LightBulb {
18
19         private LightBulb mainObj;
20         private int objectId = 0;
21         // Communications and synchronizations
22         private IoTRMIComm rmiComm;
23         private AtomicBoolean didAlreadyInitWaitInvoke;
24         private AtomicBoolean methodReceived;
25         private byte[] methodBytes = null;
26         // Permissions
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;
30         
31
32         public LightBulb_Skeleton(LightBulb _mainObj, int _portSend, int _portRecv) throws Exception {
33                 mainObj = _mainObj;
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() {
42                         public void run() {
43                                 try {
44                                         ___waitRequestInvokeMethod();
45                                 }
46                                 catch (Exception ex)
47                                 {
48                                         ex.printStackTrace();
49                                 }
50                         }
51                 };
52                 thread1.start();
53         }
54
55         public LightBulb_Skeleton(LightBulb _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
56                 mainObj = _mainObj;
57                 rmiComm = _rmiComm;
58                 objectId = _objectId;
59                 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
60                 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
61                 methodReceived = new AtomicBoolean(false);
62                 rmiComm.registerSkeleton(objectId, methodReceived);
63         }
64
65         public boolean didAlreadyInitWaitInvoke() {
66                 return didAlreadyInitWaitInvoke.get();
67         }
68
69         public void init() {
70                 mainObj.init();
71         }
72
73         public void turnOff() {
74                 mainObj.turnOff();
75         }
76
77         public void turnOn() {
78                 mainObj.turnOn();
79         }
80
81         public boolean getState() {
82                 return mainObj.getState();
83         }
84
85         public void setColor(double _hue, double _saturation, double _brightness) {
86                 mainObj.setColor(_hue, _saturation, _brightness);
87         }
88
89         public void setTemperature(int _temperature) {
90                 mainObj.setTemperature(_temperature);
91         }
92
93         public double getBrightness() {
94                 return mainObj.getBrightness();
95         }
96
97         public double getHue() {
98                 return mainObj.getHue();
99         }
100
101         public double getSaturation() {
102                 return mainObj.getSaturation();
103         }
104
105         public int getTemperature() {
106                 return mainObj.getTemperature();
107         }
108
109         public double getBrightnessRangeLowerBound() {
110                 return mainObj.getBrightnessRangeLowerBound();
111         }
112
113         public double getBrightnessRangeUpperBound() {
114                 return mainObj.getBrightnessRangeUpperBound();
115         }
116
117         public double getHueRangeLowerBound() {
118                 return mainObj.getHueRangeLowerBound();
119         }
120
121         public double getHueRangeUpperBound() {
122                 return mainObj.getHueRangeUpperBound();
123         }
124
125         public double getSaturationRangeLowerBound() {
126                 return mainObj.getSaturationRangeLowerBound();
127         }
128
129         public double getSaturationRangeUpperBound() {
130                 return mainObj.getSaturationRangeUpperBound();
131         }
132
133         public int getTemperatureRangeLowerBound() {
134                 return mainObj.getTemperatureRangeLowerBound();
135         }
136
137         public int getTemperatureRangeUpperBound() {
138                 return mainObj.getTemperatureRangeUpperBound();
139         }
140
141         public void ___init() {
142                 byte[] localMethodBytes = methodBytes;
143                 rmiComm.setGetMethodBytes();
144                 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
145                 init();
146         }
147
148         public void ___turnOff() {
149                 byte[] localMethodBytes = methodBytes;
150                 rmiComm.setGetMethodBytes();
151                 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
152                 turnOff();
153         }
154
155         public void ___turnOn() {
156                 byte[] localMethodBytes = methodBytes;
157                 rmiComm.setGetMethodBytes();
158                 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] {  }, new Class<?>[] {  }, localMethodBytes);
159                 turnOn();
160         }
161
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);
168         }
169
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]);
175         }
176
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]);
182         }
183
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);
190         }
191
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);
198         }
199
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);
206         }
207
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);
214         }
215
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);
222         }
223
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);
230         }
231
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);
238         }
239
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);
246         }
247
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);
254         }
255
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);
262         }
263
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);
270         }
271
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);
278         }
279
280         public void ___waitRequestInvokeMethod() throws IOException {
281                 didAlreadyInitWaitInvoke.compareAndSet(false, true);
282                 while (true) {
283                         if (!methodReceived.get()) {
284                                 continue;
285                         }
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);
293                                 }
294                         }
295                         else {
296                                 continue;
297                         }
298                         switch (methodId) {
299                                 case 0:
300                                 new Thread() {
301                                         public void run() {
302                                                 try {
303                                                         ___init();
304                                                 }
305                                                 catch (Exception ex) {
306                                                         ex.printStackTrace();
307                                                 }
308                                         }
309                                 }.start();
310                                 break;
311                                 case 1:
312                                 new Thread() {
313                                         public void run() {
314                                                 try {
315                                                         ___turnOff();
316                                                 }
317                                                 catch (Exception ex) {
318                                                         ex.printStackTrace();
319                                                 }
320                                         }
321                                 }.start();
322                                 break;
323                                 case 2:
324                                 new Thread() {
325                                         public void run() {
326                                                 try {
327                                                         ___turnOn();
328                                                 }
329                                                 catch (Exception ex) {
330                                                         ex.printStackTrace();
331                                                 }
332                                         }
333                                 }.start();
334                                 break;
335                                 case 3:
336                                 new Thread() {
337                                         public void run() {
338                                                 try {
339                                                         ___getState();
340                                                 }
341                                                 catch (Exception ex) {
342                                                         ex.printStackTrace();
343                                                 }
344                                         }
345                                 }.start();
346                                 break;
347                                 case 4:
348                                 new Thread() {
349                                         public void run() {
350                                                 try {
351                                                         ___setColor();
352                                                 }
353                                                 catch (Exception ex) {
354                                                         ex.printStackTrace();
355                                                 }
356                                         }
357                                 }.start();
358                                 break;
359                                 case 5:
360                                 new Thread() {
361                                         public void run() {
362                                                 try {
363                                                         ___setTemperature();
364                                                 }
365                                                 catch (Exception ex) {
366                                                         ex.printStackTrace();
367                                                 }
368                                         }
369                                 }.start();
370                                 break;
371                                 case 6:
372                                 new Thread() {
373                                         public void run() {
374                                                 try {
375                                                         ___getBrightness();
376                                                 }
377                                                 catch (Exception ex) {
378                                                         ex.printStackTrace();
379                                                 }
380                                         }
381                                 }.start();
382                                 break;
383                                 case 7:
384                                 new Thread() {
385                                         public void run() {
386                                                 try {
387                                                         ___getHue();
388                                                 }
389                                                 catch (Exception ex) {
390                                                         ex.printStackTrace();
391                                                 }
392                                         }
393                                 }.start();
394                                 break;
395                                 case 8:
396                                 new Thread() {
397                                         public void run() {
398                                                 try {
399                                                         ___getSaturation();
400                                                 }
401                                                 catch (Exception ex) {
402                                                         ex.printStackTrace();
403                                                 }
404                                         }
405                                 }.start();
406                                 break;
407                                 case 9:
408                                 new Thread() {
409                                         public void run() {
410                                                 try {
411                                                         ___getTemperature();
412                                                 }
413                                                 catch (Exception ex) {
414                                                         ex.printStackTrace();
415                                                 }
416                                         }
417                                 }.start();
418                                 break;
419                                 case 10:
420                                 new Thread() {
421                                         public void run() {
422                                                 try {
423                                                         ___getBrightnessRangeLowerBound();
424                                                 }
425                                                 catch (Exception ex) {
426                                                         ex.printStackTrace();
427                                                 }
428                                         }
429                                 }.start();
430                                 break;
431                                 case 11:
432                                 new Thread() {
433                                         public void run() {
434                                                 try {
435                                                         ___getBrightnessRangeUpperBound();
436                                                 }
437                                                 catch (Exception ex) {
438                                                         ex.printStackTrace();
439                                                 }
440                                         }
441                                 }.start();
442                                 break;
443                                 case 12:
444                                 new Thread() {
445                                         public void run() {
446                                                 try {
447                                                         ___getHueRangeLowerBound();
448                                                 }
449                                                 catch (Exception ex) {
450                                                         ex.printStackTrace();
451                                                 }
452                                         }
453                                 }.start();
454                                 break;
455                                 case 13:
456                                 new Thread() {
457                                         public void run() {
458                                                 try {
459                                                         ___getHueRangeUpperBound();
460                                                 }
461                                                 catch (Exception ex) {
462                                                         ex.printStackTrace();
463                                                 }
464                                         }
465                                 }.start();
466                                 break;
467                                 case 14:
468                                 new Thread() {
469                                         public void run() {
470                                                 try {
471                                                         ___getSaturationRangeLowerBound();
472                                                 }
473                                                 catch (Exception ex) {
474                                                         ex.printStackTrace();
475                                                 }
476                                         }
477                                 }.start();
478                                 break;
479                                 case 15:
480                                 new Thread() {
481                                         public void run() {
482                                                 try {
483                                                         ___getSaturationRangeUpperBound();
484                                                 }
485                                                 catch (Exception ex) {
486                                                         ex.printStackTrace();
487                                                 }
488                                         }
489                                 }.start();
490                                 break;
491                                 case 16:
492                                 new Thread() {
493                                         public void run() {
494                                                 try {
495                                                         ___getTemperatureRangeLowerBound();
496                                                 }
497                                                 catch (Exception ex) {
498                                                         ex.printStackTrace();
499                                                 }
500                                         }
501                                 }.start();
502                                 break;
503                                 case 17:
504                                 new Thread() {
505                                         public void run() {
506                                                 try {
507                                                         ___getTemperatureRangeUpperBound();
508                                                 }
509                                                 catch (Exception ex) {
510                                                         ex.printStackTrace();
511                                                 }
512                                         }
513                                 }.start();
514                                 break;
515                                 default: 
516                                 throw new Error("Method Id " + methodId + " not recognized!");
517                         }
518                 }
519         }
520
521 }