From 888644b2f1d6aaddf7cc463c905df09677b4f89e Mon Sep 17 00:00:00 2001 From: rtrimana Date: Thu, 12 Jan 2017 09:27:58 -0800 Subject: [PATCH] Changing a few things to pointer; Testing Lifxtest benchmark without using runtime system --- benchmarks/Cpp/Lifxtest/Lifxtest.cpp | 75 ++++++++++++++++--- benchmarks/Cpp/Lifxtest/Lifxtest.hpp | 7 +- benchmarks/Cpp/Lifxtest/Makefile | 4 +- .../Cpp/LifxLightBulb/LifxLightBulb.cpp | 19 +++-- .../Cpp/LifxLightBulb/LifxLightBulb.hpp | 4 +- 5 files changed, 86 insertions(+), 23 deletions(-) diff --git a/benchmarks/Cpp/Lifxtest/Lifxtest.cpp b/benchmarks/Cpp/Lifxtest/Lifxtest.cpp index 39c2f44..dbdfc82 100644 --- a/benchmarks/Cpp/Lifxtest/Lifxtest.cpp +++ b/benchmarks/Cpp/Lifxtest/Lifxtest.cpp @@ -3,17 +3,23 @@ #include #include "Lifxtest.hpp" +#include "LifxLightBulb.cpp" #include "Iterator.hpp" Lifxtest::Lifxtest() { } -Lifxtest::Lifxtest(IoTSet _lifx_light_bulb) { +/*Lifxtest::Lifxtest(IoTSet _lifx_light_bulb) { lifx_light_bulb = _lifx_light_bulb; -} +}*/ + +Lifxtest::Lifxtest(void** args) { + //lifx_light_bulb = *(IoTSet*) args[0]; + lifx_light_bulb = *(IoTSet*) args[0]; +} Lifxtest::~Lifxtest() { } @@ -21,13 +27,15 @@ Lifxtest::~Lifxtest() { void Lifxtest::init() { - unordered_set* bulbSet = lifx_light_bulb.values(); - for(LightBulbTest* lifx : *bulbSet) { + //unordered_set* bulbSet = lifx_light_bulb.values(); + unordered_set* bulbSet = lifx_light_bulb.values(); + //for(LightBulbTest* lifx : *bulbSet) { + for(LightBulb* lifx : *bulbSet) { lifx->init(); this_thread::sleep_for (chrono::milliseconds(1000)); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 1; i++) { lifx->turnOff(); cout << "Turning off!" << endl; this_thread::sleep_for (chrono::milliseconds(1000)); @@ -36,34 +44,77 @@ void Lifxtest::init() { this_thread::sleep_for (chrono::milliseconds(1000)); } - for (int i = 2500; i < 9000; i += 100) { - cout << "Adjusting Temp: "; +/* for (int i = 2500; i < 9000; i += 100) { + cout << "Adjusting Temp: " << i << endl; lifx->setTemperature(i); this_thread::sleep_for (chrono::milliseconds(100)); } for (int i = 9000; i > 2500; i -= 100) { - cout << "Adjusting Temp: "; + cout << "Adjusting Temp: " << i << endl; lifx->setTemperature(i); this_thread::sleep_for (chrono::milliseconds(100)); } for (int i = 100; i > 0; i -= 10) { - cout << "Adjusting Brightness: "; + cout << "Adjusting Brightness: " << i << endl; lifx->setColor(lifx->getHue(), lifx->getSaturation(), i); this_thread::sleep_for (chrono::milliseconds(500)); } for (int i = 0; i < 100; i += 10) { - cout << "Adjusting Brightness: " << endl; + cout << "Adjusting Brightness: " << i << endl; lifx->setColor(lifx->getHue(), lifx->getSaturation(), i); this_thread::sleep_for (chrono::milliseconds(500)); - } + }*/ } } -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ + // LightBulb #1 + string macAddress1 = "D073D5128E300000"; + string devIPAddress1 = "192.168.2.126"; + IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 12345, 56700, false, false); + unordered_set* myset1 = new unordered_set(); + myset1->insert(devAddress1); + IoTSet* setDevAddress1 = new IoTSet(*myset1); + LifxLightBulb *llb1 = new LifxLightBulb(setDevAddress1, macAddress1); + //cout << "Generated LifxLightBulb object!" << endl; + + // LightBulb #2 + string macAddress2 = "D073D50241DA0000"; + string devIPAddress2 = "192.168.2.232"; + IoTDeviceAddress* devAddress2 = new IoTDeviceAddress(devIPAddress2, 12346, 56700, false, false); + unordered_set* myset2 = new unordered_set(); + myset2->insert(devAddress2); + IoTSet* setDevAddress2 = new IoTSet(*myset2); + LifxLightBulb *llb2 = new LifxLightBulb(setDevAddress2, macAddress2); + + // Set of lightbulbs + unordered_set* setLb = new unordered_set(); + setLb->insert(llb1); + setLb->insert(llb2); + IoTSet* lbSet = new IoTSet(*setLb); + + void* args[1]; + args[0] = (void*) lbSet; + Lifxtest *lt = new Lifxtest(args); + lt->init(); + + //delete llb1; + //delete llb2; + delete devAddress1; + delete devAddress2; + delete myset1; + delete myset2; + delete setDevAddress1; + delete setDevAddress2; + delete setLb; + delete lbSet; + //delete llb1; + //delete llb2; return 0; } diff --git a/benchmarks/Cpp/Lifxtest/Lifxtest.hpp b/benchmarks/Cpp/Lifxtest/Lifxtest.hpp index 41b61aa..0cdc745 100644 --- a/benchmarks/Cpp/Lifxtest/Lifxtest.hpp +++ b/benchmarks/Cpp/Lifxtest/Lifxtest.hpp @@ -3,18 +3,21 @@ #include #include "IoTSet.hpp" +#include "LightBulb.hpp" #include "LightBulbTest.hpp" class Lifxtest { private: // IoTSet - IoTSet lifx_light_bulb; + //IoTSet lifx_light_bulb; + IoTSet lifx_light_bulb; public: Lifxtest(); - Lifxtest(IoTSet _lifx_light_bulb); + //Lifxtest(IoTSet _lifx_light_bulb); + Lifxtest(void** args); ~Lifxtest(); void init(); }; diff --git a/benchmarks/Cpp/Lifxtest/Makefile b/benchmarks/Cpp/Lifxtest/Makefile index 4a98f8a..3dd8e5c 100755 --- a/benchmarks/Cpp/Lifxtest/Makefile +++ b/benchmarks/Cpp/Lifxtest/Makefile @@ -6,7 +6,7 @@ all: lifxtest PHONY += lifxtest lifxtest: - $(G++) ./Lifxtest.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/Lifxtest.o --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/ - cp ./Lifxtest.config $(BIN_DIR)/iotcode/Lifxtest + $(G++) ./Lifxtest.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/Lifxtest.o --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/ -I$(BASE)/benchmarks/drivers/Cpp/LifxLightBulb/ + cp ./Lifxtest.config $(BIN_DIR)/Lifxtest .PHONY: $(PHONY) diff --git a/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.cpp b/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.cpp index 669548f..3f2cea8 100644 --- a/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.cpp +++ b/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.cpp @@ -40,7 +40,7 @@ LifxLightBulb::LifxLightBulb() { } -LifxLightBulb::LifxLightBulb(IoTSet _devAddress, string macAddress) { +LifxLightBulb::LifxLightBulb(IoTSet* _devAddress, string macAddress) { // Initialize macAddress char tmpMacAddress[16]; @@ -70,6 +70,15 @@ LifxLightBulb::~LifxLightBulb() { delete communicationSocket; communicationSocket = NULL; } + for(IoTDeviceAddress* dev : *lb_addresses) { + delete dev; + dev = NULL; + } + if (lb_addresses != NULL) { + + delete lb_addresses; + lb_addresses = NULL; + } } @@ -80,7 +89,7 @@ void LifxLightBulb::init() { if (didAlreadyInit.exchange(true)) return; - unordered_set::const_iterator itr = lb_addresses.begin(); + unordered_set::const_iterator itr = lb_addresses->begin(); IoTDeviceAddress* deviceAddress = *itr; cout << "Address: " << deviceAddress->getAddress() << endl; @@ -1126,7 +1135,7 @@ void LifxLightBulb::handleLightStateMessageReceived(char* payloadData) { // Functions for the main function void onOff(LifxLightBulb *llb) { - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 2; i++) { llb->turnOff(); cout << "Turning off!" << endl; this_thread::sleep_for (chrono::milliseconds(1000)); @@ -1170,7 +1179,7 @@ void adjustBright(LifxLightBulb *llb) { } -int main(int argc, char *argv[]) +/*int main(int argc, char *argv[]) { string macAddress = "D073D5128E300000"; //string macAddress = "D073D50241DA0000"; @@ -1194,4 +1203,4 @@ int main(int argc, char *argv[]) delete llb; return 0; -} +}*/ diff --git a/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.hpp b/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.hpp index 79e8e9e..e422a72 100644 --- a/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.hpp +++ b/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.hpp @@ -86,13 +86,13 @@ class LifxLightBulb : public LightBulb bool stateDidChange = false; // Device address - IoTSet lb_addresses; + IoTSet* lb_addresses; public: // Constructor LifxLightBulb(); - LifxLightBulb(IoTSet _devAddress, string macAddress); + LifxLightBulb(IoTSet* _devAddress, string macAddress); ~LifxLightBulb(); // Initialize the lightbulb void init(); -- 2.34.1