Kea  1.9.9-git
server_selector.cc
Go to the documentation of this file.
1 // Copyright (C) 2019-2020 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 #include <config.h>
8 
10 #include <exceptions/exceptions.h>
11 
12 using namespace isc::data;
13 
14 namespace isc {
15 namespace db {
16 
17 ServerSelector
18 ServerSelector::MULTIPLE(const std::set<std::string>& server_tags) {
19  if (server_tags.empty()) {
20  isc_throw(InvalidOperation, "ServerSelector: expecting at least one"
21  " server tag");
22  }
23 
24  std::set<ServerTag> tags;
25 
26  // Create a set of tags from strings.
27  for (auto tag : server_tags) {
28  tags.insert(ServerTag(tag));
29  }
30 
31  ServerSelector selector(tags);
32  return (selector);
33 }
34 
35 ServerSelector::ServerSelector(const Type& type)
36  : type_(type), tags_() {
37  if (type_ == Type::ALL) {
38  tags_.insert(ServerTag());
39  }
40 }
41 
42 ServerSelector::ServerSelector(const ServerTag& server_tag)
43  : type_(server_tag.amAll() ? Type::ALL : Type::SUBSET), tags_({server_tag}) {
44 }
45 
46 ServerSelector::ServerSelector(const std::set<ServerTag>& server_tags)
47  : type_(Type::SUBSET), tags_(server_tags) {
48 }
49 
50 } // end of namespace isc::db
51 } // end of namespace isc
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Represents a server tag.
Definition: server_tag.h:25
Server selector for associating objects in a database with specific servers.
Defines the logger used by the top-level component of kea-dhcp-ddns.
A generic exception that is thrown if a function is called in a prohibited way.