zone_table_segment.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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(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 Create an instance depending on the memory segment model
  91. ///
  92. /// This is a factory method to create a derived ZoneTableSegment
  93. /// object based on the \c config passed. The method returns a
  94. /// dynamically-allocated object. The caller is responsible for
  95. /// destroying it with \c ZoneTableSegment::destroy().
  96. ///
  97. /// \throw UnknownSegmentType The memory segment type specified in
  98. /// \c config is not known or not supported in this implementation.
  99. ///
  100. /// \param rrclass The RR class of the zones to be maintained in the table.
  101. /// \param type The memory segment type used for the zone table segment.
  102. /// \return Returns a ZoneTableSegment object of the specified type.
  103. static ZoneTableSegment* create(const isc::dns::RRClass& rrclass,
  104. const std::string& type);
  105. /// \brief Destroy a ZoneTableSegment
  106. ///
  107. /// This method destroys the passed ZoneTableSegment. It must be
  108. /// passed a segment previously created by \c ZoneTableSegment::create().
  109. ///
  110. /// \param segment The segment to destroy.
  111. static void destroy(ZoneTableSegment* segment);
  112. /// \brief Create a zone write corresponding to this segment
  113. ///
  114. /// This creates a new write that can be used to update zones
  115. /// inside this zone table segment.
  116. ///
  117. /// \param loadAction Callback to provide the actual data.
  118. /// \param origin The origin of the zone to reload.
  119. /// \param rrclass The class of the zone to reload.
  120. /// \return New instance of a zone writer. The ownership is passed
  121. /// onto the caller and the caller needs to \c delete it when
  122. /// it's done with the writer.
  123. virtual ZoneWriter* getZoneWriter(const LoadAction& load_action,
  124. const dns::Name& origin,
  125. const dns::RRClass& rrclass) = 0;
  126. };
  127. } // namespace memory
  128. } // namespace datasrc
  129. } // namespace isc
  130. #endif // ZONE_TABLE_SEGMENT_H
  131. // Local Variables:
  132. // mode: c++
  133. // End: