Perfecting IoTSlave for C++; Found one issue with SSH/Java process execution in which...
[iot2.git] / benchmarks / drivers / Cpp / LifxLightBulb / LightBulb_Skeleton.hpp
1 #ifndef _LIGHTBULB_SKELETON_HPP__
2 #define _LIGHTBULB_SKELETON_HPP__
3 #include <iostream>
4 #include <fstream>
5 #include "LightBulb.hpp"
6
7 #include <vector>
8 #include <set>
9 #include "IoTRMICall.hpp"
10 #include "IoTRMIObject.hpp"
11
12 using namespace std;
13
14 class LightBulb_Skeleton : public LightBulb
15 {
16         private:
17
18         LightBulb *mainObj;
19         vector<int> ports;
20         string callbackAddress;
21         IoTRMIObject *rmiObj;
22
23         const static int object0Id = 0; //LightBulbSmart
24         static set<int> set0Allowed;
25         
26         ofstream log;
27         public:
28
29         LightBulb_Skeleton(LightBulb *_mainObj, string _callbackAddress, int _port) {
30                 bool _bResult = false;
31                 mainObj = _mainObj;
32                 callbackAddress = _callbackAddress;
33                 // Logging
34                 log.open("LightBulb_Skeleton_cpp.log");
35                 log << "Callback address: " << callbackAddress << endl;
36                 log << "Port: " << _port << endl;
37                 rmiObj = new IoTRMIObject(_port, &_bResult);
38                 log << "Established connection with slave! Wait request invoke now..." << endl;
39                 ___waitRequestInvokeMethod();
40         }
41
42         ~LightBulb_Skeleton() {
43                 if (rmiObj != NULL) {
44                         delete rmiObj;
45                         rmiObj = NULL;
46                 }
47         }
48         
49         void init() {
50                 mainObj->init();
51         }
52
53         void turnOff() {
54                 mainObj->turnOff();
55         }
56
57         void turnOn() {
58                 mainObj->turnOn();
59         }
60
61         bool getState() {
62                 return mainObj->getState();
63         }
64
65         void setColor(double _hue, double _saturation, double _brightness) {
66                 mainObj->setColor(_hue, _saturation, _brightness);
67         }
68
69         void setTemperature(int _temperature) {
70                 mainObj->setTemperature(_temperature);
71         }
72
73         double getBrightness() {
74                 return mainObj->getBrightness();
75         }
76
77         double getHue() {
78                 return mainObj->getHue();
79         }
80
81         double getSaturation() {
82                 return mainObj->getSaturation();
83         }
84
85         int getTemperature() {
86                 return mainObj->getTemperature();
87         }
88
89         double getBrightnessRangeLowerBound() {
90                 return mainObj->getBrightnessRangeLowerBound();
91         }
92
93         double getBrightnessRangeUpperBound() {
94                 return mainObj->getBrightnessRangeUpperBound();
95         }
96
97         double getHueRangeLowerBound() {
98                 return mainObj->getHueRangeLowerBound();
99         }
100
101         double getHueRangeUpperBound() {
102                 return mainObj->getHueRangeUpperBound();
103         }
104
105         double getSaturationRangeLowerBound() {
106                 return mainObj->getSaturationRangeLowerBound();
107         }
108
109         double getSaturationRangeUpperBound() {
110                 return mainObj->getSaturationRangeUpperBound();
111         }
112
113         int getTemperatureRangeLowerBound() {
114                 return mainObj->getTemperatureRangeLowerBound();
115         }
116
117         int getTemperatureRangeUpperBound() {
118                 return mainObj->getTemperatureRangeUpperBound();
119         }
120
121         void ___init() {
122                 string paramCls[] = {  };
123                 int numParam = 0;
124                 void* paramObj[] = {  };
125                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
126                 init();
127         }
128
129         void ___turnOff() {
130                 string paramCls[] = {  };
131                 int numParam = 0;
132                 void* paramObj[] = {  };
133                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
134                 turnOff();
135         }
136
137         void ___turnOn() {
138                 string paramCls[] = {  };
139                 int numParam = 0;
140                 void* paramObj[] = {  };
141                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
142                 turnOn();
143         }
144
145         void ___getState() {
146                 string paramCls[] = {  };
147                 int numParam = 0;
148                 void* paramObj[] = {  };
149                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
150                 bool retVal = getState();
151                 void* retObj = &retVal;
152                 rmiObj->sendReturnObj(retObj, "boolean");
153         }
154
155         void ___setColor() {
156                 string paramCls[] = { "double", "double", "double" };
157                 int numParam = 3;
158                 double _hue;
159                 double _saturation;
160                 double _brightness;
161                 void* paramObj[] = { &_hue, &_saturation, &_brightness };
162                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
163                 setColor(_hue, _saturation, _brightness);
164         }
165
166         void ___setTemperature() {
167                 string paramCls[] = { "int" };
168                 int numParam = 1;
169                 int _temperature;
170                 void* paramObj[] = { &_temperature };
171                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
172                 setTemperature(_temperature);
173         }
174
175         void ___getBrightness() {
176                 string paramCls[] = {  };
177                 int numParam = 0;
178                 void* paramObj[] = {  };
179                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
180                 double retVal = getBrightness();
181                 void* retObj = &retVal;
182                 rmiObj->sendReturnObj(retObj, "double");
183         }
184
185         void ___getHue() {
186                 string paramCls[] = {  };
187                 int numParam = 0;
188                 void* paramObj[] = {  };
189                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
190                 double retVal = getHue();
191                 void* retObj = &retVal;
192                 rmiObj->sendReturnObj(retObj, "double");
193         }
194
195         void ___getSaturation() {
196                 string paramCls[] = {  };
197                 int numParam = 0;
198                 void* paramObj[] = {  };
199                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
200                 double retVal = getSaturation();
201                 void* retObj = &retVal;
202                 rmiObj->sendReturnObj(retObj, "double");
203         }
204
205         void ___getTemperature() {
206                 string paramCls[] = {  };
207                 int numParam = 0;
208                 void* paramObj[] = {  };
209                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
210                 int retVal = getTemperature();
211                 void* retObj = &retVal;
212                 rmiObj->sendReturnObj(retObj, "int");
213         }
214
215         void ___getBrightnessRangeLowerBound() {
216                 string paramCls[] = {  };
217                 int numParam = 0;
218                 void* paramObj[] = {  };
219                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
220                 double retVal = getBrightnessRangeLowerBound();
221                 void* retObj = &retVal;
222                 rmiObj->sendReturnObj(retObj, "double");
223         }
224
225         void ___getBrightnessRangeUpperBound() {
226                 string paramCls[] = {  };
227                 int numParam = 0;
228                 void* paramObj[] = {  };
229                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
230                 double retVal = getBrightnessRangeUpperBound();
231                 void* retObj = &retVal;
232                 rmiObj->sendReturnObj(retObj, "double");
233         }
234
235         void ___getHueRangeLowerBound() {
236                 string paramCls[] = {  };
237                 int numParam = 0;
238                 void* paramObj[] = {  };
239                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
240                 double retVal = getHueRangeLowerBound();
241                 void* retObj = &retVal;
242                 rmiObj->sendReturnObj(retObj, "double");
243         }
244
245         void ___getHueRangeUpperBound() {
246                 string paramCls[] = {  };
247                 int numParam = 0;
248                 void* paramObj[] = {  };
249                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
250                 double retVal = getHueRangeUpperBound();
251                 void* retObj = &retVal;
252                 rmiObj->sendReturnObj(retObj, "double");
253         }
254
255         void ___getSaturationRangeLowerBound() {
256                 string paramCls[] = {  };
257                 int numParam = 0;
258                 void* paramObj[] = {  };
259                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
260                 double retVal = getSaturationRangeLowerBound();
261                 void* retObj = &retVal;
262                 rmiObj->sendReturnObj(retObj, "double");
263         }
264
265         void ___getSaturationRangeUpperBound() {
266                 string paramCls[] = {  };
267                 int numParam = 0;
268                 void* paramObj[] = {  };
269                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
270                 double retVal = getSaturationRangeUpperBound();
271                 void* retObj = &retVal;
272                 rmiObj->sendReturnObj(retObj, "double");
273         }
274
275         void ___getTemperatureRangeLowerBound() {
276                 string paramCls[] = {  };
277                 int numParam = 0;
278                 void* paramObj[] = {  };
279                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
280                 int retVal = getTemperatureRangeLowerBound();
281                 void* retObj = &retVal;
282                 rmiObj->sendReturnObj(retObj, "int");
283         }
284
285         void ___getTemperatureRangeUpperBound() {
286                 string paramCls[] = {  };
287                 int numParam = 0;
288                 void* paramObj[] = {  };
289                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
290                 int retVal = getTemperatureRangeUpperBound();
291                 void* retObj = &retVal;
292                 rmiObj->sendReturnObj(retObj, "int");
293         }
294
295         void ___waitRequestInvokeMethod() {
296                 while (true) {
297                         log << "Getting into the while loop" << endl;
298                         rmiObj->getMethodBytes();
299                         log << "Getting method bytes now" << endl;
300                         log << "Method len: " << rmiObj->getMethodBytesLen() << endl;
301                         int _objectId = rmiObj->getObjectId();
302                         log << "Object Id: " << _objectId << endl;
303                         int methodId = rmiObj->getMethodId();
304                         log << "Method Id: " << methodId << endl;
305                         if (_objectId == object0Id) {
306                                 if (set0Allowed.find(methodId) == set0Allowed.end()) {
307                                         cerr << "Object with object Id: " << _objectId << "  is not allowed to access method: " << methodId << endl;
308                                         return;
309                                 }
310                         }
311                         else {
312                                 cerr << "Object Id: " << _objectId << " not recognized!" << endl;
313                                 return;
314                         }
315                         switch (methodId) {
316                                 case 0: ___init(); break;
317                                 case 1: ___turnOff(); break;
318                                 case 2: ___turnOn(); break;
319                                 case 3: ___getState(); break;
320                                 case 4: ___setColor(); break;
321                                 case 5: ___setTemperature(); break;
322                                 case 6: ___getBrightness(); break;
323                                 case 7: ___getHue(); break;
324                                 case 8: ___getSaturation(); break;
325                                 case 9: ___getTemperature(); break;
326                                 case 10: ___getBrightnessRangeLowerBound(); break;
327                                 case 11: ___getBrightnessRangeUpperBound(); break;
328                                 case 12: ___getHueRangeLowerBound(); break;
329                                 case 13: ___getHueRangeUpperBound(); break;
330                                 case 14: ___getSaturationRangeLowerBound(); break;
331                                 case 15: ___getSaturationRangeUpperBound(); break;
332                                 case 16: ___getTemperatureRangeLowerBound(); break;
333                                 case 17: ___getTemperatureRangeUpperBound(); break;
334                                 default: 
335                                 cerr << "Method Id " << methodId << " not recognized!" << endl;
336                                 throw exception();
337                         }
338                 }
339                 log.close();
340         }
341
342 };
343 set<int> LightBulb_Skeleton::set0Allowed { 2, 10, 1, 3, 11, 8, 12, 7, 13, 9, 6, 16, 17, 4, 0, 14, 15, 5 };
344
345 #endif