Browse Source

[2100] updated the return type of findZone().

It now simply returns ZoneData as the data associated with the code;
the corresponding client implementation will create a zone finder from it.
also updated some doc.
JINMEI Tatuya 12 years ago
parent
commit
450fef21a6

+ 1 - 0
src/lib/datasrc/memory/Makefile.am

@@ -12,4 +12,5 @@ noinst_LTLIBRARIES = libdatasrc_memory.la
 
 libdatasrc_memory_la_SOURCES = rdata_encoder.h rdata_encoder.cc
 libdatasrc_memory_la_SOURCES += domaintree.h
+libdatasrc_memory_la_SOURCES += zone_data.h
 libdatasrc_memory_la_SOURCES += zone_table.h zone_table.cc

+ 13 - 11
src/lib/datasrc/memory/tests/zone_table_unittest.cc

@@ -119,32 +119,34 @@ TEST_F(ZoneTableTest, DISABLED_removeZone) {
     EXPECT_EQ(result::NOTFOUND, zone_table->removeZone(Name("example.net")));
 }
 
-TEST_F(ZoneTableTest, DISABLED_findZone) {
-    EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zname1).code);
+TEST_F(ZoneTableTest, findZone) {
+    const ZoneTable::AddResult add_result1 =
+        zone_table->addZone(mem_sgmt_, zname1);
+    EXPECT_EQ(result::SUCCESS, add_result1.code);
     EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zname2).code);
     EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_, zname3).code);
 
-    EXPECT_EQ(result::SUCCESS, zone_table->findZone(Name("example.com")).code);
-    EXPECT_EQ(Name("example.com"),
-              zone_table->findZone(Name("example.com")).zone->getOrigin());
+    const ZoneTable::FindResult find_result1 =
+        zone_table->findZone(Name("example.com"));
+    EXPECT_EQ(result::SUCCESS, find_result1.code);
+    EXPECT_EQ(add_result1.zone_data, find_result1.zone_data);
 
     EXPECT_EQ(result::NOTFOUND,
               zone_table->findZone(Name("example.org")).code);
-    EXPECT_EQ(ConstZoneFinderPtr(),
-              zone_table->findZone(Name("example.org")).zone);
+    EXPECT_EQ(NULL, zone_table->findZone(Name("example.org")).zone_data);
 
     // there's no exact match.  the result should be the longest match,
     // and the code should be PARTIALMATCH.
     EXPECT_EQ(result::PARTIALMATCH,
               zone_table->findZone(Name("www.example.com")).code);
-    EXPECT_EQ(Name("example.com"),
-              zone_table->findZone(Name("www.example.com")).zone->getOrigin());
+    EXPECT_EQ(add_result1.zone_data,
+              zone_table->findZone(Name("www.example.com")).zone_data);
 
     // make sure the partial match is indeed the longest match by adding
     // a zone with a shorter origin and query again.
     EXPECT_EQ(result::SUCCESS, zone_table->addZone(mem_sgmt_,
                                                    Name("com")).code);
-    EXPECT_EQ(Name("example.com"),
-              zone_table->findZone(Name("www.example.com")).zone->getOrigin());
+    EXPECT_EQ(add_result1.zone_data,
+              zone_table->findZone(Name("www.example.com")).zone_data);
 }
 }

+ 5 - 12
src/lib/datasrc/memory/zone_data.h

@@ -15,32 +15,25 @@
 #ifndef DATASRC_MEMORY_ZONE_DATA_H
 #define DATASRC_MEMORY_ZONE_DATA_H 1
 
-#include <dns/name.h>
-#include <dns/rrclass.h>
+#include <util/memory_segment.h>
 
 namespace isc {
 namespace datasrc {
 namespace memory {
 class ZoneData {
 private:
-    ZoneData(const dns::Name& zone_name) :
-        zone_name_(zone_name)
-    {}
+    ZoneData() {}
+    ~ZoneData() {}
 public:
-    static ZoneData* create(util::MemorySegment& mem_sgmt,
-                            const dns::Name& zone_name)
-    {
+    static ZoneData* create(util::MemorySegment& mem_sgmt) {
         void* p = mem_sgmt.allocate(sizeof(ZoneData));
-        ZoneData* zone_data = new(p) ZoneData(zone_name);
+        ZoneData* zone_data = new(p) ZoneData();
         return (zone_data);
     }
     static void destroy(util::MemorySegment& mem_sgmt, ZoneData* zone_data) {
         zone_data->~ZoneData();
         mem_sgmt.deallocate(zone_data, sizeof(ZoneData));
     }
-
-private:
-    const dns::Name zone_name_;
 };
 } // namespace memory
 } // namespace datasrc

+ 13 - 8
src/lib/datasrc/memory/zone_table.cc

@@ -55,6 +55,13 @@ private:
 };
 }
 
+void
+ZoneTable::ZoneDataDeleter::operator()(util::MemorySegment& mem_sgmt,
+                                       ZoneData* zone_data) const
+{
+    ZoneData::destroy(mem_sgmt, zone_data);
+}
+
 ZoneTable*
 ZoneTable::create(util::MemorySegment& mem_sgmt) {
     Holder<ZoneTableTree> holder(mem_sgmt, ZoneTableTree::create(mem_sgmt));
@@ -78,7 +85,7 @@ ZoneTable::addZone(util::MemorySegment& mem_sgmt, const Name& zone_name) {
     // provide as strong guarantee as possible.  In practice, we generally
     // expect the caller tries to add a zone only when it's a new one, so
     // this should be a minor concern.
-    Holder<ZoneData> holder(mem_sgmt, ZoneData::create(mem_sgmt, zone_name));
+    Holder<ZoneData> holder(mem_sgmt, ZoneData::create(mem_sgmt));
 
     // Get the node where we put the zone
     ZoneTableNode* node(NULL);
@@ -124,22 +131,20 @@ ZoneTable::findZone(const Name& name) const {
     case ZoneTableTree::PARTIALMATCH:
         my_result = result::PARTIALMATCH;
         break;
-        // We have no data there, so translate the pointer to NULL as well
     case ZoneTableTree::NOTFOUND:
-        return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
-        // Can Not Happen
+        // We have no data there, so translate the pointer to NULL as well
+        return (FindResult(result::NOTFOUND, NULL));
     default:
+        // Can Not Happen
         assert(0);
         // Because of warning
-        return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
+        return (FindResult(result::NOTFOUND, NULL));
     }
 
     // Can Not Happen (remember, NOTFOUND is handled)
     assert(node != NULL);
 
-    // Temporarily return an easy fake value
-    return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
-    //return (FindResult(my_result, node->getData()));
+    return (FindResult(my_result, node->getData()));
 }
 
 } // end of namespace memory

+ 17 - 27
src/lib/datasrc/memory/zone_table.h

@@ -17,13 +17,8 @@
 
 #include <util/memory_segment.h>
 
-#include <dns/rrset.h>
-
-#include <datasrc/zone.h>
+#include <datasrc/result.h>
 #include <datasrc/memory/domaintree.h>
-#include <datasrc/memory/zone_table.h>
-
-#include <boost/shared_ptr.hpp>
 
 namespace isc {
 namespace dns {
@@ -33,27 +28,20 @@ class RRClass;
 
 namespace datasrc {
 namespace memory {
+// forward declaration: in this header it's mostly an opaque type.
 class ZoneData;
 
 /// \brief A set of authoritative zones.
 ///
-/// \c ZoneTable class is primarily intended to be used as a backend for the
-/// \c MemoryDataSrc class, but is exposed as a separate class in case some
-/// application wants to use it directly (e.g. for a customized data source
-/// implementation).
-///
-/// For more descriptions about its struct and interfaces, please refer to the
-/// corresponding struct and interfaces of \c MemoryDataSrc.
+/// This class is intended to be used as a backend for the \c MemoryDataSrc
+/// class, and is not intended to be used for other general purposes.
 class ZoneTable {
 private:
     // The deleter for the zone data stored in the table.
     struct ZoneDataDeleter {
         ZoneDataDeleter() {}
         void operator()(util::MemorySegment& mem_sgmt,
-                        ZoneData* zone_data) const
-        {
-            mem_sgmt.deallocate(zone_data, sizeof(ZoneData));
-        }
+                        ZoneData* zone_data) const;
     };
 
     // Type aliases to make it shorter
@@ -69,12 +57,14 @@ public:
         ZoneData* const zone_data;
     };
     struct FindResult {
-        FindResult(result::Result param_code, const ZoneFinderPtr param_zone) :
-            code(param_code), zone(param_zone)
+        FindResult(result::Result param_code,
+                   const ZoneData* param_zone_data) :
+            code(param_code), zone_data(param_zone_data)
         {}
         const result::Result code;
-        const ZoneFinderPtr zone;
+        const ZoneData* const zone_data;
     };
+
     ///
     /// \name Constructors and Destructor.
     ///
@@ -134,9 +124,9 @@ public:
     AddResult addZone(util::MemorySegment& mem_sgmt,
                       const dns::Name& zone_name);
 
-    /// Remove a \c Zone of the given origin name from the \c ZoneTable.
+    /// Remove a zone of the given origin name from the \c ZoneTable.
     ///
-    /// This method never throws an exception.
+    /// This method should never throw an exception.
     ///
     /// \param origin The origin name of the zone to be removed.
     /// \return \c result::SUCCESS If the zone is successfully
@@ -145,9 +135,9 @@ public:
     /// store the zone that matches \c origin.
     result::Result removeZone(const isc::dns::Name& origin);
 
-    /// Find a \c Zone that best matches the given name in the \c ZoneTable.
+    /// Find a zone that best matches the given name in the \c ZoneTable.
     ///
-    /// It searches the internal storage for a \c Zone that gives the
+    /// It searches the internal storage for a zone that gives the
     /// longest match against \c name, and returns the result in the
     /// form of a \c FindResult object as follows:
     /// - \c code: The result code of the operation.
@@ -156,10 +146,10 @@ public:
     ///   - \c result::PARTIALMATCH: A zone whose origin is a
     ///    super domain of \c name is found (but there is no exact match)
     ///   - \c result::NOTFOUND: For all other cases.
-    /// - \c zone: A "Boost" shared pointer to the found \c Zone object if one
-    ///  is found; otherwise \c NULL.
+    /// - \c zone_data: corresponding zone data of the found zone; NULL if
+    ///   no matching zone is found.
     ///
-    /// This method never throws an exception.
+    /// \throw none
     ///
     /// \param name A domain name for which the search is performed.
     /// \return A \c FindResult object enclosing the search result (see above).