#include <thread>
#include "Lifxtest.hpp"
-#include "Iterator.hpp"
-
-Lifxtest::Lifxtest() {
+#include "LifxLightBulb.cpp"
+#include "LabRoom.cpp"
+// External create, destroy, and init functions
+extern "C" void* createLifxtest(void** params) {
+ // Arguments: IoTSet<void*>* lifx_light_bulb, IoTSet<void*>* lab_room, IoTRelation<void*,void*> roomLightRelation
+ return new Lifxtest((IoTSet<void*>*) params[0], (IoTSet<void*>*) params[1], (IoTRelation<void*,void*>*) params[2]);
}
-Lifxtest::Lifxtest(IoTSet<LightBulbTest*> _lifx_light_bulb) {
- lifx_light_bulb = _lifx_light_bulb;
+extern "C" void destroyLifxtest(void* t) {
+ Lifxtest* lt = (Lifxtest*) t;
+ delete lt;
}
-Lifxtest::~Lifxtest() {
+extern "C" void initLifxtest(void* t) {
+ Lifxtest* lt = (Lifxtest*) t;
+ lt->init();
}
-void Lifxtest::init() {
-
- unordered_set<LightBulbTest*>* bulbSet = lifx_light_bulb.values();
- for(LightBulbTest* lifx : *bulbSet) {
+// Empty constructor (for testing)
+Lifxtest::Lifxtest() {
+}
- lifx->init();
- this_thread::sleep_for (chrono::milliseconds(1000));
- for (int i = 0; i < 5; i++) {
- lifx->turnOff();
- cout << "Turning off!" << endl;
- this_thread::sleep_for (chrono::milliseconds(1000));
- lifx->turnOn();
- cout << "Turning on!" << endl;
- this_thread::sleep_for (chrono::milliseconds(1000));
- }
+// Constructor with 2 IoTSet and 1 IoTRelation objects
+Lifxtest::Lifxtest(IoTSet<void*>* _lifx_light_bulb, IoTSet<void*>* _lab_room, IoTRelation<void*,void*>* _roomLightRelation) {
- for (int i = 2500; i < 9000; i += 100) {
- cout << "Adjusting Temp: ";
- lifx->setTemperature(i);
- this_thread::sleep_for (chrono::milliseconds(100));
- }
+ log.open("/home/iotuser/iot2/bin/iotruntime/log/Lifxtest_object_cpp.log");
+ lifx_light_bulb = _lifx_light_bulb;
+ lab_room = _lab_room;
+ roomLightRelation = _roomLightRelation;
+ log << "lifx_light_bulb initialized!" << endl;
+}
- for (int i = 9000; i > 2500; i -= 100) {
- cout << "Adjusting Temp: ";
- lifx->setTemperature(i);
- this_thread::sleep_for (chrono::milliseconds(100));
- }
+Lifxtest::~Lifxtest() {
+}
- for (int i = 100; i > 0; i -= 10) {
- cout << "Adjusting Brightness: ";
- lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
- this_thread::sleep_for (chrono::milliseconds(500));
- }
+void Lifxtest::init() {
- for (int i = 0; i < 100; i += 10) {
- cout << "Adjusting Brightness: " << endl;
- lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
- this_thread::sleep_for (chrono::milliseconds(500));
+ unordered_set<void*>* bulbSet = lifx_light_bulb->values();
+ unordered_set<void*>* roomSet = lab_room->values();
+ unordered_multimap<void*,void*>* roomLightRel = roomLightRelation->values();
+ log << "Size of map: " << roomLightRel->size() << endl;
+
+ for (auto itr = roomSet->begin(); itr != roomSet->end(); ++itr) {
+ RoomSmart* rs = (RoomSmart*) *itr;
+ log << "Now turning on lights in room with ID: " << rs->getRoomID() << endl;
+ auto itrLight = roomLightRel->find(rs);
+
+ if (itrLight == roomLightRel->end())
+ log << "No matching light! - should not get here at all!" << endl;
+ else {
+ log << "Getting LightBulb!" << endl;
+ LightBulbTest* lifx = (LightBulbTest*) itrLight->second;
+ log << "Executing init!" << endl;
+ lifx->init();
+ for (int i = 0; i < 10; i++) {
+ lifx->turnOff();
+ log << "Turning off!" << endl;
+ this_thread::sleep_for (chrono::milliseconds(1000));
+ lifx->turnOn();
+ log << "Turning on!" << i << endl;
+ this_thread::sleep_for (chrono::milliseconds(1000));
+ }
+ /* Note: The bottom part has not yet been heavily tested and
+ this might get the execution stuck at some point.
+ We are suspecting that this is due to the complex interaction
+ of the multiple threads that we have.
+ for (int i = 2500; i < 9000; i += 100) {
+ log << "Adjusting Temp: " << i << endl;
+ lifx->setTemperature(i);
+ this_thread::sleep_for (chrono::milliseconds(100));
+ }
+
+ for (int i = 9000; i > 2500; i -= 100) {
+ log << "Adjusting Temp: " << i << endl;
+ lifx->setTemperature(i);
+ this_thread::sleep_for (chrono::milliseconds(100));
+ }
+
+ double hue = lifx->getHue();
+ double saturation = lifx->getSaturation();
+
+ for (int i = 100; i > 0; i -= 10) {
+ log << "Adjusting Brightness: " << i << endl;
+ lifx->setColor(hue, saturation, i);
+ this_thread::sleep_for (chrono::milliseconds(500));
+ }
+
+ for (int i = 0; i < 100; i += 10) {
+ log << "Adjusting Brightness: " << i << endl;
+ lifx->setColor(hue, saturation, i);
+ this_thread::sleep_for (chrono::milliseconds(500));
+ }*/
+ //lifx->turnOff();
}
+ log << "End of one LightBulb!" << endl << endl;
}
+
+ log << "End of iteration.. closing!" << endl;
+ log.close();
+ //while(true) { } // Testing infinite loop - will need to do "pkill IoTSlave"
}
-
-
-int main(int argc, char *argv[]) {
-
- return 0;
-}
-
-