|
9 | 9 |
|
10 | 10 | #include <boost/shared_ptr.hpp> |
11 | 11 | #include <cstdint> |
| 12 | +#include <set> |
12 | 13 | #include <string> |
13 | 14 |
|
14 | 15 | namespace isc { |
15 | 16 | namespace cb { |
16 | 17 |
|
| 18 | +/// @brief Server selector for associating objects in a database with |
| 19 | +/// specific servers. |
| 20 | +/// |
| 21 | +/// Configuration information stored in the configuration backends can be |
| 22 | +/// associated with selected servers, all servers or no particular server. |
| 23 | +/// For example: a particular subnet definition in the database may be |
| 24 | +/// associated with one server or can be shared by multiple servers. |
| 25 | +/// In the latter case, a subnet may be associated with a subset of |
| 26 | +/// servers or all servers. An administrator may also add the |
| 27 | +/// configuration data into the database and do not associate this data |
| 28 | +/// with any patrticular server. |
| 29 | +/// |
| 30 | +/// When fetching the configuration data from a databse or when storing |
| 31 | +/// data in the database there is a need to specify which servers this |
| 32 | +/// data is associated with. The @c ServerSelector class represents |
| 33 | +/// such associations. |
| 34 | +/// |
| 35 | +/// It includes three modes of selection: UNASSIGNED, ALL and SUBSET and |
| 36 | +/// several factory functions making associations described above. |
| 37 | +/// |
| 38 | +/// The @c ServerSelector class should be used in objects derived from |
| 39 | +/// @c BaseConfigBackendPool and in objects derived from |
| 40 | +/// @c BaseConfigBackend to indicate which servers the specific calls |
| 41 | +/// exposed by these objects refer to. |
| 42 | +class ServerSelector { |
| 43 | +public: |
| 44 | + |
| 45 | + /// @brief Type of the server selection. |
| 46 | + enum class Type { |
| 47 | + UNASSIGNED, |
| 48 | + ALL, |
| 49 | + SUBSET |
| 50 | + }; |
| 51 | + |
| 52 | + /// @brief Factory returning "unassigned" server selector. |
| 53 | + static ServerSelector& UNASSIGNED() { |
| 54 | + static ServerSelector selector(Type::UNASSIGNED); |
| 55 | + return (selector); |
| 56 | + } |
| 57 | + |
| 58 | + /// @brief Factory returning "all servers" selector. |
| 59 | + static ServerSelector& ALL() { |
| 60 | + static ServerSelector selector(Type::ALL); |
| 61 | + return (selector); |
| 62 | + } |
| 63 | + |
| 64 | + /// @brief Factory returning selector of one server. |
| 65 | + /// |
| 66 | + /// @param server_tag tag of the single server to be selected. |
| 67 | + static ServerSelector& ONE(const std::string& server_tag) { |
| 68 | + static ServerSelector selector(server_tag); |
| 69 | + return (selector); |
| 70 | + } |
| 71 | + |
| 72 | + /// @brief Factory returning "multiple servers" selector. |
| 73 | + /// |
| 74 | + /// @param server_tags set of server tags to be selected. |
| 75 | + static ServerSelector& MULTIPLE(const std::set<std::string>& server_tags) { |
| 76 | + static ServerSelector selector(server_tags); |
| 77 | + return (selector); |
| 78 | + } |
| 79 | + |
| 80 | + /// @brief Returns type of the selector. |
| 81 | + Type getType() const { |
| 82 | + return (type_); |
| 83 | + } |
| 84 | + |
| 85 | + /// @brief Returns tags associated with the selector. |
| 86 | + /// |
| 87 | + /// @return server tags for mutliple selections and for one server, |
| 88 | + /// empty set for all servers and and unassigned. |
| 89 | + std::set<std::string> getTags() const { |
| 90 | + return (tags_); |
| 91 | + } |
| 92 | + |
| 93 | +private: |
| 94 | + |
| 95 | + /// @brief Constructor used for "unassigned" and "all" slection types. |
| 96 | + /// |
| 97 | + /// @param type selector type. |
| 98 | + explicit ServerSelector(const Type& type) |
| 99 | + : type_(type), tags_() { |
| 100 | + } |
| 101 | + |
| 102 | + /// @brief Constructor used for selecting a single server. |
| 103 | + /// |
| 104 | + /// @param server_tag tag of the server to be selected. |
| 105 | + explicit ServerSelector(const std::string& server_tag) |
| 106 | + : type_(Type::SUBSET), tags_() { |
| 107 | + tags_.insert(server_tag); |
| 108 | + } |
| 109 | + |
| 110 | + /// @brief Constructor used for selecting multiple servers. |
| 111 | + /// |
| 112 | + /// @param server_tags set of server tags. |
| 113 | + explicit ServerSelector(const std::set<std::string>& server_tags) |
| 114 | + : type_(Type::SUBSET), tags_(server_tags) { |
| 115 | + } |
| 116 | + |
| 117 | + /// @brief Selection type used. |
| 118 | + Type type_; |
| 119 | + |
| 120 | + /// @brief Holds tags of explicitly selected servers. |
| 121 | + std::set<std::string> tags_; |
| 122 | +}; |
| 123 | + |
17 | 124 | /// @brief Base class for server specific configuration backends. |
18 | 125 | class BaseConfigBackend { |
19 | 126 | public: |
|
0 commit comments