zone_table_segment.h 5.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 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>
19
#include "load_action.h"
20
21
22
23
24
25
26
27
#include <cc/data.h>
#include <util/memory_segment.h>

#include <boost/interprocess/offset_ptr.hpp>

#include <stdlib.h>

namespace isc {
28
29
30
31
32
// Some forward declarations
namespace dns {
class Name;
class RRClass;
}
33
34
namespace datasrc {
namespace memory {
35
class ZoneWriter;
36

37
38
39
40
41
42
/// \brief Memory-management independent entry point that contains a
/// pointer to a zone table in memory.
///
/// An instance of this type lives inside a ZoneTableSegment
/// implementation. It contains an offset pointer to the zone table (a
/// map from domain names to zone locators) in memory.
43
struct ZoneTableHeader {
44
45
46
47
48
49
public:
    /// \brief Returns a pointer to the underlying zone table.
    ZoneTable* getTable() {
        return (table.get());
    }

Mukund Sivaraman's avatar
Mukund Sivaraman committed
50
    /// \brief const version of \c getTable().
51
    const ZoneTable* getTable() const {
52
        return (table.get());
53
54
    }

55
56
57
58
59
    /// \brief Method to set the internal table
    ///
    /// The interface is tentative, we don't know if this is the correct place
    /// and way to set the data. But for now, we need something to be there
    /// at least for the tests. So we have this. For this reason, there are
60
    /// no tests for this method directly. Do not use in actual
61
62
63
64
65
66
67
68
69
70
71
72
73
74
    /// implementation.
    ///
    /// It can be used only once, to initially set it. It can't replace the
    /// one already there.
    ///
    /// \param table Pointer to the table to use.
    /// \throw isc::Unexpected if called the second time.
    void setTable(ZoneTable* table) {
        if (this->table.get() != NULL) {
            isc_throw(isc::Unexpected, "Replacing table");
        }
        this->table = table;
    }

75
private:
76
77
78
    boost::interprocess::offset_ptr<ZoneTable> table;
};

79
80
/// \brief Manages a ZoneTableHeader, an entry point into a table of
/// zones
81
82
83
///
/// This class specifies an interface for derived implementations which
/// return a pointer to an object of type ZoneTableHeader, an entry
84
85
86
/// point into a table of zones regardless of the underlying memory
/// management implementation. Derived classes would implement the
/// interface for specific memory-implementation behavior.
87
class ZoneTableSegment {
88
89
90
91
92
93
94
95
protected:
    /// \brief Protected constructor
    ///
    /// An instance implementing this interface is expected to be
    /// created by the factory method (\c create()), so this constructor
    /// is protected.
    ZoneTableSegment()
    {}
96
97
98
99
public:
    /// \brief Destructor
    virtual ~ZoneTableSegment() {}

100
    /// \brief Return the ZoneTableHeader for the zone table segment.
101
    virtual ZoneTableHeader& getHeader() = 0;
102

103
    /// \brief const version of \c getHeader().
104
    virtual const ZoneTableHeader& getHeader() const = 0;
105

106
107
108
    /// \brief Return the MemorySegment for the zone table segment.
    virtual isc::util::MemorySegment& getMemorySegment() = 0;

109
    /// \brief Create an instance depending on the memory segment model
110
111
    ///
    /// This is a factory method to create a derived ZoneTableSegment
112
113
114
    /// object based on the \c config passed. The method returns a
    /// dynamically-allocated object. The caller is responsible for
    /// destroying it with \c ZoneTableSegment::destroy().
115
    ///
116
117
    /// FIXME: For now, we always return ZoneTableSegmentLocal
    /// regardless of the passed \c config.
118
119
120
121
122
    ///
    /// \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);
123
124
125
126

    /// \brief Destroy a ZoneTableSegment
    ///
    /// This method destroys the passed ZoneTableSegment. It must be
127
    /// passed a segment previously created by \c ZoneTableSegment::create().
128
129
130
    ///
    /// \param segment The segment to destroy.
    static void destroy(ZoneTableSegment* segment);
131

132
    /// \brief Create a zone write corresponding to this segment
133
    ///
134
    /// This creates a new write that can be used to update zones
135
136
137
138
139
    /// inside this zone table segment.
    ///
    /// \param loadAction Callback to provide the actual data.
    /// \param origin The origin of the zone to reload.
    /// \param rrclass The class of the zone to reload.
140
141
    /// \return New instance of a zone reloader. The ownership is passed
    ///     onto the caller.
142
143
144
    virtual ZoneWriter* getZoneWriter(const LoadAction& load_action,
                                      const dns::Name& origin,
                                      const dns::RRClass& rrclass) = 0;
145
146
147
148
149
150
151
};

} // namespace memory
} // namespace datasrc
} // namespace isc

#endif // __ZONE_TABLE_SEGMENT_H__