[dss-commits] r8866 - dss/trunk/core

dss-commits at forum.digitalstrom.org dss-commits at forum.digitalstrom.org
Tue Oct 27 09:40:39 CET 2009


Author: pstaehlin
Date: 2009-10-27 09:40:39 +0100 (Tue, 27 Oct 2009)
New Revision: 8866

Modified:
   dss/trunk/core/model.cpp
   dss/trunk/core/model.h
   dss/trunk/core/webserver.cpp
Log:
Note the date of the first and last appearance on the device

Closes #72

Modified: dss/trunk/core/model.cpp
===================================================================
--- dss/trunk/core/model.cpp	2009-10-27 08:40:37 UTC (rev 8865)
+++ dss/trunk/core/model.cpp	2009-10-27 08:40:39 UTC (rev 8866)
@@ -65,7 +65,8 @@
     m_pApartment(_pApartment),
     m_LastCalledScene(SceneOff),
     m_Consumption(0),
-    m_pPropertyNode()
+    m_LastDiscovered(DateTime::NullDate),
+    m_FirstSeen(DateTime::NullDate)
   { } // ctor
 
   void Device::publishToPropertyTree() {
@@ -214,6 +215,7 @@
   void Device::setShortAddress(const devid_t _shortAddress) {
     m_ShortAddress = _shortAddress;
     publishToPropertyTree();
+    m_LastDiscovered = DateTime();
   } // setShortAddress
 
   dsid_t Device::getDSID() const {
@@ -1179,11 +1181,18 @@
         } catch(XMLException& e) {
           /* discard node not found exceptions */
         }
-
+        
+        DateTime firstSeen; 
+        std::string firstSeenStr = iNode->getAttributes()["firstSeen"];
+        if(!firstSeenStr.empty()) {
+          firstSeen = DateTime(dateFromISOString(firstSeenStr.c_str()));
+        }
+        
         Device& newDevice = allocateDevice(dsid);
         if(!name.empty()) {
           newDevice.setName(name);
         }
+        newDevice.setFirstSeen(firstSeen);
       }
     }
   } // loadDevices
@@ -1238,7 +1247,8 @@
       AutoPtr<Text> txtNode = _pDocument->createTextNode(_pDevice->getName());
       pNameNode->appendChild(txtNode);
       pDeviceNode->appendChild(pNameNode);
-    }
+    }    
+    pDeviceNode->setAttribute("firstSeen", _pDevice->getFirstSeen());
 
     _parentNode->appendChild(pDeviceNode);
   } // deviceToXML
@@ -1452,6 +1462,7 @@
     }
 
     Device* pResult = new Device(_dsid, this);
+    pResult->setFirstSeen(DateTime());
     m_Devices.push_back(pResult);
     DeviceReference devRef(*pResult, *this);
     getZone(0).addDevice(devRef);

Modified: dss/trunk/core/model.h
===================================================================
--- dss/trunk/core/model.h	2009-10-27 08:40:37 UTC (rev 8865)
+++ dss/trunk/core/model.h	2009-10-27 08:40:39 UTC (rev 8866)
@@ -220,10 +220,11 @@
     int m_FunctionID;
     int m_LastCalledScene;
     unsigned long m_Consumption;
+    DateTime m_LastDiscovered;
+    DateTime m_FirstSeen;
 
     PropertyNodePtr m_pPropertyNode;
     PropertyNodePtr m_pAliasNode;
-
   protected:
     /** Publishes the device to the property tree.
      * @see DSS::getPropertySystem */
@@ -329,6 +330,10 @@
     void setZoneID(const int _value);
     /** Returns the apartment the device resides in. */
     Apartment& getApartment() const;
+    
+    const DateTime& getLastDiscovered() const { return m_LastDiscovered; }
+    const DateTime& getFirstSeen() const { return m_FirstSeen; }
+    void setFirstSeen(const DateTime& _value) { m_FirstSeen = _value; }
 
     virtual unsigned long getPowerConsumption();
 

Modified: dss/trunk/core/webserver.cpp
===================================================================
--- dss/trunk/core/webserver.cpp	2009-10-27 08:40:37 UTC (rev 8865)
+++ dss/trunk/core/webserver.cpp	2009-10-27 08:40:39 UTC (rev 8866)
@@ -525,6 +525,8 @@
             << ", \"circuitID\":" << ToJSONValue(_device.getDevice().getModulatorID())
             << ", \"busID\":"  << ToJSONValue(_device.getDevice().getShortAddress())
             << ", \"isPresent\":"  << ToJSONValue(_device.getDevice().isPresent())
+            << ", \"lastDiscovered\":"  << ToJSONValue(int(_device.getDevice().getLastDiscovered().secondsSinceEpoch()))
+            << ", \"firstSeen\":"  << ToJSONValue(int(_device.getDevice().getFirstSeen().secondsSinceEpoch()))
             << ", \"on\": " << ToJSONValue(_device.isOn()) << " }";
     return sstream.str();
   } // toJSONValue(DeviceReference)



More information about the dss-commits mailing list