/src/kea/src/lib/cc/stamped_element.h
Line | Count | Source |
1 | | // Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC") |
2 | | // |
3 | | // This Source Code Form is subject to the terms of the Mozilla Public |
4 | | // License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | // file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | | |
7 | | #ifndef STAMPED_ELEMENT_H |
8 | | #define STAMPED_ELEMENT_H |
9 | | |
10 | | #include <cc/base_stamped_element.h> |
11 | | #include <cc/server_tag.h> |
12 | | #include <set> |
13 | | |
14 | | namespace isc { |
15 | | namespace data { |
16 | | |
17 | | /// @brief This class represents configuration element which is |
18 | | /// associated with database identifier, modification timestamp |
19 | | /// and servers. |
20 | | /// |
21 | | /// Classes storing Kea configuration should derive from this object |
22 | | /// to track ids and modification times of the configuration objects. |
23 | | /// This is specifically required by the Kea Configuration Backend |
24 | | /// feature which stores and fetches configuration from the database. |
25 | | /// The configuration elements must be accessible by their database |
26 | | /// identifiers and modification times. |
27 | | /// |
28 | | /// @note This class is not derived from @c Element and should not |
29 | | /// be confused with the classes being derived from @c Element class. |
30 | | /// Those classes are used to represent JSON structures, whereas this |
31 | | /// class represents data fetched from the database. |
32 | | /// |
33 | | /// @todo Find a better name for @c StampedElement. |
34 | | class StampedElement : public BaseStampedElement { |
35 | | public: |
36 | | |
37 | | /// @brief Constructor. |
38 | | /// |
39 | | /// Sets timestamp to the current time. |
40 | | StampedElement(); |
41 | | |
42 | | /// @brief Adds new server tag. |
43 | | /// |
44 | | /// @param server_tag new server tag. |
45 | | /// @throw BadValue if the server tag length exceeds 256 characters. |
46 | 147 | void setServerTag(const std::string& server_tag) { |
47 | 147 | server_tags_.insert(ServerTag(server_tag)); |
48 | 147 | } |
49 | | |
50 | | /// @brief Deletes server tag. |
51 | | /// |
52 | | /// Remove the first occurrence of the given server tag. |
53 | | /// |
54 | | /// @param server_tag server tag to delete. |
55 | | /// @throw NotFound if the server tag cannot be found. |
56 | | void delServerTag(const std::string& server_tag); |
57 | | |
58 | | /// @brief Returns server tags. |
59 | | /// |
60 | | /// @return Server tags. |
61 | 0 | std::set<ServerTag> getServerTags() const { |
62 | 0 | return (server_tags_); |
63 | 0 | } |
64 | | |
65 | | /// @brief Checks if the element has the given server tag. |
66 | | /// |
67 | | /// @param server_tag Server tag to be found. |
68 | | /// @return true if the server tag was found, false otherwise. |
69 | | bool hasServerTag(const ServerTag& server_tag) const; |
70 | | |
71 | | /// @brief Checks if the element has 'all' server tag. |
72 | | /// |
73 | | /// @return true if the server tag was found, false otherwise. |
74 | | bool hasAllServerTag() const; |
75 | | |
76 | | /// @brief Returns an object representing metadata to be returned |
77 | | /// with objects from the configuration backend. |
78 | | /// |
79 | | /// @return Pointer to the metadata element. |
80 | | isc::data::ElementPtr getMetadata() const; |
81 | | |
82 | | private: |
83 | | |
84 | | /// @brief Holds server tags. |
85 | | std::set<ServerTag> server_tags_; |
86 | | }; |
87 | | |
88 | | } // end of namespace isc::data |
89 | | } // end of namespace isc |
90 | | |
91 | | #endif |