[svn] commit: r3512 - in /branches/trac408/src/lib/nsas: tests/zone_entry_unittest.cc zone_entry.h

BIND 10 source code commits bind10-changes at lists.isc.org
Sat Nov 13 15:32:19 UTC 2010


Author: vorner
Date: Sat Nov 13 15:32:18 2010
New Revision: 3512

Log:
Add nameserver manipulation to zone entry

Modified:
    branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc
    branches/trac408/src/lib/nsas/zone_entry.h

Modified: branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc
==============================================================================
--- branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc (original)
+++ branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc Sat Nov 13 15:32:18 2010
@@ -21,6 +21,7 @@
 
 #include "../asiolink.h"
 #include "../zone_entry.h"
+#include "../nameserver_entry.h"
 #include "../address_request_callback.h"
 
 #include "nsas_test.h"
@@ -77,5 +78,22 @@
     EXPECT_FALSE(zone.hasCallbacks());
 }
 
+TEST_F(ZoneEntryTest, Nameserver_iterators) {
+    ZoneEntry zone(EXAMPLE_CO_UK, RRClass::IN().getCode());
+    shared_ptr<NameserverEntry> nse(new NameserverEntry(EXAMPLE_CO_UK,
+        RRClass::IN().getCode()));
+    // The iterator can't be printed, so we can't use EQ
+    const ZoneEntry& zone_const(zone);
+    EXPECT_TRUE(zone.begin() == zone.end());
+    EXPECT_TRUE(zone_const.begin() == zone_const.end());
+    zone.nameserver_add(nse);
+    EXPECT_FALSE(zone.begin() == zone.end());
+    EXPECT_FALSE(zone_const.begin() == zone_const.end());
+    EXPECT_TRUE(*zone.begin() == nse);
+    EXPECT_TRUE(*zone_const.begin() == nse);
+    EXPECT_TRUE(zone.begin() + 1 == zone.end());
+    EXPECT_TRUE(zone_const.begin() + 1 == zone_const.end());
+}
+
 }   // namespace nsas
 }   // namespace isc

Modified: branches/trac408/src/lib/nsas/zone_entry.h
==============================================================================
--- branches/trac408/src/lib/nsas/zone_entry.h (original)
+++ branches/trac408/src/lib/nsas/zone_entry.h Sat Nov 13 15:32:18 2010
@@ -89,11 +89,38 @@
     /// \short Remove a callback from queue and return it
     boost::shared_ptr<AddressRequestCallback> popCallback();
 
+    /// \short Nameserver entry pointer
+    typedef boost::shared_ptr<NameserverEntry> NameserverPtr;
+    /// \short Vector of nameservers
+    typedef std::vector<NameserverPtr> NameserverVector;
+    /// \short Iterators to the nameservers
+    typedef NameserverVector::iterator iterator;
+    typedef NameserverVector::const_iterator const_iterator;
+
+    /**
+     * \short Add a nameserver pointer to this zone.
+     *
+     * This does not lock, as it should be called while it is being created.
+     * No new nameservers should be added later (it should timeout first and
+     * be rebuild). Calling this after addition to the NameserverAddressStore
+     * is undefined (it is not thread safe).
+     */
+    void nameserver_add(NameserverPtr ns) { nameservers_.push_back(ns); }
+    /**
+     * \short Iterators for the nameservers.
+     *
+     * They do not lock, as the nameservers should be read only during
+     * the life of the zone.
+     */
+    iterator begin() { return (nameservers_.begin()); }
+    iterator end() { return (nameservers_.end()); }
+    const_iterator begin() const { return (nameservers_.begin()); }
+    const_iterator end() const { return (nameservers_.end()); }
 private:
     mutable boost::mutex    mutex_;     ///< Mutex protecting this zone entry
     std::string     name_;      ///< Canonical zone name
     uint16_t        classCode_; ///< Class code
-    std::vector<boost::shared_ptr<NameserverEntry> > nameservers_; ///< Nameservers
+    NameserverVector nameservers_; ///< Nameservers
     time_t          expiry_;    ///< Expiry time of this entry
     std::list<boost::shared_ptr<AddressRequestCallback> > callbacks_;
 };




More information about the bind10-changes mailing list