Updating skeletons and stubs for C++; Fixing one bug in IoTCompiler for C++ skeleton...
[iot2.git] / benchmarks / Cpp / Lifxtest / LightBulbTest_Stub.cpp
1 #include <iostream>
2 #include "LightBulbTest_Stub.hpp"
3
4 using namespace std;
5
6 LightBulbTest_Stub::LightBulbTest_Stub(int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult) {
7         rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev, _bResult);
8         rmiComm->registerStub(objectId, 6, &retValueReceived6);
9         rmiComm->registerStub(objectId, 3, &retValueReceived3);
10         rmiComm->registerStub(objectId, 8, &retValueReceived8);
11         rmiComm->registerStub(objectId, 7, &retValueReceived7);
12         rmiComm->registerStub(objectId, 9, &retValueReceived9);
13         IoTRMIUtil::mapStub->insert(make_pair(objectId, this));
14 }
15
16 LightBulbTest_Stub::LightBulbTest_Stub(IoTRMIComm* _rmiComm, int _objectId) {
17         rmiComm = _rmiComm;
18         objectId = _objectId;
19         rmiComm->registerStub(objectId, 6, &retValueReceived6);
20         rmiComm->registerStub(objectId, 3, &retValueReceived3);
21         rmiComm->registerStub(objectId, 8, &retValueReceived8);
22         rmiComm->registerStub(objectId, 7, &retValueReceived7);
23         rmiComm->registerStub(objectId, 9, &retValueReceived9);
24 }
25
26 LightBulbTest_Stub::~LightBulbTest_Stub() {
27         if (rmiComm != NULL) {
28                 delete rmiComm;
29                 rmiComm = NULL;
30         }
31 }
32
33 mutex mtxLightBulbTest_StubMethodExec2;
34 void LightBulbTest_Stub::turnOn() { 
35         lock_guard<mutex> guard(mtxLightBulbTest_StubMethodExec2);
36         int methodId = 2;
37         string retType = "void";
38         int numParam = 0;
39         string paramCls[] = {  };
40         void* paramObj[] = {  };
41         rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
42 }
43
44 mutex mtxLightBulbTest_StubMethodExec6;
45 double LightBulbTest_Stub::getBrightness() { 
46         lock_guard<mutex> guard(mtxLightBulbTest_StubMethodExec6);
47         int methodId = 6;
48         string retType = "double";
49         int numParam = 0;
50         string paramCls[] = {  };
51         void* paramObj[] = {  };
52         double retVal = 0;
53         void* retObj = &retVal;
54         rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
55         // Waiting for return value
56         while (!retValueReceived6);
57         rmiComm->getReturnValue(retType, retObj);
58         retValueReceived6 = false;
59         didGetReturnBytes.exchange(true);
60
61         return retVal;
62 }
63
64 mutex mtxLightBulbTest_StubMethodExec1;
65 void LightBulbTest_Stub::turnOff() { 
66         lock_guard<mutex> guard(mtxLightBulbTest_StubMethodExec1);
67         int methodId = 1;
68         string retType = "void";
69         int numParam = 0;
70         string paramCls[] = {  };
71         void* paramObj[] = {  };
72         rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
73 }
74
75 mutex mtxLightBulbTest_StubMethodExec3;
76 bool LightBulbTest_Stub::getState() { 
77         lock_guard<mutex> guard(mtxLightBulbTest_StubMethodExec3);
78         int methodId = 3;
79         string retType = "boolean";
80         int numParam = 0;
81         string paramCls[] = {  };
82         void* paramObj[] = {  };
83         bool retVal = false;
84         void* retObj = &retVal;
85         rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
86         // Waiting for return value
87         while (!retValueReceived3);
88         rmiComm->getReturnValue(retType, retObj);
89         retValueReceived3 = false;
90         didGetReturnBytes.exchange(true);
91
92         return retVal;
93 }
94
95 mutex mtxLightBulbTest_StubMethodExec4;
96 void LightBulbTest_Stub::setColor(double _hue, double _saturation, double _brightness) { 
97         lock_guard<mutex> guard(mtxLightBulbTest_StubMethodExec4);
98         int methodId = 4;
99         string retType = "void";
100         int numParam = 3;
101         string paramCls[] = { "double", "double", "double" };
102         void* paramObj[] = { &_hue, &_saturation, &_brightness };
103         rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
104 }
105
106 mutex mtxLightBulbTest_StubMethodExec8;
107 double LightBulbTest_Stub::getSaturation() { 
108         lock_guard<mutex> guard(mtxLightBulbTest_StubMethodExec8);
109         int methodId = 8;
110         string retType = "double";
111         int numParam = 0;
112         string paramCls[] = {  };
113         void* paramObj[] = {  };
114         double retVal = 0;
115         void* retObj = &retVal;
116         rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
117         // Waiting for return value
118         while (!retValueReceived8);
119         rmiComm->getReturnValue(retType, retObj);
120         retValueReceived8 = false;
121         didGetReturnBytes.exchange(true);
122
123         return retVal;
124 }
125
126 mutex mtxLightBulbTest_StubMethodExec0;
127 void LightBulbTest_Stub::init() { 
128         lock_guard<mutex> guard(mtxLightBulbTest_StubMethodExec0);
129         int methodId = 0;
130         string retType = "void";
131         int numParam = 0;
132         string paramCls[] = {  };
133         void* paramObj[] = {  };
134         rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
135 }
136
137 mutex mtxLightBulbTest_StubMethodExec5;
138 void LightBulbTest_Stub::setTemperature(int _temperature) { 
139         lock_guard<mutex> guard(mtxLightBulbTest_StubMethodExec5);
140         int methodId = 5;
141         string retType = "void";
142         int numParam = 1;
143         string paramCls[] = { "int" };
144         void* paramObj[] = { &_temperature };
145         rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
146 }
147
148 mutex mtxLightBulbTest_StubMethodExec7;
149 double LightBulbTest_Stub::getHue() { 
150         lock_guard<mutex> guard(mtxLightBulbTest_StubMethodExec7);
151         int methodId = 7;
152         string retType = "double";
153         int numParam = 0;
154         string paramCls[] = {  };
155         void* paramObj[] = {  };
156         double retVal = 0;
157         void* retObj = &retVal;
158         rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
159         // Waiting for return value
160         while (!retValueReceived7);
161         rmiComm->getReturnValue(retType, retObj);
162         retValueReceived7 = false;
163         didGetReturnBytes.exchange(true);
164
165         return retVal;
166 }
167
168 mutex mtxLightBulbTest_StubMethodExec9;
169 int LightBulbTest_Stub::getTemperature() { 
170         lock_guard<mutex> guard(mtxLightBulbTest_StubMethodExec9);
171         int methodId = 9;
172         string retType = "int";
173         int numParam = 0;
174         string paramCls[] = {  };
175         void* paramObj[] = {  };
176         int retVal = 0;
177         void* retObj = &retVal;
178         rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
179         // Waiting for return value
180         while (!retValueReceived9);
181         rmiComm->getReturnValue(retType, retObj);
182         retValueReceived9 = false;
183         didGetReturnBytes.exchange(true);
184
185         return retVal;
186 }
187
188 extern "C" void* createLightBulbTest_Stub(void** params) {
189         // Args: int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult
190         return new LightBulbTest_Stub(*((int*) params[0]), *((int*) params[1]), ((string*) params[2])->c_str(), *((int*) params[3]), (bool*) params[4]);
191 }
192
193 extern "C" void destroyLightBulbTest_Stub(void* t) {
194         LightBulbTest_Stub* obj = (LightBulbTest_Stub*) t;
195         delete obj;
196 }
197
198 extern "C" void initLightBulbTest_Stub(void* t) {
199 }
200
201 int main() {
202         return 0;
203 }