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