Adjusting object ID on the stub side according to the Java stubs.
[iot2.git] / benchmarks / Cpp / Lifxtest / LightBulbTest_Stub.hpp
index 3e20d5bc533c8dfcdea49bd2b56489dc10d2c335..64c501271f1073cd52dab60e5508467cb1964ce6 100644 (file)
@@ -1,7 +1,14 @@
 #ifndef _LIGHTBULBTEST_STUB_HPP__
 #define _LIGHTBULBTEST_STUB_HPP__
 #include <iostream>
-#include <fstream>
+#include <thread>
+#include <mutex>
+#include <vector>
+#include <set>
+#include "IoTRMIComm.hpp"
+#include "IoTRMICommClient.hpp"
+#include "IoTRMICommServer.hpp"
+
 #include "LightBulbTest.hpp"
 
 using namespace std;
@@ -10,155 +17,31 @@ class LightBulbTest_Stub : public LightBulbTest
 {
        private:
 
-       IoTRMICall *rmiCall;
-       string callbackAddress;
-       vector<int> ports;
-
-       const static int objectId = 0;
-
-       ofstream log;
-
-       public:
-
-       LightBulbTest_Stub() { }
-       
-       LightBulbTest_Stub(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {
-               callbackAddress = _callbackAddress;
-               ports = _ports;
-               // Logging
-               log.open("LightBulbTest_Stub_cpp.log");
-               log << "Port: " << _port << endl;
-               log << "Skeleton address: " << _skeletonAddress << endl;
-               log << "Callback address: " << callbackAddress << endl;
-               log << "Rev: " << _rev << endl;
-               log << "bResult: " << *_bResult << endl;
-               log << "Ports: " << _ports[0] << endl;
-               rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev, _bResult);
-               log << "Established connection with skeleton!" << endl;
-               //log.close();
-       }
-
-       ~LightBulbTest_Stub() {
-               if (rmiCall != NULL) {
-                       delete rmiCall;
-                       rmiCall = NULL;
-               }
-       }
+       IoTRMIComm *rmiComm;
+       int objectId = 1;
+       // Synchronization variables
+       bool retValueReceived6 = false;
+       bool retValueReceived3 = false;
+       bool retValueReceived8 = false;
+       bool retValueReceived7 = false;
+       bool retValueReceived9 = false;
        
-       void turnOn() { 
-               int methodId = 2;
-               string retType = "void";
-               int numParam = 0;
-               string paramCls[] = {  };
-               void* paramObj[] = {  };
-               void* retObj = NULL;
-               rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-       }
-
-       double getBrightness() { 
-               int methodId = 6;
-               string retType = "double";
-               int numParam = 0;
-               string paramCls[] = {  };
-               void* paramObj[] = {  };
-               double retVal = 0;
-               void* retObj = &retVal;
-               rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-               return retVal;
-       }
 
-       void turnOff() { 
-               int methodId = 1;
-               string retType = "void";
-               int numParam = 0;
-               string paramCls[] = {  };
-               void* paramObj[] = {  };
-               void* retObj = NULL;
-               rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-       }
-
-       bool getState() { 
-               int methodId = 3;
-               string retType = "boolean";
-               int numParam = 0;
-               string paramCls[] = {  };
-               void* paramObj[] = {  };
-               bool retVal = false;
-               void* retObj = &retVal;
-               rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-               return retVal;
-       }
-
-       void setColor(double _hue, double _saturation, double _brightness) { 
-               int methodId = 4;
-               string retType = "void";
-               int numParam = 3;
-               string paramCls[] = { "double", "double", "double" };
-               void* paramObj[] = { &_hue, &_saturation, &_brightness };
-               void* retObj = NULL;
-               rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-       }
-
-       double getSaturation() { 
-               int methodId = 8;
-               string retType = "double";
-               int numParam = 0;
-               string paramCls[] = {  };
-               void* paramObj[] = {  };
-               double retVal = 0;
-               void* retObj = &retVal;
-               rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-               return retVal;
-       }
-
-       void init() {
-               log << "Calling init() in stub!" << endl;
-               int methodId = 0;
-               string retType = "void";
-               int numParam = 0;
-               string paramCls[] = {  };
-               void* paramObj[] = {  };
-               void* retObj = NULL;
-               log << "About to remote call!" << endl;
-               rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-               log << "Remote call performed!" << endl;
-               log.close();
-       }
-
-       void setTemperature(int _temperature) { 
-               int methodId = 5;
-               string retType = "void";
-               int numParam = 1;
-               string paramCls[] = { "int" };
-               void* paramObj[] = { &_temperature };
-               void* retObj = NULL;
-               rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-       }
-
-       double getHue() { 
-               int methodId = 7;
-               string retType = "double";
-               int numParam = 0;
-               string paramCls[] = {  };
-               void* paramObj[] = {  };
-               double retVal = 0;
-               void* retObj = &retVal;
-               rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-               return retVal;
-       }
-
-       int getTemperature() { 
-               int methodId = 9;
-               string retType = "int";
-               int numParam = 0;
-               string paramCls[] = {  };
-               void* paramObj[] = {  };
-               int retVal = 0;
-               void* retObj = &retVal;
-               rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
-               return retVal;
-       }
+       public:
 
+       LightBulbTest_Stub();
+       LightBulbTest_Stub(int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult);
+       LightBulbTest_Stub(IoTRMIComm* _rmiComm, int _objectId);
+       ~LightBulbTest_Stub();
+       void turnOn();
+       double getBrightness();
+       void turnOff();
+       bool getState();
+       void setColor(double _hue, double _saturation, double _brightness);
+       double getSaturation();
+       void init();
+       void setTemperature(int _temperature);
+       double getHue();
+       int getTemperature();
 };
-
 #endif