Working C++ IoTSlave for both IoTSet and IoTRelation; threading works for C++ LifxLig...
[iot2.git] / benchmarks / Cpp / Lifxtest / RoomSmart_Stub.hpp
1 #ifndef _ROOMSMART_STUB_HPP__
2 #define _ROOMSMART_STUB_HPP__
3 #include <iostream>
4 #include <fstream>
5 #include "RoomSmart.hpp"
6
7 using namespace std;
8
9 class RoomSmart_Stub : public RoomSmart
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         public:
21
22         RoomSmart_Stub() { }
23         
24         RoomSmart_Stub(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {
25                 callbackAddress = _callbackAddress;
26                 ports = _ports;
27                 // Logging
28                 int i=0;
29                 string file = "RoomSmart_Stub_cpp" + to_string(i) + ".log";
30                 while (ifstream(file.c_str())) {
31                         i++;
32                         file = "RoomSmart_Stub_cpp" + to_string(i) + ".log";
33                 }
34                 log.open(file);
35                 log << "Port: " << _port << endl;
36                 log << "Skeleton address: " << _skeletonAddress << endl;
37                 log << "Callback address: " << callbackAddress << endl;
38                 log << "Rev: " << _rev << endl;
39                 log << "bResult: " << *_bResult << endl;
40                 log << "Ports: " << _ports[0] << endl;
41                 rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev, _bResult);
42                 log << "Established connection with skeleton!" << endl;
43         }
44
45         ~RoomSmart_Stub() {
46                 if (rmiCall != NULL) {
47                         delete rmiCall;
48                         rmiCall = NULL;
49                 }
50         }
51         
52         int getRoomID() {
53                 log << "Calling getRoomID() in stub!" << endl;
54                 int methodId = 0;
55                 string retType = "int";
56                 int numParam = 0;
57                 string paramCls[] = {  };
58                 void* paramObj[] = {  };
59                 int retVal = 0;
60                 void* retObj = &retVal;
61                 log << "About to remote call!" << endl;
62                 rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
63                 log << "Remote call performed!" << endl;
64                 return retVal;
65         }
66
67 };
68 #endif