summaryrefslogtreecommitdiffstats
path: root/src/lib/datasrc/iterator.h
blob: e1c69294dad0157f804a9f3a385fe7bb6950e3d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (C) 2011  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 DATASRC_ZONE_ITERATOR_H
#define DATASRC_ZONE_ITERATOR_H 1

#include <dns/rrset.h>

#include <boost/noncopyable.hpp>

#include <datasrc/zone.h>

namespace isc {
namespace datasrc {

/**
 * \brief Read-only iterator to a zone.
 *
 * You can get an instance of (descendand of) ZoneIterator from
 * DataSourceClient::getIterator() method. The actual concrete implementation
 * will be different depending on the actual data source used. This is the
 * abstract interface.
 *
 * There's no way to start iterating from the beginning again or return.
 */
class ZoneIterator : public boost::noncopyable {
public:
    /**
     * \brief Destructor
     *
     * Virtual destructor. It is empty, but ensures the right destructor from
     * descendant is called.
     */
    virtual ~ ZoneIterator() { }

    /**
     * \brief Get next RRset from the zone.
     *
     * This returns the next RRset in the zone as a shared pointer. The
     * shared pointer is used to allow both accessing in-memory data and
     * automatic memory management.
     *
     * Any special order is not guaranteed.
     *
     * While this can potentially throw anything (including standard allocation
     * errors), it should be rare.
     *
     * \return Pointer to the next RRset or NULL pointer when the iteration
     *     gets to the end of the zone.
     */
    virtual isc::dns::ConstRRsetPtr getNextRRset() = 0;

    /**
     * \brief Return the SOA record of the zone in the iterator context.
     *
     * This method returns the zone's SOA record (if any, and a valid zone
     * should have it) in the form of an RRset object.  This SOA is identical
     * to that (again, if any) contained in the sequence of RRsets returned
     * by the iterator.  In that sense this method is redundant, but is
     * provided as a convenient utility for the application of the
     * iterator; the application may need to know the SOA serial or the
     * SOA RR itself for the purpose of protocol handling or skipping the
     * expensive iteration processing.
     *
     * If the zone doesn't have an SOA (which is broken, but some data source
     * may allow that situation), this method returns NULL.  Also, in the
     * normal and valid case, the SOA should have exactly one RDATA, but
     * this API does not guarantee it as some data source may accept such an
     * abnormal condition.  It's up to the caller whether to check the number
     * of RDATA and how to react to the unexpected case.
     *
     * Each concrete derived method must ensure that the SOA returned by this
     * method is identical to the zone's SOA returned via the iteration.
     * For example, even if another thread or process updates the SOA while
     * the iterator is working, the result of this method must not be
     * affected by the update.  For database based data sources, this can
     * be done by making the entire iterator operation as a single database
     * transaction, but the actual implementation can differ.
     *
     * \exception None
     *
     * \return A shared pointer to an SOA RRset that would be returned
     * from the iteration.  It will be NULL if the zone doesn't have an SOA.
     */
    virtual isc::dns::ConstRRsetPtr getSOA() const = 0;
};

}
}
#endif  // DATASRC_ZONE_ITERATOR_H

// Local Variables:
// mode: c++
// End: