Moving Java drivers; Creating iotruntime socket connections for C++; First version...
[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 iotrmi.Java.IoTRMICall;
8 import iotrmi.Java.IoTRMIObject;
9
10 import iotcode.interfaces.LightBulb;
11
12 public class LightBulb_Skeleton implements LightBulb {
13
14         private LightBulb mainObj;
15         private IoTRMIObject rmiObj;
16
17         private String callbackAddress;
18         private final static int object0Id = 0; //LightBulbSmart
19         private static Integer[] object0Permission = { 2, 10, 1, 3, 11, 8, 12, 7, 13, 9, 6, 16, 17, 4, 0, 14, 15, 5 };
20         private static List<Integer> set0Allowed;
21         
22
23         public LightBulb_Skeleton(LightBulb _mainObj, String _callbackAddress, int _port) throws Exception {
24                 mainObj = _mainObj;
25                 callbackAddress = _callbackAddress;
26                 rmiObj = new IoTRMIObject(_port);
27                 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
28                 ___waitRequestInvokeMethod();
29         }
30
31         public void init() {
32                 mainObj.init();
33         }
34
35         public void turnOff() {
36                 mainObj.turnOff();
37         }
38
39         public void turnOn() {
40                 mainObj.turnOn();
41         }
42
43         public boolean getState() {
44                 return mainObj.getState();
45         }
46
47         public void setColor(double _hue, double _saturation, double _brightness) {
48                 mainObj.setColor(_hue, _saturation, _brightness);
49         }
50
51         public void setTemperature(int _temperature) {
52                 mainObj.setTemperature(_temperature);
53         }
54
55         public double getBrightness() {
56                 return mainObj.getBrightness();
57         }
58
59         public double getHue() {
60                 return mainObj.getHue();
61         }
62
63         public double getSaturation() {
64                 return mainObj.getSaturation();
65         }
66
67         public int getTemperature() {
68                 return mainObj.getTemperature();
69         }
70
71         public double getBrightnessRangeLowerBound() {
72                 return mainObj.getBrightnessRangeLowerBound();
73         }
74
75         public double getBrightnessRangeUpperBound() {
76                 return mainObj.getBrightnessRangeUpperBound();
77         }
78
79         public double getHueRangeLowerBound() {
80                 return mainObj.getHueRangeLowerBound();
81         }
82
83         public double getHueRangeUpperBound() {
84                 return mainObj.getHueRangeUpperBound();
85         }
86
87         public double getSaturationRangeLowerBound() {
88                 return mainObj.getSaturationRangeLowerBound();
89         }
90
91         public double getSaturationRangeUpperBound() {
92                 return mainObj.getSaturationRangeUpperBound();
93         }
94
95         public int getTemperatureRangeLowerBound() {
96                 return mainObj.getTemperatureRangeLowerBound();
97         }
98
99         public int getTemperatureRangeUpperBound() {
100                 return mainObj.getTemperatureRangeUpperBound();
101         }
102
103         public void ___init() {
104                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
105                 new Class<?>[] {  });
106                 init();
107         }
108
109         public void ___turnOff() {
110                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
111                 new Class<?>[] {  });
112                 turnOff();
113         }
114
115         public void ___turnOn() {
116                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
117                 new Class<?>[] {  });
118                 turnOn();
119         }
120
121         public void ___getState() throws IOException {
122                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
123                 new Class<?>[] {  });
124                 Object retObj = getState();
125                 rmiObj.sendReturnObj(retObj);
126         }
127
128         public void ___setColor() {
129                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { double.class, double.class, double.class }, 
130                 new Class<?>[] { null, null, null });
131                 setColor((double) paramObj[0], (double) paramObj[1], (double) paramObj[2]);
132         }
133
134         public void ___setTemperature() {
135                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
136                 new Class<?>[] { null });
137                 setTemperature((int) paramObj[0]);
138         }
139
140         public void ___getBrightness() throws IOException {
141                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
142                 new Class<?>[] {  });
143                 Object retObj = getBrightness();
144                 rmiObj.sendReturnObj(retObj);
145         }
146
147         public void ___getHue() throws IOException {
148                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
149                 new Class<?>[] {  });
150                 Object retObj = getHue();
151                 rmiObj.sendReturnObj(retObj);
152         }
153
154         public void ___getSaturation() throws IOException {
155                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
156                 new Class<?>[] {  });
157                 Object retObj = getSaturation();
158                 rmiObj.sendReturnObj(retObj);
159         }
160
161         public void ___getTemperature() throws IOException {
162                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
163                 new Class<?>[] {  });
164                 Object retObj = getTemperature();
165                 rmiObj.sendReturnObj(retObj);
166         }
167
168         public void ___getBrightnessRangeLowerBound() throws IOException {
169                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
170                 new Class<?>[] {  });
171                 Object retObj = getBrightnessRangeLowerBound();
172                 rmiObj.sendReturnObj(retObj);
173         }
174
175         public void ___getBrightnessRangeUpperBound() throws IOException {
176                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
177                 new Class<?>[] {  });
178                 Object retObj = getBrightnessRangeUpperBound();
179                 rmiObj.sendReturnObj(retObj);
180         }
181
182         public void ___getHueRangeLowerBound() throws IOException {
183                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
184                 new Class<?>[] {  });
185                 Object retObj = getHueRangeLowerBound();
186                 rmiObj.sendReturnObj(retObj);
187         }
188
189         public void ___getHueRangeUpperBound() throws IOException {
190                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
191                 new Class<?>[] {  });
192                 Object retObj = getHueRangeUpperBound();
193                 rmiObj.sendReturnObj(retObj);
194         }
195
196         public void ___getSaturationRangeLowerBound() throws IOException {
197                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
198                 new Class<?>[] {  });
199                 Object retObj = getSaturationRangeLowerBound();
200                 rmiObj.sendReturnObj(retObj);
201         }
202
203         public void ___getSaturationRangeUpperBound() throws IOException {
204                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
205                 new Class<?>[] {  });
206                 Object retObj = getSaturationRangeUpperBound();
207                 rmiObj.sendReturnObj(retObj);
208         }
209
210         public void ___getTemperatureRangeLowerBound() throws IOException {
211                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
212                 new Class<?>[] {  });
213                 Object retObj = getTemperatureRangeLowerBound();
214                 rmiObj.sendReturnObj(retObj);
215         }
216
217         public void ___getTemperatureRangeUpperBound() throws IOException {
218                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
219                 new Class<?>[] {  });
220                 Object retObj = getTemperatureRangeUpperBound();
221                 rmiObj.sendReturnObj(retObj);
222         }
223
224         private void ___waitRequestInvokeMethod() throws IOException {
225                 while (true) {
226                         rmiObj.getMethodBytes();
227                         int _objectId = rmiObj.getObjectId();
228                         int methodId = rmiObj.getMethodId();
229                         if (_objectId == object0Id) {
230                                 if (!set0Allowed.contains(methodId)) {
231                                         throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
232                                 }
233                         }
234                         else {
235                                 throw new Error("Object Id: " + _objectId + " not recognized!");
236                         }
237                         switch (methodId) {
238                                 case 0: ___init(); break;
239                                 case 1: ___turnOff(); break;
240                                 case 2: ___turnOn(); break;
241                                 case 3: ___getState(); break;
242                                 case 4: ___setColor(); break;
243                                 case 5: ___setTemperature(); break;
244                                 case 6: ___getBrightness(); break;
245                                 case 7: ___getHue(); break;
246                                 case 8: ___getSaturation(); break;
247                                 case 9: ___getTemperature(); break;
248                                 case 10: ___getBrightnessRangeLowerBound(); break;
249                                 case 11: ___getBrightnessRangeUpperBound(); break;
250                                 case 12: ___getHueRangeLowerBound(); break;
251                                 case 13: ___getHueRangeUpperBound(); break;
252                                 case 14: ___getSaturationRangeLowerBound(); break;
253                                 case 15: ___getSaturationRangeUpperBound(); break;
254                                 case 16: ___getTemperatureRangeLowerBound(); break;
255                                 case 17: ___getTemperatureRangeUpperBound(); break;
256                                 default: 
257                                 throw new Error("Method Id " + methodId + " not recognized!");
258                         }
259                 }
260         }
261
262 }