Working C++ IoTSlave for both IoTSet and IoTRelation; threading works for C++ LifxLig...
[iot2.git] / benchmarks / Cpp / Lifxtest / LightBulbTest_Stub.hpp
1 #ifndef _LIGHTBULBTEST_STUB_HPP__
2 #define _LIGHTBULBTEST_STUB_HPP__
3 #include <iostream>
4 #include <fstream>
5 #include "LightBulbTest.hpp"
6
7 using namespace std;
8
9 class LightBulbTest_Stub : public LightBulbTest
10 {
11         private:
12
13         IoTRMICall *rmiCall;
14         string callbackAddress;
15         vector<int> ports;
16
17         const static int objectId = 0;
18
19         ofstream log;
20
21         public:
22
23         LightBulbTest_Stub() { }
24         
25         LightBulbTest_Stub(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {
26                 callbackAddress = _callbackAddress;
27                 ports = _ports;
28                 // Logging
29                 int i=0;
30                 string file = "LightBulbTest_Stub_cpp" + to_string(i) + ".log";
31                 while (ifstream(file.c_str())) {
32                         i++;
33                         file = "LightBulbTest_Stub_cpp" + to_string(i) + ".log";
34                 }
35                 log.open(file);
36                 log << "Port: " << _port << endl;
37                 log << "Skeleton address: " << _skeletonAddress << endl;
38                 log << "Callback address: " << callbackAddress << endl;
39                 log << "Rev: " << _rev << endl;
40                 log << "bResult: " << *_bResult << endl;
41                 log << "Ports: " << _ports[0] << endl;
42                 rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev, _bResult);
43                 log << "Established connection with skeleton!" << endl;
44                 //log.close();
45         }
46
47         ~LightBulbTest_Stub() {
48                 if (rmiCall != NULL) {
49                         delete rmiCall;
50                         rmiCall = NULL;
51                 }
52         }
53         
54         void turnOn() {
55                 log << "Calling turnOn() in stub!" << endl;
56                 int methodId = 2;
57                 string retType = "void";
58                 int numParam = 0;
59                 string paramCls[] = {  };
60                 void* paramObj[] = {  };
61                 void* retObj = NULL;
62                 log << "About to remote call!" << endl;
63                 rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
64                 log << "Remote call performed!" << endl;
65         }
66
67         double getBrightness() { 
68                 int methodId = 6;
69                 string retType = "double";
70                 int numParam = 0;
71                 string paramCls[] = {  };
72                 void* paramObj[] = {  };
73                 double retVal = 0;
74                 void* retObj = &retVal;
75                 rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
76                 return retVal;
77         }
78
79         void turnOff() {
80                 log << "Calling turnOff() in stub!" << endl;
81                 int methodId = 1;
82                 string retType = "void";
83                 int numParam = 0;
84                 string paramCls[] = {  };
85                 void* paramObj[] = {  };
86                 void* retObj = NULL;
87                 log << "About to remote call!" << endl;
88                 rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
89                 log << "Remote call performed!" << endl;
90         }
91
92         bool getState() { 
93                 int methodId = 3;
94                 string retType = "boolean";
95                 int numParam = 0;
96                 string paramCls[] = {  };
97                 void* paramObj[] = {  };
98                 bool retVal = false;
99                 void* retObj = &retVal;
100                 rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
101                 return retVal;
102         }
103
104         void setColor(double _hue, double _saturation, double _brightness) { 
105                 int methodId = 4;
106                 string retType = "void";
107                 int numParam = 3;
108                 string paramCls[] = { "double", "double", "double" };
109                 void* paramObj[] = { &_hue, &_saturation, &_brightness };
110                 void* retObj = NULL;
111                 rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
112         }
113
114         double getSaturation() { 
115                 int methodId = 8;
116                 string retType = "double";
117                 int numParam = 0;
118                 string paramCls[] = {  };
119                 void* paramObj[] = {  };
120                 double retVal = 0;
121                 void* retObj = &retVal;
122                 rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
123                 return retVal;
124         }
125
126         void init() {
127                 log << "Calling init() in stub!" << endl;
128                 int methodId = 0;
129                 string retType = "void";
130                 int numParam = 0;
131                 string paramCls[] = {  };
132                 void* paramObj[] = {  };
133                 void* retObj = NULL;
134                 log << "About to remote call!" << endl;
135                 rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
136                 log << "Remote call performed!" << endl;
137                 log.close();
138         }
139
140         void setTemperature(int _temperature) { 
141                 int methodId = 5;
142                 string retType = "void";
143                 int numParam = 1;
144                 string paramCls[] = { "int" };
145                 void* paramObj[] = { &_temperature };
146                 void* retObj = NULL;
147                 rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
148         }
149
150         double getHue() { 
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                 rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
159                 return retVal;
160         }
161
162         int getTemperature() { 
163                 int methodId = 9;
164                 string retType = "int";
165                 int numParam = 0;
166                 string paramCls[] = {  };
167                 void* paramObj[] = {  };
168                 int retVal = 0;
169                 void* retObj = &retVal;
170                 rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
171                 return retVal;
172         }
173
174 };
175
176 #endif