zone_table_segment.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 <cc/data.h>
  18. #include <util/memory_segment.h>
  19. #include <boost/interprocess/offset_ptr.hpp>
  20. #include <stdlib.h>
  21. namespace isc {
  22. namespace datasrc {
  23. namespace memory {
  24. /// \brief Memory-management independent entry point that contains a
  25. /// pointer to a zone table in memory.
  26. ///
  27. /// An instance of this type lives inside a ZoneTableSegment
  28. /// implementation. It contains an offset pointer to the zone table (a
  29. /// map from domain names to zone locators) in memory.
  30. struct ZoneTableHeader {
  31. public:
  32. /// \brief Returns a pointer to the underlying zone table.
  33. ZoneTable* getTable() {
  34. return (table.get());
  35. }
  36. /// \brief const version of \c getTable().
  37. const ZoneTable* getTable() const {
  38. return (table.get());
  39. }
  40. private:
  41. boost::interprocess::offset_ptr<ZoneTable> table;
  42. };
  43. /// \brief Manages a ZoneTableHeader, an entry point into a table of
  44. /// zones
  45. ///
  46. /// This class specifies an interface for derived implementations which
  47. /// return a pointer to an object of type ZoneTableHeader, an entry
  48. /// point into a table of zones regardless of the underlying memory
  49. /// management implementation. Derived classes would implement the
  50. /// interface for specific memory-implementation behavior.
  51. class ZoneTableSegment {
  52. protected:
  53. /// \brief Protected constructor
  54. ///
  55. /// An instance implementing this interface is expected to be
  56. /// created by the factory method (\c create()), so this constructor
  57. /// is protected.
  58. ZoneTableSegment()
  59. {}
  60. public:
  61. /// \brief Destructor
  62. virtual ~ZoneTableSegment() {}
  63. /// \brief Return the ZoneTableHeader for the zone table segment.
  64. virtual ZoneTableHeader& getHeader() = 0;
  65. /// \brief const version of \c getHeader().
  66. virtual const ZoneTableHeader& getHeader() const = 0;
  67. /// \brief Return the MemorySegment for the zone table segment.
  68. virtual isc::util::MemorySegment& getMemorySegment() = 0;
  69. /// \brief Create an instance depending on the memory segment model
  70. ///
  71. /// This is a factory method to create a derived ZoneTableSegment
  72. /// object based on the \c config passed. The method returns a
  73. /// dynamically-allocated object. The caller is responsible for
  74. /// destroying it with \c ZoneTableSegment::destroy().
  75. ///
  76. /// FIXME: For now, we always return ZoneTableSegmentLocal
  77. /// regardless of the passed \c config.
  78. ///
  79. /// \param config The configuration based on which a derived object
  80. /// is returned.
  81. /// \return Returns a ZoneTableSegment object
  82. static ZoneTableSegment* create(const isc::data::Element& config);
  83. /// \brief Destroy a ZoneTableSegment
  84. ///
  85. /// This method destroys the passed ZoneTableSegment. It must be
  86. /// passed a segment previously created by \c ZoneTableSegment::create().
  87. ///
  88. /// \param segment The segment to destroy.
  89. static void destroy(ZoneTableSegment* segment);
  90. };
  91. } // namespace memory
  92. } // namespace datasrc
  93. } // namespace isc
  94. #endif // __ZONE_TABLE_SEGMENT_H__