Perfecting IoTSlave for C++; Found one issue with SSH/Java process execution in which...
[iot2.git] / benchmarks / Cpp / Lifxtest / LightBulbTest_Stub.cpp
index 4a046bcb030395614888516be7294b1c47b0e496..18fb7806f916c9e07de010bbf5ecd098d038b6f0 100644 (file)
@@ -1,11 +1,46 @@
 #include <iostream>
+#include <thread>
 #include "LightBulbTest_Stub.hpp"
 
-// External creator/destroyer
-/*extern "C" LightBulbTest_Stub* create(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {
-       return new LightBulbTest_Stub(_port, _skeletonAddress, _callbackAddress, _rev, _bResult, _ports);
+// External create, destroy, and init functions
+extern "C" void* createLightBulbTest_Stub(void** params) {
+       // Arguments: int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports
+       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]));
 }
 
-extern "C" void destroy(LightBulbTest_Stub* t) {
-       delete t;
-}*/
+
+extern "C" void destroyLightBulbTest_Stub(void* t) {
+       LightBulbTest_Stub* lbs = (LightBulbTest_Stub*) t;
+       delete lbs;
+}
+
+
+extern "C" void initLightBulbTest_Stub(void* t) {
+       LightBulbTest_Stub* lbs = (LightBulbTest_Stub*) t;
+       lbs->init();
+}
+
+
+int main(int argc, char *argv[])
+{
+       int stubPort = 55179;
+       vector<int> ports;
+       ports.push_back(58551);
+       const char* skeletonAddress = "localhost";
+       string callbackAddress = "localhost";
+       int rev = 0;
+       bool result = false;
+       LightBulbTest_Stub *lbs = new LightBulbTest_Stub(stubPort, skeletonAddress, callbackAddress, rev, &result, ports);
+       cout << "Successfully instantiated stub!" << endl;
+       lbs->init();
+       for (int i = 0; i < 100; 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));
+       }
+
+       return 0;
+}