X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=blobdiff_plain;f=benchmarks%2FCpp%2FLifxtest%2FRoomSmart_Stub.cpp;h=0e1a498f0d146cde5efdb3e25d73f9d8c9bc4e23;hp=7650e52aaf8e6cd1c60c5a9b2e1cfd47e38992e2;hb=fed43b1232f674bd9dec130ea1bf624b71cbe26c;hpb=b27c0918dc21c9fb264c71d935ed83c9a69e5c6e;ds=sidebyside diff --git a/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp b/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp index 7650e52..0e1a498 100644 --- a/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp +++ b/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp @@ -1,17 +1,74 @@ #include -#include #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 _ports - return new RoomSmart_Stub(*((int*) params[0]), ((string*) params[1])->c_str(), *((string*) params[2]), *((int*) params[3]), (bool*) params[4], *((vector*) 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 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; +}