Cleaning up the Makefile for compiler related commands; cleaning up C++ stubs and...
[iot2.git] / benchmarks / Cpp / Lifxtest / RoomSmart_Stub.cpp
index 7650e52aaf8e6cd1c60c5a9b2e1cfd47e38992e2..0e1a498f0d146cde5efdb3e25d73f9d8c9bc4e23 100644 (file)
@@ -1,17 +1,74 @@
 #include <iostream>
-#include <thread>
 #include "RoomSmart_Stub.hpp"
 
-// External create, destroy, and init functions
-extern "C" void* createRoomSmart_Stub(void** params) {
-       // Arguments: int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports
-       return new RoomSmart_Stub(*((int*) params[0]), ((string*) params[1])->c_str(), *((string*) params[2]), *((int*) params[3]), (bool*) params[4], *((vector<int>*) params[5]));
+using namespace std;
+
+RoomSmart_Stub::RoomSmart_Stub(int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult) {
+       // Logging
+       int i=0;
+       string file = "RoomSmart_Stub_cpp" + to_string(i) + ".log";
+       while (ifstream(file.c_str())) {
+               i++;
+               file = "RoomSmart_Stub_cpp" + to_string(i) + ".log";
+       }
+       log.open(file);
+       log << "Send port: " << _portSend << endl;
+       log << "Recv port: " << _portRecv << endl;
+       log << "Skeleton address: " << _skeletonAddress << endl;
+       log << "Rev: " << _rev << endl;
+       log << "bResult: " << *_bResult << endl;
+       rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev, _bResult);
+       log << "Established connection with skeleton!" << endl;
+       rmiComm->registerStub(objectId, 0, &retValueReceived0);
+       IoTRMIUtil::mapStub->insert(make_pair(objectId, this));
 }
 
+RoomSmart_Stub::RoomSmart_Stub(IoTRMIComm* _rmiComm, int _objectId) {
+       rmiComm = _rmiComm;
+       objectId = _objectId;
+       rmiComm->registerStub(objectId, 0, &retValueReceived0);
+}
+
+RoomSmart_Stub::~RoomSmart_Stub() {
+       if (rmiComm != NULL) {
+               delete rmiComm;
+               rmiComm = NULL;
+       }
+}
+
+mutex mtxRoomSmart_StubMethodExec0;
+int RoomSmart_Stub::getRoomID() { 
+       lock_guard<mutex> guard(mtxRoomSmart_StubMethodExec0);
+       int methodId = 0;
+       string retType = "int";
+       int numParam = 0;
+       string paramCls[] = {  };
+       void* paramObj[] = {  };
+       int retVal = 0;
+       void* retObj = &retVal;
+       rmiComm->remoteCall(objectId, methodId, paramCls, paramObj, numParam);
+       // Waiting for return value
+       while (!retValueReceived0);
+       rmiComm->getReturnValue(retType, retObj);
+       retValueReceived0 = false;
+       didGetReturnBytes.exchange(true);
+
+       return retVal;
+}
+
+extern "C" void* createRoomSmart_Stub(void** params) {
+       // Args: int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult
+       return new RoomSmart_Stub(*((int*) params[0]), *((int*) params[1]), ((string*) params[2])->c_str(), *((int*) params[3]), (bool*) params[4]);
+}
 
 extern "C" void destroyRoomSmart_Stub(void* t) {
-       RoomSmart_Stub* rss = (RoomSmart_Stub*) t;
-       delete rss;
+       RoomSmart_Stub* obj = (RoomSmart_Stub*) t;
+       delete obj;
 }
 
+extern "C" void initRoomSmart_Stub(void* t) {
+}
 
+int main() {
+       return 0;
+}