Perfecting IoTSlave for C++; Found one issue with SSH/Java process execution in which...
[iot2.git] / benchmarks / Cpp / Lifxtest / LightBulbTest_Stub.cpp
1 #include <iostream>
2 #include <thread>
3 #include "LightBulbTest_Stub.hpp"
4
5 // External create, destroy, and init functions
6 extern "C" void* createLightBulbTest_Stub(void** params) {
7         // Arguments: int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports
8         return new LightBulbTest_Stub(*((int*) params[0]), ((string*) params[1])->c_str(), *((string*) params[2]), *((int*) params[3]), (bool*) params[4], *((vector<int>*) params[5]));
9 }
10
11
12 extern "C" void destroyLightBulbTest_Stub(void* t) {
13         LightBulbTest_Stub* lbs = (LightBulbTest_Stub*) t;
14         delete lbs;
15 }
16
17
18 extern "C" void initLightBulbTest_Stub(void* t) {
19         LightBulbTest_Stub* lbs = (LightBulbTest_Stub*) t;
20         lbs->init();
21 }
22
23
24 int main(int argc, char *argv[])
25 {
26         int stubPort = 55179;
27         vector<int> ports;
28         ports.push_back(58551);
29         const char* skeletonAddress = "localhost";
30         string callbackAddress = "localhost";
31         int rev = 0;
32         bool result = false;
33         LightBulbTest_Stub *lbs = new LightBulbTest_Stub(stubPort, skeletonAddress, callbackAddress, rev, &result, ports);
34         cout << "Successfully instantiated stub!" << endl;
35         lbs->init();
36         for (int i = 0; i < 100; i++) {
37                 lbs->turnOff();
38                 cout << "Turning off!" << endl;
39                 this_thread::sleep_for (chrono::milliseconds(1000));
40                 lbs->turnOn();
41                 cout << "Turning on!" << endl;
42                 this_thread::sleep_for (chrono::milliseconds(1000));
43         }
44
45         return 0;
46 }