Adjusting C++ files to compile with gcc 4.9.3
[iot2.git] / benchmarks / drivers / Cpp / LifxLightBulb / LifxLightBulb.cpp
index 07076db9f9002d0711505b89e8ade62f17c12c21..976ec547216f0d6c8865ce9ccf67e0f9ebafa30c 100644 (file)
@@ -76,7 +76,13 @@ LifxLightBulb::LifxLightBulb(IoTSet<void*>* _devAddress, string macAddress) {
        //cout << "MAC address is set. Value: ";
        IoTRMIUtil::printBytes(bulbMacAddress, 8, false);
        // Logging
-       log.open("LifxLightBulb_cpp.log");
+       int i=0;
+       string file = "LifxLightBulb_cpp" + to_string(i) + ".log";
+       while (ifstream(file.c_str())) {
+               i++;
+               file = "LifxLightBulb_cpp" + to_string(i) + ".log";
+       }
+       log.open(file);
        log << "MAC address is " << macAddress << endl;
 
        // Initialize device address
@@ -113,6 +119,7 @@ void LifxLightBulb::init() {
        if (didAlreadyInit.exchange(true))
                return;
 
+       log << "lb_addresses has: " << lb_addresses->size() << endl;
        unordered_set<void*>::const_iterator itr = lb_addresses->begin();
        IoTDeviceAddress* deviceAddress = (IoTDeviceAddress*) *itr;
        //cout << "Address: " << deviceAddress->getAddress() << endl;
@@ -332,7 +339,6 @@ void LifxLightBulb::receivedPacket(char* packetData) {
        recHeader.setFromBytes(headerBytes);
 
        // load the payload bytes (strip away the header)
-       //char payloadBytes[recHeader.getSize()];
        char* payloadBytes = new char[recHeader.getSize()];
        for (int i = 36; i < recHeader.getSize(); i++) {
                payloadBytes[i - 36] = packetData[i];
@@ -340,6 +346,7 @@ void LifxLightBulb::receivedPacket(char* packetData) {
 
        int type = recHeader.getType();
        //cout << "Received: " << type << endl;
+       log << "Received: " << type << endl;
 
        DeviceStateService* dat = NULL;
        switch (type) {
@@ -396,6 +403,8 @@ void LifxLightBulb::workerFunction(LifxLightBulb* llb) {
        int64_t lastSentGetBulbVersionRequest = 0;      // time last request sent
        char dat[1024];
 
+       llb->log << "Turning off and entering while loop!" << endl;
+
        while (true) {
                // Check if we got the bulb version yet
                // could have requested it but message could have gotten lost (UDP)
@@ -1212,26 +1221,28 @@ void adjustBright(LifxLightBulb *llb) {
 
 /*int main(int argc, char *argv[])
 {
-       string macAddress = "D073D5128E300000";
+       string macAddress1 = "D073D5128E300000";
        //string macAddress = "D073D50241DA0000";
-       string devIPAddress = "192.168.2.126";
-       //string devIPAddress = "192.168.2.232";
-       //IoTDeviceAddress devAddress(devIPAddress, 12345, 56700, false, false);
-       IoTDeviceAddress* devAddress = new IoTDeviceAddress(devIPAddress, 12345, 56700, false, false);
-       unordered_set<IoTDeviceAddress*> myset = { devAddress };
-
-       IoTSet<IoTDeviceAddress*> setDevAddress(myset);
-       LifxLightBulb *llb = new LifxLightBulb(setDevAddress, macAddress);
+       string devIPAddress1 = "192.168.1.126";
+       //string devIPAddress = "192.168.1.232";
+       IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 12345, 56700, false, false);
+       unordered_set<void*>* myset1 = new unordered_set<void*>();
+       myset1->insert(devAddress1);
+
+       IoTSet<void*>* setDevAddress1 = new IoTSet<void*>(myset1);
+       LifxLightBulb *llb1 = new LifxLightBulb(setDevAddress1, macAddress1);
        cout << "Generated LifxLightBulb object!" << endl;
-       llb->init();
-       llb->turnOn();
-       onOff(llb);
-       adjustTemp(llb);
-       adjustBright(llb);
-//     llb->turnOff();
-
-       delete devAddress;
-       delete llb;
+       llb1->init();
+       cout << "Initialized!" << endl;
+       llb1->turnOn();
+       cout << "Turning on!" << endl;
+       onOff(llb1);
+//     adjustTemp(llb1);
+//     adjustBright(llb1);
+       llb1->turnOff();
+
+//     delete devAddress1;
+//     delete llb1;
 
        return 0;
 }*/