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