e533d08f6336054b807bda2285565f07813740d2
[iot2.git] / benchmarks / drivers / Cpp / LifxLightBulb / LightBulb_Skeleton.cpp
1 #include <iostream>
2 #include "LightBulb_Skeleton.hpp"
3
4 using namespace std;
5
6 LightBulb_Skeleton::LightBulb_Skeleton(LightBulb *_mainObj, int _portSend, int _portRecv) {
7         bool _bResult = false;
8         mainObj = _mainObj;
9         rmiComm = new IoTRMICommServer(_portSend, _portRecv, &_bResult);
10         IoTRMIUtil::mapSkel->insert(make_pair(_mainObj, this));
11         IoTRMIUtil::mapSkelId->insert(make_pair(_mainObj, objectId));
12         rmiComm->registerSkeleton(objectId, &methodReceived);
13         thread th1 (&LightBulb_Skeleton::___waitRequestInvokeMethod, this, this);
14         th1.join();
15 }
16
17 LightBulb_Skeleton::LightBulb_Skeleton(LightBulb *_mainObj, IoTRMIComm *_rmiComm, int _objectId) {
18         bool _bResult = false;
19         mainObj = _mainObj;
20         rmiComm = _rmiComm;
21         objectId = _objectId;
22         rmiComm->registerSkeleton(objectId, &methodReceived);
23 }
24
25 LightBulb_Skeleton::~LightBulb_Skeleton() {
26         if (rmiComm != NULL) {
27                 delete rmiComm;
28                 rmiComm = NULL;
29         }
30 }
31
32 bool LightBulb_Skeleton::didInitWaitInvoke() {
33         return didAlreadyInitWaitInvoke;
34 }
35
36 void LightBulb_Skeleton::init() {
37         mainObj->init();
38 }
39
40 void LightBulb_Skeleton::turnOff() {
41         mainObj->turnOff();
42 }
43
44 void LightBulb_Skeleton::turnOn() {
45         mainObj->turnOn();
46 }
47
48 bool LightBulb_Skeleton::getState() {
49         return mainObj->getState();
50 }
51
52 void LightBulb_Skeleton::setColor(double _hue, double _saturation, double _brightness) {
53         mainObj->setColor(_hue, _saturation, _brightness);
54 }
55
56 void LightBulb_Skeleton::setTemperature(int _temperature) {
57         mainObj->setTemperature(_temperature);
58 }
59
60 double LightBulb_Skeleton::getBrightness() {
61         return mainObj->getBrightness();
62 }
63
64 double LightBulb_Skeleton::getHue() {
65         return mainObj->getHue();
66 }
67
68 double LightBulb_Skeleton::getSaturation() {
69         return mainObj->getSaturation();
70 }
71
72 int LightBulb_Skeleton::getTemperature() {
73         return mainObj->getTemperature();
74 }
75
76 double LightBulb_Skeleton::getBrightnessRangeLowerBound() {
77         return mainObj->getBrightnessRangeLowerBound();
78 }
79
80 double LightBulb_Skeleton::getBrightnessRangeUpperBound() {
81         return mainObj->getBrightnessRangeUpperBound();
82 }
83
84 double LightBulb_Skeleton::getHueRangeLowerBound() {
85         return mainObj->getHueRangeLowerBound();
86 }
87
88 double LightBulb_Skeleton::getHueRangeUpperBound() {
89         return mainObj->getHueRangeUpperBound();
90 }
91
92 double LightBulb_Skeleton::getSaturationRangeLowerBound() {
93         return mainObj->getSaturationRangeLowerBound();
94 }
95
96 double LightBulb_Skeleton::getSaturationRangeUpperBound() {
97         return mainObj->getSaturationRangeUpperBound();
98 }
99
100 int LightBulb_Skeleton::getTemperatureRangeLowerBound() {
101         return mainObj->getTemperatureRangeLowerBound();
102 }
103
104 int LightBulb_Skeleton::getTemperatureRangeUpperBound() {
105         return mainObj->getTemperatureRangeUpperBound();
106 }
107
108 void LightBulb_Skeleton::___init(LightBulb_Skeleton* skel) {
109         char* localMethodBytes = new char[methodLen];
110         memcpy(localMethodBytes, skel->methodBytes, methodLen);
111         didGetMethodBytes.exchange(true);
112         string paramCls[] = {  };
113         int numParam = 0;
114         void* paramObj[] = {  };
115         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
116         init();
117         delete[] localMethodBytes;
118 }
119
120 void LightBulb_Skeleton::___turnOff(LightBulb_Skeleton* skel) {
121         char* localMethodBytes = new char[methodLen];
122         memcpy(localMethodBytes, skel->methodBytes, methodLen);
123         didGetMethodBytes.exchange(true);
124         string paramCls[] = {  };
125         int numParam = 0;
126         void* paramObj[] = {  };
127         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
128         turnOff();
129         delete[] localMethodBytes;
130 }
131
132 void LightBulb_Skeleton::___turnOn(LightBulb_Skeleton* skel) {
133         char* localMethodBytes = new char[methodLen];
134         memcpy(localMethodBytes, skel->methodBytes, methodLen);
135         didGetMethodBytes.exchange(true);
136         string paramCls[] = {  };
137         int numParam = 0;
138         void* paramObj[] = {  };
139         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
140         turnOn();
141         delete[] localMethodBytes;
142 }
143
144 void LightBulb_Skeleton::___getState(LightBulb_Skeleton* skel) {
145         char* localMethodBytes = new char[methodLen];
146         memcpy(localMethodBytes, skel->methodBytes, methodLen);
147         didGetMethodBytes.exchange(true);
148         string paramCls[] = {  };
149         int numParam = 0;
150         void* paramObj[] = {  };
151         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
152         bool retVal = getState();
153         void* retObj = &retVal;
154         rmiComm->sendReturnObj(retObj, "boolean", localMethodBytes);
155         delete[] localMethodBytes;
156 }
157
158 void LightBulb_Skeleton::___setColor(LightBulb_Skeleton* skel) {
159         char* localMethodBytes = new char[methodLen];
160         memcpy(localMethodBytes, skel->methodBytes, methodLen);
161         didGetMethodBytes.exchange(true);
162         string paramCls[] = { "double", "double", "double" };
163         int numParam = 3;
164         double _hue;
165         double _saturation;
166         double _brightness;
167         void* paramObj[] = { &_hue, &_saturation, &_brightness };
168         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
169         setColor(_hue, _saturation, _brightness);
170         delete[] localMethodBytes;
171 }
172
173 void LightBulb_Skeleton::___setTemperature(LightBulb_Skeleton* skel) {
174         char* localMethodBytes = new char[methodLen];
175         memcpy(localMethodBytes, skel->methodBytes, methodLen);
176         didGetMethodBytes.exchange(true);
177         string paramCls[] = { "int" };
178         int numParam = 1;
179         int _temperature;
180         void* paramObj[] = { &_temperature };
181         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
182         setTemperature(_temperature);
183         delete[] localMethodBytes;
184 }
185
186 void LightBulb_Skeleton::___getBrightness(LightBulb_Skeleton* skel) {
187         char* localMethodBytes = new char[methodLen];
188         memcpy(localMethodBytes, skel->methodBytes, methodLen);
189         didGetMethodBytes.exchange(true);
190         string paramCls[] = {  };
191         int numParam = 0;
192         void* paramObj[] = {  };
193         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
194         double retVal = getBrightness();
195         void* retObj = &retVal;
196         rmiComm->sendReturnObj(retObj, "double", localMethodBytes);
197         delete[] localMethodBytes;
198 }
199
200 void LightBulb_Skeleton::___getHue(LightBulb_Skeleton* skel) {
201         char* localMethodBytes = new char[methodLen];
202         memcpy(localMethodBytes, skel->methodBytes, methodLen);
203         didGetMethodBytes.exchange(true);
204         string paramCls[] = {  };
205         int numParam = 0;
206         void* paramObj[] = {  };
207         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
208         double retVal = getHue();
209         void* retObj = &retVal;
210         rmiComm->sendReturnObj(retObj, "double", localMethodBytes);
211         delete[] localMethodBytes;
212 }
213
214 void LightBulb_Skeleton::___getSaturation(LightBulb_Skeleton* skel) {
215         char* localMethodBytes = new char[methodLen];
216         memcpy(localMethodBytes, skel->methodBytes, methodLen);
217         didGetMethodBytes.exchange(true);
218         string paramCls[] = {  };
219         int numParam = 0;
220         void* paramObj[] = {  };
221         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
222         double retVal = getSaturation();
223         void* retObj = &retVal;
224         rmiComm->sendReturnObj(retObj, "double", localMethodBytes);
225         delete[] localMethodBytes;
226 }
227
228 void LightBulb_Skeleton::___getTemperature(LightBulb_Skeleton* skel) {
229         char* localMethodBytes = new char[methodLen];
230         memcpy(localMethodBytes, skel->methodBytes, methodLen);
231         didGetMethodBytes.exchange(true);
232         string paramCls[] = {  };
233         int numParam = 0;
234         void* paramObj[] = {  };
235         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
236         int retVal = getTemperature();
237         void* retObj = &retVal;
238         rmiComm->sendReturnObj(retObj, "int", localMethodBytes);
239         delete[] localMethodBytes;
240 }
241
242 void LightBulb_Skeleton::___getBrightnessRangeLowerBound(LightBulb_Skeleton* skel) {
243         char* localMethodBytes = new char[methodLen];
244         memcpy(localMethodBytes, skel->methodBytes, methodLen);
245         didGetMethodBytes.exchange(true);
246         string paramCls[] = {  };
247         int numParam = 0;
248         void* paramObj[] = {  };
249         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
250         double retVal = getBrightnessRangeLowerBound();
251         void* retObj = &retVal;
252         rmiComm->sendReturnObj(retObj, "double", localMethodBytes);
253         delete[] localMethodBytes;
254 }
255
256 void LightBulb_Skeleton::___getBrightnessRangeUpperBound(LightBulb_Skeleton* skel) {
257         char* localMethodBytes = new char[methodLen];
258         memcpy(localMethodBytes, skel->methodBytes, methodLen);
259         didGetMethodBytes.exchange(true);
260         string paramCls[] = {  };
261         int numParam = 0;
262         void* paramObj[] = {  };
263         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
264         double retVal = getBrightnessRangeUpperBound();
265         void* retObj = &retVal;
266         rmiComm->sendReturnObj(retObj, "double", localMethodBytes);
267         delete[] localMethodBytes;
268 }
269
270 void LightBulb_Skeleton::___getHueRangeLowerBound(LightBulb_Skeleton* skel) {
271         char* localMethodBytes = new char[methodLen];
272         memcpy(localMethodBytes, skel->methodBytes, methodLen);
273         didGetMethodBytes.exchange(true);
274         string paramCls[] = {  };
275         int numParam = 0;
276         void* paramObj[] = {  };
277         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
278         double retVal = getHueRangeLowerBound();
279         void* retObj = &retVal;
280         rmiComm->sendReturnObj(retObj, "double", localMethodBytes);
281         delete[] localMethodBytes;
282 }
283
284 void LightBulb_Skeleton::___getHueRangeUpperBound(LightBulb_Skeleton* skel) {
285         char* localMethodBytes = new char[methodLen];
286         memcpy(localMethodBytes, skel->methodBytes, methodLen);
287         didGetMethodBytes.exchange(true);
288         string paramCls[] = {  };
289         int numParam = 0;
290         void* paramObj[] = {  };
291         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
292         double retVal = getHueRangeUpperBound();
293         void* retObj = &retVal;
294         rmiComm->sendReturnObj(retObj, "double", localMethodBytes);
295         delete[] localMethodBytes;
296 }
297
298 void LightBulb_Skeleton::___getSaturationRangeLowerBound(LightBulb_Skeleton* skel) {
299         char* localMethodBytes = new char[methodLen];
300         memcpy(localMethodBytes, skel->methodBytes, methodLen);
301         didGetMethodBytes.exchange(true);
302         string paramCls[] = {  };
303         int numParam = 0;
304         void* paramObj[] = {  };
305         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
306         double retVal = getSaturationRangeLowerBound();
307         void* retObj = &retVal;
308         rmiComm->sendReturnObj(retObj, "double", localMethodBytes);
309         delete[] localMethodBytes;
310 }
311
312 void LightBulb_Skeleton::___getSaturationRangeUpperBound(LightBulb_Skeleton* skel) {
313         char* localMethodBytes = new char[methodLen];
314         memcpy(localMethodBytes, skel->methodBytes, methodLen);
315         didGetMethodBytes.exchange(true);
316         string paramCls[] = {  };
317         int numParam = 0;
318         void* paramObj[] = {  };
319         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
320         double retVal = getSaturationRangeUpperBound();
321         void* retObj = &retVal;
322         rmiComm->sendReturnObj(retObj, "double", localMethodBytes);
323         delete[] localMethodBytes;
324 }
325
326 void LightBulb_Skeleton::___getTemperatureRangeLowerBound(LightBulb_Skeleton* skel) {
327         char* localMethodBytes = new char[methodLen];
328         memcpy(localMethodBytes, skel->methodBytes, methodLen);
329         didGetMethodBytes.exchange(true);
330         string paramCls[] = {  };
331         int numParam = 0;
332         void* paramObj[] = {  };
333         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
334         int retVal = getTemperatureRangeLowerBound();
335         void* retObj = &retVal;
336         rmiComm->sendReturnObj(retObj, "int", localMethodBytes);
337         delete[] localMethodBytes;
338 }
339
340 void LightBulb_Skeleton::___getTemperatureRangeUpperBound(LightBulb_Skeleton* skel) {
341         char* localMethodBytes = new char[methodLen];
342         memcpy(localMethodBytes, skel->methodBytes, methodLen);
343         didGetMethodBytes.exchange(true);
344         string paramCls[] = {  };
345         int numParam = 0;
346         void* paramObj[] = {  };
347         rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
348         int retVal = getTemperatureRangeUpperBound();
349         void* retObj = &retVal;
350         rmiComm->sendReturnObj(retObj, "int", localMethodBytes);
351         delete[] localMethodBytes;
352 }
353
354 void LightBulb_Skeleton::___waitRequestInvokeMethod(LightBulb_Skeleton* skel) {
355         skel->didAlreadyInitWaitInvoke = true;
356         while (true) {
357                 if (!methodReceived) {
358                         continue;
359                 }
360                 skel->methodBytes = skel->rmiComm->getMethodBytes();
361                 skel->methodLen = skel->rmiComm->getMethodLength();
362                 methodReceived = false;
363                 int _objectId = skel->rmiComm->getObjectId(skel->methodBytes);
364                 int methodId = skel->rmiComm->getMethodId(skel->methodBytes);
365                 if (_objectId == objectId) {
366                         if (set0Allowed.find(methodId) == set0Allowed.end()) {
367                                 cerr << "Object with object Id: " << _objectId << "  is not allowed to access method: " << methodId << endl;
368                                 return;
369                         }
370                 }
371                 else {
372                         continue;
373                 }
374                 switch (methodId) {
375                         case 0: {
376                                 thread th0 (&LightBulb_Skeleton::___init, std::ref(skel), skel);
377                                 th0.detach(); break;
378                         }
379                         case 1: {
380                                 thread th1 (&LightBulb_Skeleton::___turnOff, std::ref(skel), skel);
381                                 th1.detach(); break;
382                         }
383                         case 2: {
384                                 thread th2 (&LightBulb_Skeleton::___turnOn, std::ref(skel), skel);
385                                 th2.detach(); break;
386                         }
387                         case 3: {
388                                 thread th3 (&LightBulb_Skeleton::___getState, std::ref(skel), skel);
389                                 th3.detach(); break;
390                         }
391                         case 4: {
392                                 thread th4 (&LightBulb_Skeleton::___setColor, std::ref(skel), skel);
393                                 th4.detach(); break;
394                         }
395                         case 5: {
396                                 thread th5 (&LightBulb_Skeleton::___setTemperature, std::ref(skel), skel);
397                                 th5.detach(); break;
398                         }
399                         case 6: {
400                                 thread th6 (&LightBulb_Skeleton::___getBrightness, std::ref(skel), skel);
401                                 th6.detach(); break;
402                         }
403                         case 7: {
404                                 thread th7 (&LightBulb_Skeleton::___getHue, std::ref(skel), skel);
405                                 th7.detach(); break;
406                         }
407                         case 8: {
408                                 thread th8 (&LightBulb_Skeleton::___getSaturation, std::ref(skel), skel);
409                                 th8.detach(); break;
410                         }
411                         case 9: {
412                                 thread th9 (&LightBulb_Skeleton::___getTemperature, std::ref(skel), skel);
413                                 th9.detach(); break;
414                         }
415                         case 10: {
416                                 thread th10 (&LightBulb_Skeleton::___getBrightnessRangeLowerBound, std::ref(skel), skel);
417                                 th10.detach(); break;
418                         }
419                         case 11: {
420                                 thread th11 (&LightBulb_Skeleton::___getBrightnessRangeUpperBound, std::ref(skel), skel);
421                                 th11.detach(); break;
422                         }
423                         case 12: {
424                                 thread th12 (&LightBulb_Skeleton::___getHueRangeLowerBound, std::ref(skel), skel);
425                                 th12.detach(); break;
426                         }
427                         case 13: {
428                                 thread th13 (&LightBulb_Skeleton::___getHueRangeUpperBound, std::ref(skel), skel);
429                                 th13.detach(); break;
430                         }
431                         case 14: {
432                                 thread th14 (&LightBulb_Skeleton::___getSaturationRangeLowerBound, std::ref(skel), skel);
433                                 th14.detach(); break;
434                         }
435                         case 15: {
436                                 thread th15 (&LightBulb_Skeleton::___getSaturationRangeUpperBound, std::ref(skel), skel);
437                                 th15.detach(); break;
438                         }
439                         case 16: {
440                                 thread th16 (&LightBulb_Skeleton::___getTemperatureRangeLowerBound, std::ref(skel), skel);
441                                 th16.detach(); break;
442                         }
443                         case 17: {
444                                 thread th17 (&LightBulb_Skeleton::___getTemperatureRangeUpperBound, std::ref(skel), skel);
445                                 th17.detach(); break;
446                         }
447                         default: 
448                         cerr << "Method Id " << methodId << " not recognized!" << endl;
449                         return;
450                 }
451         }
452 }
453
454 extern "C" void* createLightBulb_Skeleton(void** params) {
455         // Args: *_mainObj, int _portSend, int _portRecv
456         return new LightBulb_Skeleton((LightBulb*) params[0], *((int*) params[0]), *((int*) params[1]));
457 }
458
459 extern "C" void destroyLightBulb_Skeleton(void* t) {
460         LightBulb_Skeleton* obj = (LightBulb_Skeleton*) t;
461         delete obj;
462 }
463
464 extern "C" void initLightBulb_Skeleton(void* t) {
465 }
466
467 int main() {
468         return 0;
469 }