Kea: server_selector.cc Source File

| Kea 2.2.0

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
9#include <database/server_selector.h>
10#include <exceptions/exceptions.h>
11
12using namespace isc::data;
13
14namespace isc {
15namespace db {
16
17ServerSelector
18ServerSelector::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
35ServerSelector::ServerSelector(const Type& type)
36 : type_(type), tags_() {
37 if (type_ == Type::ALL) {
38 tags_.insert(ServerTag());
39 }
40}
41
42ServerSelector::ServerSelector(const ServerTag& server_tag)
43 : type_(server_tag.amAll() ? Type::ALL : Type::SUBSET), tags_({server_tag}) {
44}
45
46ServerSelector::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
isc::InvalidOperation
A generic exception that is thrown if a function is called in a prohibited way.
Definition: exceptions/exceptions.h:143
isc::data::ServerTag
Represents a server tag.
Definition: server_tag.h:25
isc::db::ServerSelector
Server selector for associating objects in a database with specific servers.
Definition: server_selector.h:46
isc::db::ServerSelector::MULTIPLE
static ServerSelector MULTIPLE(const std::set< std::string > &server_tags)
Factory returning "multiple servers" selector.
Definition: server_selector.cc:18
isc::db::ServerSelector::Type::ALL
@ ALL
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: exceptions/exceptions.h:210
isc::data
Definition: base_stamped_element.cc:12
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143
server_selector.h