zone_table_segment.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef ZONE_TABLE_SEGMENT_H
  15. #define ZONE_TABLE_SEGMENT_H
  16. #include <exceptions/exceptions.h>
  17. #include <dns/rrclass.h>
  18. #include <datasrc/memory/zone_table.h>
  19. #include <datasrc/memory/load_action.h>
  20. #include <cc/data.h>
  21. #include <util/memory_segment.h>
  22. #include <boost/interprocess/offset_ptr.hpp>
  23. #include <cstdlib>
  24. #include <string>
  25. namespace isc {
  26. // Some forward declarations
  27. namespace dns {
  28. class Name;
  29. class RRClass;
  30. }
  31. namespace datasrc {
  32. namespace memory {
  33. class ZoneWriter;
  34. /// \brief Exception thrown when unknown or unsupported type of zone table
  35. /// segment is specified.
  36. class UnknownSegmentType : public Exception {
  37. public:
  38. UnknownSegmentType(const char* file, size_t line, const char* what) :
  39. Exception(file, line, what)
  40. {}
  41. };
  42. /// \brief Memory-management independent entry point that contains a
  43. /// pointer to a zone table in memory.
  44. ///
  45. /// An instance of this type lives inside a ZoneTableSegment
  46. /// implementation. It contains an offset pointer to the zone table (a
  47. /// map from domain names to zone locators) in memory.
  48. struct ZoneTableHeader {
  49. public:
  50. ZoneTableHeader(ZoneTable* zone_table) :
  51. table_(zone_table)
  52. {}
  53. /// \brief Returns a pointer to the underlying zone table.
  54. ZoneTable* getTable() {
  55. return (table_.get());
  56. }
  57. /// \brief const version of \c getTable().
  58. const ZoneTable* getTable() const {
  59. return (table_.get());
  60. }
  61. private:
  62. boost::interprocess::offset_ptr<ZoneTable> table_;
  63. };
  64. /// \brief Manages a ZoneTableHeader, an entry point into a table of
  65. /// zones
  66. ///
  67. /// This class specifies an interface for derived implementations which
  68. /// return a pointer to an object of type ZoneTableHeader, an entry
  69. /// point into a table of zones regardless of the underlying memory
  70. /// management implementation. Derived classes would implement the
  71. /// interface for specific memory-implementation behavior.
  72. class ZoneTableSegment {
  73. protected:
  74. /// \brief Protected constructor
  75. ///
  76. /// An instance implementing this interface is expected to be
  77. /// created by the factory method (\c create()), so this constructor
  78. /// is protected.
  79. ZoneTableSegment(const isc::dns::RRClass&)
  80. {}
  81. public:
  82. /// \brief Destructor
  83. virtual ~ZoneTableSegment() {}
  84. /// \brief Return the ZoneTableHeader for the zone table segment.
  85. virtual ZoneTableHeader& getHeader() = 0;
  86. /// \brief const version of \c getHeader().
  87. virtual const ZoneTableHeader& getHeader() const = 0;
  88. /// \brief Return the MemorySegment for the zone table segment.
  89. virtual isc::util::MemorySegment& getMemorySegment() = 0;
  90. /// \brief Return true if the segment is writable.
  91. ///
  92. /// The user of the zone table segment will load or update zones
  93. /// into the segment only for writable ones. The precise definition
  94. /// of "writability" differs in different derived classes (see
  95. /// derived class documentation). In general, however, the user
  96. /// should only rely on this interface rather than assume a specific
  97. /// definition for a specific type of segment.
  98. virtual bool isWritable() const = 0;
  99. /// \brief Create an instance depending on the memory segment model
  100. ///
  101. /// This is a factory method to create a derived ZoneTableSegment
  102. /// object based on the \c config passed. The method returns a
  103. /// dynamically-allocated object. The caller is responsible for
  104. /// destroying it with \c ZoneTableSegment::destroy().
  105. ///
  106. /// \throw UnknownSegmentType The memory segment type specified in
  107. /// \c config is not known or not supported in this implementation.
  108. ///
  109. /// \param rrclass The RR class of the zones to be maintained in the table.
  110. /// \param type The memory segment type used for the zone table segment.
  111. /// \return Returns a ZoneTableSegment object of the specified type.
  112. static ZoneTableSegment* create(const isc::dns::RRClass& rrclass,
  113. const std::string& type);
  114. /// \brief Destroy a ZoneTableSegment
  115. ///
  116. /// This method destroys the passed ZoneTableSegment. It must be
  117. /// passed a segment previously created by \c ZoneTableSegment::create().
  118. ///
  119. /// \param segment The segment to destroy.
  120. static void destroy(ZoneTableSegment* segment);
  121. };
  122. } // namespace memory
  123. } // namespace datasrc
  124. } // namespace isc
  125. #endif // ZONE_TABLE_SEGMENT_H
  126. // Local Variables:
  127. // mode: c++
  128. // End: