0e1a498f0d146cde5efdb3e25d73f9d8c9bc4e23
[iot2.git] / benchmarks / Cpp / Lifxtest / RoomSmart_Stub.cpp
1 #include <iostream>
2 #include "RoomSmart_Stub.hpp"
3
4 using namespace std;
5
6 RoomSmart_Stub::RoomSmart_Stub(int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult) {
7         // Logging
8         int i=0;
9         string file = "RoomSmart_Stub_cpp" + to_string(i) + ".log";
10         while (ifstream(file.c_str())) {
11                 i++;
12                 file = "RoomSmart_Stub_cpp" + to_string(i) + ".log";
13         }
14         log.open(file);
15         log << "Send port: " << _portSend << endl;
16         log << "Recv port: " << _portRecv << endl;
17         log << "Skeleton address: " << _skeletonAddress << endl;
18         log << "Rev: " << _rev << endl;
19         log << "bResult: " << *_bResult << endl;
20         rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev, _bResult);
21         log << "Established connection with skeleton!" << endl;
22         rmiComm->registerStub(objectId, 0, &retValueReceived0);
23         IoTRMIUtil::mapStub->insert(make_pair(objectId, this));
24 }
25
26 RoomSmart_Stub::RoomSmart_Stub(IoTRMIComm* _rmiComm, int _objectId) {
27         rmiComm = _rmiComm;
28         objectId = _objectId;
29         rmiComm->registerStub(objectId, 0, &retValueReceived0);
30 }
31
32 RoomSmart_Stub::~RoomSmart_Stub() {
33         if (rmiComm != NULL) {
34                 delete rmiComm;
35                 rmiComm = NULL;
36         }
37 }
38
39 mutex mtxRoomSmart_StubMethodExec0;
40 int RoomSmart_Stub::getRoomID() { 
41         lock_guard<mutex> guard(mtxRoomSmart_StubMethodExec0);
42         int methodId = 0;
43         string retType = "int";
44         int numParam = 0;
45         string paramCls[] = {  };
46         void* paramObj[] = {  };
47         int retVal = 0;
48         void* retObj = &retVal;
49         rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
50         // Waiting for return value
51         while (!retValueReceived0);
52         rmiComm->getReturnValue(retType, retObj);
53         retValueReceived0 = false;
54         didGetReturnBytes.exchange(true);
55
56         return retVal;
57 }
58
59 extern "C" void* createRoomSmart_Stub(void** params) {
60         // Args: int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult
61         return new RoomSmart_Stub(*((int*) params[0]), *((int*) params[1]), ((string*) params[2])->c_str(), *((int*) params[3]), (bool*) params[4]);
62 }
63
64 extern "C" void destroyRoomSmart_Stub(void* t) {
65         RoomSmart_Stub* obj = (RoomSmart_Stub*) t;
66         delete obj;
67 }
68
69 extern "C" void initRoomSmart_Stub(void* t) {
70 }
71
72 int main() {
73         return 0;
74 }