zone_table_segment.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 <datasrc/memory/zone_table.h>
  17. #include "load_action.h"
  18. #include <cc/data.h>
  19. #include <util/memory_segment.h>
  20. #include <boost/interprocess/offset_ptr.hpp>
  21. #include <stdlib.h>
  22. namespace isc {
  23. // Some forward declarations
  24. namespace dns {
  25. class Name;
  26. class RRClass;
  27. }
  28. namespace datasrc {
  29. namespace memory {
  30. class ZoneWriter;
  31. /// \brief Memory-management independent entry point that contains a
  32. /// pointer to a zone table in memory.
  33. ///
  34. /// An instance of this type lives inside a ZoneTableSegment
  35. /// implementation. It contains an offset pointer to the zone table (a
  36. /// map from domain names to zone locators) in memory.
  37. struct ZoneTableHeader {
  38. public:
  39. /// \brief Returns a pointer to the underlying zone table.
  40. ZoneTable* getTable() {
  41. return (table.get());
  42. }
  43. /// \brief const version of \c getTable().
  44. const ZoneTable* getTable() const {
  45. return (table.get());
  46. }
  47. /// \brief Method to set the internal table
  48. ///
  49. /// The interface is tentative, we don't know if this is the correct place
  50. /// and way to set the data. But for now, we need something to be there
  51. /// at least for the tests. So we have this. For this reason, there are
  52. /// no tests for this method directly. Do not use in actual
  53. /// implementation.
  54. ///
  55. /// It can be used only once, to initially set it. It can't replace the
  56. /// one already there.
  57. ///
  58. /// \param table Pointer to the table to use.
  59. /// \throw isc::Unexpected if called the second time.
  60. void setTable(ZoneTable* table) {
  61. if (this->table.get() != NULL) {
  62. isc_throw(isc::Unexpected, "Replacing table");
  63. }
  64. this->table = table;
  65. }
  66. private:
  67. boost::interprocess::offset_ptr<ZoneTable> table;
  68. };
  69. /// \brief Manages a ZoneTableHeader, an entry point into a table of
  70. /// zones
  71. ///
  72. /// This class specifies an interface for derived implementations which
  73. /// return a pointer to an object of type ZoneTableHeader, an entry
  74. /// point into a table of zones regardless of the underlying memory
  75. /// management implementation. Derived classes would implement the
  76. /// interface for specific memory-implementation behavior.
  77. class ZoneTableSegment {
  78. protected:
  79. /// \brief Protected constructor
  80. ///
  81. /// An instance implementing this interface is expected to be
  82. /// created by the factory method (\c create()), so this constructor
  83. /// is protected.
  84. ZoneTableSegment()
  85. {}
  86. public:
  87. /// \brief Destructor
  88. virtual ~ZoneTableSegment() {}
  89. /// \brief Return the ZoneTableHeader for the zone table segment.
  90. virtual ZoneTableHeader& getHeader() = 0;
  91. /// \brief const version of \c getHeader().
  92. virtual const ZoneTableHeader& getHeader() const = 0;
  93. /// \brief Return the MemorySegment for the zone table segment.
  94. virtual isc::util::MemorySegment& getMemorySegment() = 0;
  95. /// \brief Create an instance depending on the memory segment model
  96. ///
  97. /// This is a factory method to create a derived ZoneTableSegment
  98. /// object based on the \c config passed. The method returns a
  99. /// dynamically-allocated object. The caller is responsible for
  100. /// destroying it with \c ZoneTableSegment::destroy().
  101. ///
  102. /// FIXME: For now, we always return ZoneTableSegmentLocal
  103. /// regardless of the passed \c config.
  104. ///
  105. /// \param config The configuration based on which a derived object
  106. /// is returned.
  107. /// \return Returns a ZoneTableSegment object
  108. static ZoneTableSegment* create(const isc::data::Element& config);
  109. /// \brief Destroy a ZoneTableSegment
  110. ///
  111. /// This method destroys the passed ZoneTableSegment. It must be
  112. /// passed a segment previously created by \c ZoneTableSegment::create().
  113. ///
  114. /// \param segment The segment to destroy.
  115. static void destroy(ZoneTableSegment* segment);
  116. /// \brief Create a zone write corresponding to this segment
  117. ///
  118. /// This creates a new write that can be used to update zones
  119. /// inside this zone table segment.
  120. ///
  121. /// \param loadAction Callback to provide the actual data.
  122. /// \param origin The origin of the zone to reload.
  123. /// \param rrclass The class of the zone to reload.
  124. /// \return New instance of a zone reloader. The ownership is passed
  125. /// onto the caller.
  126. virtual ZoneWriter* getZoneWriter(const LoadAction& load_action,
  127. const dns::Name& origin,
  128. const dns::RRClass& rrclass) = 0;
  129. };
  130. } // namespace memory
  131. } // namespace datasrc
  132. } // namespace isc
  133. #endif // __ZONE_TABLE_SEGMENT_H__