Cleaning up drivers/Cpp, Cpp/Lifxtest, virtuals, and iotrmi/C++ (revisiting the C...
[iot2.git] / benchmarks / Cpp / Lifxtest / LightBulbTest_Stub.cpp
index b2e1623d936dbaa79a2414bdcbdf2c2708c96490..f760f89345f6eeaa6463ab939f2503f8c400f227 100644 (file)
@@ -3,8 +3,25 @@
 
 using namespace std;
 
+//LightBulbTest_Stub::LightBulbTest_Stub(int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult) {
 LightBulbTest_Stub::LightBulbTest_Stub(int _portSend, int _portRecv, const char* _skeletonAddress, int _rev, bool* _bResult) {
+
+        int i=0;
+        string file = "LightBulbTest_cpp" + to_string(i) + ".log";
+        while (ifstream(file.c_str())) {
+                i++;
+                file = "LightBulbTest_cpp" + to_string(i) + ".log";
+        }
+        log.open(file);
+       log << "Constructing LightBulbTest_Stub!" << endl;
+       log << "Port send: " << _portSend << endl;
+       log << "Port recv: " << _portRecv << endl;
+       log << "Skeleton addr: " << _skeletonAddress << endl;
+       log << "Rev: " << _rev << endl;
+       log << "Result: " << _bResult << endl;
+
        rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev, _bResult);
+       log << "Reached 1!" << endl;
        rmiComm->registerStub(objectId, 6, &retValueReceived6);
        rmiComm->registerStub(objectId, 3, &retValueReceived3);
        rmiComm->registerStub(objectId, 8, &retValueReceived8);
@@ -198,6 +215,43 @@ extern "C" void destroyLightBulbTest_Stub(void* t) {
 extern "C" void initLightBulbTest_Stub(void* t) {
 }
 
-int main() {
+/*int main() {
+       return 0;
+}*/
+
+int main()
+{
+
+       int send_port = 5010;
+       int recv_port = 5011;
+       //const char* skeletonAddress = "127.0.0.1";
+       const char* skeletonAddress = "localhost";
+       int rev = 0;
+       bool result = false;
+
+       LightBulbTest_Stub *lbs = new LightBulbTest_Stub(send_port, recv_port, skeletonAddress, rev, &result);
+       cout << "Successfully instantiated stub!" << endl;
+       lbs->init();
+       lbs->turnOn();
+       this_thread::sleep_for (chrono::milliseconds(1000));
+       lbs->turnOff();
+       for (int i = 0; i < 2; i++) {
+               lbs->turnOff();
+               cout << "Turning off!" << endl;
+               this_thread::sleep_for (chrono::milliseconds(1000));
+               lbs->turnOn();
+               cout << "Turning on!" << endl;
+               this_thread::sleep_for (chrono::milliseconds(1000));
+               double hue = lbs->getHue();
+               double saturation = lbs->getSaturation();
+               cout << "Hue: " << hue << endl;
+               cout << "Saturation: " << saturation << endl;
+               this_thread::sleep_for (chrono::milliseconds(1000));
+       }
+       //lbs->turnOff();
+       cout << "Done controlling! Exit now!" << endl;
+       
+       delete lbs;
+
        return 0;
 }