Browse Source

[2206] Define and implement ZoneTableSegment class

Mukund Sivaraman 12 years ago
parent
commit
1ab6aafab6

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

@@ -20,6 +20,8 @@ libdatasrc_memory_la_SOURCES += memory_client.h memory_client.cc
 libdatasrc_memory_la_SOURCES += logger.h logger.cc
 libdatasrc_memory_la_SOURCES += zone_table.h zone_table.cc
 libdatasrc_memory_la_SOURCES += zone_finder.h zone_finder.cc
+libdatasrc_memory_la_SOURCES += zone_table_segment.h zone_table_segment.cc
+libdatasrc_memory_la_SOURCES += zone_table_segment_local.h zone_table_segment_local.cc
 nodist_libdatasrc_memory_la_SOURCES = memory_messages.h memory_messages.cc
 
 EXTRA_DIST  = rdata_serialization_priv.cc

+ 29 - 0
src/lib/datasrc/memory/zone_table_segment.cc

@@ -0,0 +1,29 @@
+// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <datasrc/memory/zone_table_segment.h>
+#include <datasrc/memory/zone_table_segment_local.h>
+
+namespace isc {
+namespace datasrc {
+namespace memory {
+
+ZoneTableSegment*
+ZoneTableSegment::create(const isc::data::Element&) {
+     return (new ZoneTableSegmentLocal);
+}
+
+} // namespace memory
+} // namespace datasrc
+} // namespace isc

+ 78 - 0
src/lib/datasrc/memory/zone_table_segment.h

@@ -0,0 +1,78 @@
+// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef __ZONE_TABLE_SEGMENT_H__
+#define __ZONE_TABLE_SEGMENT_H__
+
+#include <datasrc/memory/zone_table.h>
+#include <cc/data.h>
+#include <util/memory_segment.h>
+
+#include <boost/interprocess/offset_ptr.hpp>
+
+#include <stdlib.h>
+
+namespace isc {
+namespace datasrc {
+namespace memory {
+
+/// \brief Zone Table Header Class
+struct ZoneTableHeader {
+    boost::interprocess::offset_ptr<ZoneTable> table;
+};
+
+/// \brief Zone Table Segment Class
+///
+/// This class specifies an interface for derived implementations which
+/// return a pointer to an object of type ZoneTableHeader, an entry
+/// point of some memory image regardless of the underlying memory
+/// management implementation.
+class ZoneTableSegment {
+public:
+    /// \brief Destructor
+    virtual ~ZoneTableSegment() {}
+
+    /// \brief Return a ZoneTableHeader for the zone table segment.
+    ///
+    /// Returns a ZoneTableHeader that contains a pointer to the zone
+    /// table data in memory.
+    ///
+    /// \return Returns a ZoneTableHeader for this zone table segment.
+    virtual ZoneTableHeader* getHeader() = 0;
+
+    /// \brief Return the MemorySegment for the zone table segment.
+    ///
+    /// Returns the MemorySegment used in this zone table segment.
+    ///
+    /// \return Returns a ZoneTableHeader for this zone table segment.
+    virtual isc::util::MemorySegment& getMemorySegment() = 0;
+
+    /// \brief Create a subclass depending on the memory segment model
+    ///
+    /// This is a factory method to create a derived ZoneTableSegment
+    /// object based on the \c config passed.
+    ///
+    /// FIXME: For now, we always return ZoneTableSegmentLocal.
+    ///
+    /// \param config The configuration based on which a derived object
+    ///               is returned.
+    /// \return Returns a ZoneTableSegment object
+    static ZoneTableSegment* create(const isc::data::Element& config);
+};
+
+} // namespace memory
+} // namespace datasrc
+} // namespace isc
+
+#endif // __ZONE_TABLE_SEGMENT_H__

+ 35 - 0
src/lib/datasrc/memory/zone_table_segment_local.cc

@@ -0,0 +1,35 @@
+// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <datasrc/memory/zone_table_segment_local.h>
+
+using namespace isc::util;
+
+namespace isc {
+namespace datasrc {
+namespace memory {
+
+ZoneTableHeader*
+ZoneTableSegmentLocal::getHeader() {
+     return (&header_);
+}
+
+MemorySegment&
+ZoneTableSegmentLocal::getMemorySegment() {
+     return (mem_sgmt_);
+}
+
+} // namespace memory
+} // namespace datasrc
+} // namespace isc

+ 59 - 0
src/lib/datasrc/memory/zone_table_segment_local.h

@@ -0,0 +1,59 @@
+// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef __ZONE_TABLE_SEGMENT_LOCAL_H__
+#define __ZONE_TABLE_SEGMENT_LOCAL_H__
+
+#include <datasrc/memory/zone_table_segment.h>
+#include <util/memory_segment_local.h>
+
+namespace isc {
+namespace datasrc {
+namespace memory {
+
+/// \brief MemorySegmentLocal based Zone Table Segment class
+///
+/// This class specifies a concrete implementation for a
+/// MemorySegmentLocal based ZoneTableSegment. Please see the
+/// ZoneTableSegment class documentation for usage.
+class ZoneTableSegmentLocal : public ZoneTableSegment {
+public:
+    /// \brief Destructor
+    virtual ~ZoneTableSegmentLocal() {}
+
+    /// \brief Return a ZoneTableHeader for the zone table segment.
+    ///
+    /// Returns a ZoneTableHeader that contains a pointer to the zone
+    /// table data in memory.
+    ///
+    /// \return Returns a ZoneTableHeader for this zone table segment.
+    virtual ZoneTableHeader* getHeader();
+
+    /// \brief Return the MemorySegment for the zone table segment.
+    ///
+    /// Returns the MemorySegment used in this zone table segment.
+    ///
+    /// \return Returns a ZoneTableHeader for this zone table segment.
+    virtual isc::util::MemorySegment& getMemorySegment();
+
+private:
+    ZoneTableHeader header_;
+    isc::util::MemorySegmentLocal mem_sgmt_;
+};
+
+} // namespace memory
+} // namespace datasrc
+} // namespace isc
+
+#endif // __ZONE_TABLE_SEGMENT_LOCAL_H__

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

@@ -32,6 +32,7 @@ run_unittests_SOURCES += ../../tests/faked_nsec3.h ../../tests/faked_nsec3.cc
 run_unittests_SOURCES += memory_segment_test.h
 run_unittests_SOURCES += segment_object_holder_unittest.cc
 run_unittests_SOURCES += memory_client_unittest.cc
+run_unittests_SOURCES += zone_table_segment_unittest.cc
 
 run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 run_unittests_LDFLAGS  = $(AM_LDFLAGS)  $(GTEST_LDFLAGS)

+ 57 - 0
src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc

@@ -0,0 +1,57 @@
+// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <datasrc/memory/zone_table_segment.h>
+#include <gtest/gtest.h>
+
+using namespace isc::datasrc::memory;
+using namespace isc::data;
+using namespace isc::util;
+using namespace std;
+
+namespace {
+
+TEST(ZoneTableSegment, create) {
+    const ElementPtr config = Element::fromJSON("{}");
+    auto_ptr<ZoneTableSegment>
+        seg(ZoneTableSegment::create((*config.get())));
+
+    // By default, a local zone table segment is created.
+    EXPECT_NE(static_cast<void*>(NULL), seg.get());
+}
+
+TEST(ZoneTableSegment, getHeader) {
+    const ElementPtr config = Element::fromJSON("{}");
+    auto_ptr<ZoneTableSegment>
+        seg(ZoneTableSegment::create((*config.get())));
+
+    ZoneTableHeader* header = seg->getHeader();
+    EXPECT_NE(static_cast<void*>(NULL), header);
+
+    // The zone table is unset.
+    ZoneTable* table = header->table.get();
+    EXPECT_EQ(static_cast<void*>(NULL), table);
+}
+
+TEST(ZoneTableSegment, getMemorySegment) {
+    // This doesn't do anything fun except test the API.
+    const ElementPtr config = Element::fromJSON("{}");
+    auto_ptr<ZoneTableSegment>
+        seg(ZoneTableSegment::create((*config.get())));
+
+    MemorySegment& mem_sgmt = seg->getMemorySegment();
+    EXPECT_TRUE(mem_sgmt.allMemoryDeallocated());
+}
+
+} // anonymous namespace