[dss-commits] digitalSTROM Server branch, master, updated. 356f356bc70e84f152bd8b8126a51acae9a1727a

git version control dss-commits at forum.digitalstrom.org
Tue Jan 5 16:04:06 CET 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "digitalSTROM Server".

The branch, master has been updated
       via  356f356bc70e84f152bd8b8126a51acae9a1727a (commit)
      from  11491310eedca6baabf234c726e3b65079887938 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 356f356bc70e84f152bd8b8126a51acae9a1727a
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Tue Jan 5 16:00:24 2010 +0100

    Include parameter for meter in set::getByBusID
    
    Closes #245

-----------------------------------------------------------------------

Changes:
diff --git a/core/model/apartment.cpp b/core/model/apartment.cpp
index 19febf7..de2cf56 100644
--- a/core/model/apartment.cpp
+++ b/core/model/apartment.cpp
@@ -644,7 +644,7 @@ namespace dss {
       DSMeter& mod = getDSMeterByBusID(_dsMeterID);
       try {
         log("OnDeviceCallScene: dsMeter-id '" + intToString(_dsMeterID) + "' for device '" + intToString(_deviceID) + "' scene: " + intToString(_sceneID));
-        DeviceReference devRef = mod.getDevices().getByBusID(_deviceID);
+        DeviceReference devRef = mod.getDevices().getByBusID(_deviceID, _dsMeterID);
         if(SceneHelper::rememberScene(_sceneID & 0x00ff)) {
           devRef.getDevice().setLastCalledScene(_sceneID & 0x00ff);
         }
diff --git a/core/model/set.cpp b/core/model/set.cpp
index 43bf2c2..0dff8bd 100644
--- a/core/model/set.cpp
+++ b/core/model/set.cpp
@@ -209,23 +209,31 @@ namespace dss {
   class ByIDSelector : public IDeviceSelector {
   private:
     const devid_t m_ID;
+    const int m_DSMeterID;
   public:
-    ByIDSelector(const devid_t _id) : m_ID(_id) {}
+    ByIDSelector(const devid_t _id, const int _dsMeterID)
+    : m_ID(_id), m_DSMeterID(_dsMeterID)
+    {}
     virtual ~ByIDSelector() {};
 
     virtual bool selectDevice(const Device& _device) const {
-      return _device.getShortAddress() == m_ID;
+      return (_device.getShortAddress() == m_ID) &&
+             (_device.getDSMeterID() == m_DSMeterID);
     }
   };
 
-  DeviceReference Set::getByBusID(const devid_t _id) const {
-    Set resultSet = getSubset(ByIDSelector(_id));
+  DeviceReference Set::getByBusID(const devid_t _id, const int _dsMeterID) const {
+    Set resultSet = getSubset(ByIDSelector(_id, _dsMeterID));
     if(resultSet.length() == 0) {
       throw ItemNotFoundException(std::string("with busid ") + intToString(_id));
     }
     return resultSet.m_ContainedDevices.front();
   } // getByBusID
 
+  DeviceReference Set::getByBusID(const devid_t _busid, const DSMeter& _meter) const {
+    return getByBusID(_busid, _meter.getBusID());
+  } // getByBusID
+
   class ByDSIDSelector : public IDeviceSelector {
   private:
     const dsid_t m_ID;
diff --git a/core/model/set.h b/core/model/set.h
index ae70a15..65886a9 100644
--- a/core/model/set.h
+++ b/core/model/set.h
@@ -111,7 +111,8 @@ namespace dss {
      */
     DeviceReference getByName(const std::string& _name) const;
     /** Returns the device indicated by \a _busid */
-    DeviceReference getByBusID(const devid_t _busid) const;
+    DeviceReference getByBusID(const devid_t _busid, const int _dsMeterID) const;
+    DeviceReference getByBusID(const devid_t _busid, const DSMeter& _meter) const;
 
     /** Returns the device indicated by \a _dsid */
     DeviceReference getByDSID(const dsid_t _dsid)  const;
diff --git a/tests/modeltests.cpp b/tests/modeltests.cpp
index 04f817b..0f19452 100644
--- a/tests/modeltests.cpp
+++ b/tests/modeltests.cpp
@@ -56,6 +56,38 @@ BOOST_AUTO_TEST_CASE(testApartmentAllocateDeviceReturnsTheSameDeviceForDSID) {
   BOOST_CHECK_EQUAL(dev1.getDSMeterID(), dev2.getDSMeterID());
 } // testApartmentAllocateDeviceReturnsTheSameDeviceForDSID
 
+BOOST_AUTO_TEST_CASE(testSetGetByBusID) {
+  Apartment apt(NULL, NULL);
+  apt.initialize();
+
+  Device& dev1 = apt.allocateDevice(dsid_t(0,1));
+  dev1.setShortAddress(1);
+  dev1.setName("dev1");
+  dev1.setDSMeterID(1);
+
+  Device& dev2 = apt.allocateDevice(dsid_t(0,2));
+  dev2.setShortAddress(1);
+  dev2.setName("dev2");
+  dev2.setDSMeterID(2);
+
+  DSMeter& mod1 = apt.allocateDSMeter(dsid_t(0,3));
+  mod1.setBusID(1);
+
+  DSMeter& mod2 = apt.allocateDSMeter(dsid_t(0,4));
+  mod2.setBusID(2);
+  BOOST_CHECK_EQUAL(apt.getDevices().getByBusID(1, 1).getName(), dev1.getName());
+  BOOST_CHECK_THROW(apt.getDevices().getByBusID(2, 1), ItemNotFoundException);
+
+  BOOST_CHECK_EQUAL(apt.getDevices().getByBusID(1, mod1).getName(), dev1.getName());
+  BOOST_CHECK_THROW(apt.getDevices().getByBusID(2, mod1), ItemNotFoundException);
+
+  BOOST_CHECK_EQUAL(apt.getDevices().getByBusID(1, 2).getName(), dev2.getName());
+  BOOST_CHECK_THROW(apt.getDevices().getByBusID(2, 2), ItemNotFoundException);
+
+  BOOST_CHECK_EQUAL(apt.getDevices().getByBusID(1, mod2).getName(), dev2.getName());
+  BOOST_CHECK_THROW(apt.getDevices().getByBusID(2, mod2), ItemNotFoundException);
+} // testSetGetByBusID
+
 BOOST_AUTO_TEST_CASE(testApartmentGetDeviceByShortAddress) {
   Apartment apt(NULL, NULL);
   apt.initialize();
@@ -107,15 +139,19 @@ BOOST_AUTO_TEST_CASE(testZoneMoving) {
 
   Device& dev1 = apt.allocateDevice(dsid_t(0,1));
   dev1.setShortAddress(1);
+  dev1.setDSMeterID(1);
   DeviceReference devRef1(dev1, &apt);
   Device& dev2 = apt.allocateDevice(dsid_t(0,2));
   dev2.setShortAddress(2);
+  dev2.setDSMeterID(1);
   DeviceReference devRef2(dev2, &apt);
   Device& dev3 = apt.allocateDevice(dsid_t(0,3));
   dev3.setShortAddress(3);
+  dev3.setDSMeterID(1);
   DeviceReference devRef3(dev3, &apt);
   Device& dev4 = apt.allocateDevice(dsid_t(0,4));
   dev4.setShortAddress(4);
+  dev4.setDSMeterID(1);
   DeviceReference devRef4(dev4, &apt);
 
   Zone& zone1 = apt.allocateZone(1);
@@ -126,10 +162,10 @@ BOOST_AUTO_TEST_CASE(testZoneMoving) {
 
   Set allDevices = apt.getDevices();
 
-  BOOST_CHECK_EQUAL(dev1, allDevices.getByBusID(1).getDevice());
-  BOOST_CHECK_EQUAL(dev2, allDevices.getByBusID(2).getDevice());
-  BOOST_CHECK_EQUAL(dev3, allDevices.getByBusID(3).getDevice());
-  BOOST_CHECK_EQUAL(dev4, allDevices.getByBusID(4).getDevice());
+  BOOST_CHECK_EQUAL(dev1, allDevices.getByBusID(1, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev2, allDevices.getByBusID(2, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev3, allDevices.getByBusID(3, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev4, allDevices.getByBusID(4, 1).getDevice());
 
   BOOST_CHECK_EQUAL(4, zone1.getDevices().length());
 
@@ -142,12 +178,12 @@ BOOST_AUTO_TEST_CASE(testZoneMoving) {
 
   // check that the devices are moved correctly in the zones datamodel
   Set zone1Devices = zone1.getDevices();
-  BOOST_CHECK_EQUAL(dev1, zone1Devices.getByBusID(1).getDevice());
-  BOOST_CHECK_EQUAL(dev3, zone1Devices.getByBusID(3).getDevice());
+  BOOST_CHECK_EQUAL(dev1, zone1Devices.getByBusID(1, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev3, zone1Devices.getByBusID(3, 1).getDevice());
 
   Set zone2Devices = zone2.getDevices();
-  BOOST_CHECK_EQUAL(dev2, zone2Devices.getByBusID(2).getDevice());
-  BOOST_CHECK_EQUAL(dev4, zone2Devices.getByBusID(4).getDevice());
+  BOOST_CHECK_EQUAL(dev2, zone2Devices.getByBusID(2, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev4, zone2Devices.getByBusID(4, 1).getDevice());
 
   // check the datamodel of the devices
   BOOST_CHECK_EQUAL(1, dev1.getZoneID());
@@ -159,12 +195,12 @@ BOOST_AUTO_TEST_CASE(testZoneMoving) {
   // check that the groups are set up correctly
   // (this should be the case if all test above passed)
   Set zone1Group0Devices = zone1.getGroup(GroupIDBroadcast)->getDevices();
-  BOOST_CHECK_EQUAL(dev1, zone1Group0Devices.getByBusID(1).getDevice());
-  BOOST_CHECK_EQUAL(dev3, zone1Group0Devices.getByBusID(3).getDevice());
+  BOOST_CHECK_EQUAL(dev1, zone1Group0Devices.getByBusID(1, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev3, zone1Group0Devices.getByBusID(3, 1).getDevice());
 
   Set zone2Group0Devices = zone2.getGroup(GroupIDBroadcast)->getDevices();
-  BOOST_CHECK_EQUAL(dev2, zone2Group0Devices.getByBusID(2).getDevice());
-  BOOST_CHECK_EQUAL(dev4, zone2Group0Devices.getByBusID(4).getDevice());
+  BOOST_CHECK_EQUAL(dev2, zone2Group0Devices.getByBusID(2, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev4, zone2Group0Devices.getByBusID(4, 1).getDevice());
 } // testZoneMoving
 
 BOOST_AUTO_TEST_CASE(testSet) {
@@ -173,19 +209,23 @@ BOOST_AUTO_TEST_CASE(testSet) {
 
   Device& dev1 = apt.allocateDevice(dsid_t(0,1));
   dev1.setShortAddress(1);
+  dev1.setDSMeterID(1);
   Device& dev2 = apt.allocateDevice(dsid_t(0,2));
   dev2.setShortAddress(2);
+  dev2.setDSMeterID(1);
   Device& dev3 = apt.allocateDevice(dsid_t(0,3));
   dev3.setShortAddress(3);
+  dev3.setDSMeterID(1);
   Device& dev4 = apt.allocateDevice(dsid_t(0,4));
   dev4.setShortAddress(4);
+  dev4.setDSMeterID(1);
 
   Set allDevices = apt.getDevices();
 
-  BOOST_CHECK_EQUAL(dev1, allDevices.getByBusID(1).getDevice());
-  BOOST_CHECK_EQUAL(dev2, allDevices.getByBusID(2).getDevice());
-  BOOST_CHECK_EQUAL(dev3, allDevices.getByBusID(3).getDevice());
-  BOOST_CHECK_EQUAL(dev4, allDevices.getByBusID(4).getDevice());
+  BOOST_CHECK_EQUAL(dev1, allDevices.getByBusID(1, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev2, allDevices.getByBusID(2, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev3, allDevices.getByBusID(3, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev4, allDevices.getByBusID(4, 1).getDevice());
 
   Set setdev1 = Set(dev1);
 
@@ -195,38 +235,30 @@ BOOST_AUTO_TEST_CASE(testSet) {
 
   BOOST_CHECK_EQUAL(false, allMinusDev1.contains(dev1));
 
-  /*
-  try {
-    allMinusDev1.getByBusID(1);
-    BOOST_CHECK(false);
-  } catch(ItemNotFoundException& e) {
-    BOOST_CHECK(true);
-  }*/
-
-  BOOST_CHECK_EQUAL(dev2, allMinusDev1.getByBusID(2).getDevice());
-  BOOST_CHECK_EQUAL(dev3, allMinusDev1.getByBusID(3).getDevice());
-  BOOST_CHECK_EQUAL(dev4, allMinusDev1.getByBusID(4).getDevice());
+  BOOST_CHECK_EQUAL(dev2, allMinusDev1.getByBusID(2, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev3, allMinusDev1.getByBusID(3, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev4, allMinusDev1.getByBusID(4, 1).getDevice());
 
   // check that the other sets are not afected by our operation
   BOOST_CHECK_EQUAL(1, setdev1.length());
-  BOOST_CHECK_EQUAL(dev1, setdev1.getByBusID(1).getDevice());
+  BOOST_CHECK_EQUAL(dev1, setdev1.getByBusID(1, 1).getDevice());
 
   BOOST_CHECK_EQUAL(4, allDevices.length());
-  BOOST_CHECK_EQUAL(dev1, allDevices.getByBusID(1).getDevice());
-  BOOST_CHECK_EQUAL(dev2, allDevices.getByBusID(2).getDevice());
-  BOOST_CHECK_EQUAL(dev3, allDevices.getByBusID(3).getDevice());
-  BOOST_CHECK_EQUAL(dev4, allDevices.getByBusID(4).getDevice());
+  BOOST_CHECK_EQUAL(dev1, allDevices.getByBusID(1, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev2, allDevices.getByBusID(2, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev3, allDevices.getByBusID(3, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev4, allDevices.getByBusID(4, 1).getDevice());
 
   Set allRecombined = allMinusDev1.combine(setdev1);
 
   BOOST_CHECK_EQUAL(4, allRecombined.length());
-  BOOST_CHECK_EQUAL(dev1, allRecombined.getByBusID(1).getDevice());
-  BOOST_CHECK_EQUAL(dev2, allRecombined.getByBusID(2).getDevice());
-  BOOST_CHECK_EQUAL(dev3, allRecombined.getByBusID(3).getDevice());
-  BOOST_CHECK_EQUAL(dev4, allRecombined.getByBusID(4).getDevice());
+  BOOST_CHECK_EQUAL(dev1, allRecombined.getByBusID(1, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev2, allRecombined.getByBusID(2, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev3, allRecombined.getByBusID(3, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev4, allRecombined.getByBusID(4, 1).getDevice());
 
   BOOST_CHECK_EQUAL(1, setdev1.length());
-  BOOST_CHECK_EQUAL(dev1, setdev1.getByBusID(1).getDevice());
+  BOOST_CHECK_EQUAL(dev1, setdev1.getByBusID(1, 1).getDevice());
 
   allRecombined = allRecombined.combine(setdev1);
   BOOST_CHECK_EQUAL(4, allRecombined.length());
@@ -236,17 +268,17 @@ BOOST_AUTO_TEST_CASE(testSet) {
 
   allRecombined = allRecombined.combine(allRecombined);
   BOOST_CHECK_EQUAL(4, allRecombined.length());
-  BOOST_CHECK_EQUAL(dev1, allRecombined.getByBusID(1).getDevice());
-  BOOST_CHECK_EQUAL(dev2, allRecombined.getByBusID(2).getDevice());
-  BOOST_CHECK_EQUAL(dev3, allRecombined.getByBusID(3).getDevice());
-  BOOST_CHECK_EQUAL(dev4, allRecombined.getByBusID(4).getDevice());
+  BOOST_CHECK_EQUAL(dev1, allRecombined.getByBusID(1, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev2, allRecombined.getByBusID(2, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev3, allRecombined.getByBusID(3, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev4, allRecombined.getByBusID(4, 1).getDevice());
 
   allMinusDev1 = allRecombined;
   allMinusDev1.removeDevice(dev1);
   BOOST_CHECK_EQUAL(3, allMinusDev1.length());
-  BOOST_CHECK_EQUAL(dev2, allMinusDev1.getByBusID(2).getDevice());
-  BOOST_CHECK_EQUAL(dev3, allMinusDev1.getByBusID(3).getDevice());
-  BOOST_CHECK_EQUAL(dev4, allMinusDev1.getByBusID(4).getDevice());
+  BOOST_CHECK_EQUAL(dev2, allMinusDev1.getByBusID(2, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev3, allMinusDev1.getByBusID(3, 1).getDevice());
+  BOOST_CHECK_EQUAL(dev4, allMinusDev1.getByBusID(4, 1).getDevice());
 } // testSet
 
 BOOST_AUTO_TEST_CASE(testSetBuilder) {


hooks/post-receive
-- 
digitalSTROM Server


More information about the dss-commits mailing list