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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
/// @file control_socket.h
/// Contains declarations for control socket communication.
#ifndef CONTROL_SOCKET_H
#define CONTROL_SOCKET_H
#include <netconf/netconf_config.h>
#include <exceptions/exceptions.h>
namespace isc {
namespace netconf {
/// @brief Exception thrown when the error during communication.
class ControlSocketError : public isc::Exception {
public:
ControlSocketError(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) { };
};
/// @brief Base class for control socket communication.
///
/// This class is the base class for control socket communication.
/// Derived classes implement config-get, config-test and config-set
/// using control sockets of different types. Those classes are used to
/// communicate with other Kea daemons.
class ControlSocketBase {
public:
/// @brief Constructor.
///
/// @param ctrl_sock The control socket configuration.
/// @throw ControlSocketError if ctrl_sock is null.
ControlSocketBase(CfgControlSocketPtr ctrl_sock) : socket_cfg_(ctrl_sock) {
if (!ctrl_sock) {
isc_throw(ControlSocketError, "ControlSocket constructor called "
"with a null configuration");
}
}
/// @brief Destructor (does nothing).
virtual ~ControlSocketBase() {
}
/// @brief Getter which returns the socket type.
///
/// @return returns the socket type as a CfgControlSocket::Type.
CfgControlSocket::Type getType() const {
return (socket_cfg_->getType());
}
/// @brief Returns the Unix socket name.
///
/// @return returns the Unix socket name as a std::string.
const std::string getName() const {
return (socket_cfg_->getName());
}
/// @brief Returns the HTTP server URL.
///
/// @return returns the HTTP server URL as an isc::http::Url.
const isc::http::Url getUrl() const {
return (socket_cfg_->getUrl());
}
/// @brief Get configuration.
///
/// Call config-get over the control socket.
///
/// @param service The target service (used by http).
/// @return The JSON element answer of config-get.
/// @throw ControlSocketError when a communication error occurs.
virtual data::ConstElementPtr configGet(const std::string& service) = 0;
/// @brief Test configuration.
///
/// Call config-test over the control socket.
///
/// @param config The configuration to test.
/// @param service The target service (used by http).
/// @return The JSON element answer of config-test.
/// @throw ControlSocketError when a communication error occurs.
virtual data::ConstElementPtr configTest(data::ConstElementPtr config,
const std::string& service) = 0;
/// @brief Set configuration.
///
/// Call config-set over the control socket.
///
/// @param config The configuration to set.
/// @param service The target service (used by http).
/// @return The JSON element answer of config-set.
/// @throw ControlSocketError when a communication error occurs.
virtual data::ConstElementPtr configSet(data::ConstElementPtr config,
const std::string& service) = 0;
/// @brief The control socket configuration.
CfgControlSocketPtr socket_cfg_;
};
/// @brief Type definition for the pointer to the @c ControlSocketBase.
typedef boost::shared_ptr<ControlSocketBase> ControlSocketBasePtr;
/// @brief Factory template for control sockets.
///
/// @tparam TYPE The control socket type.
/// @param ctrl_sock The control socket configuration.
/// @return A pointer to a control socket communication object.
/// @throw NotImplemented if no specialization was called.
template <CfgControlSocket::Type TYPE> ControlSocketBasePtr
createControlSocket(CfgControlSocketPtr ctrl_sock) {
isc_throw(NotImplemented, "not specialized createControlSocket");
}
/// @brief Factory function for control sockets.
///
/// @param ctrl_sock The control socket configuration.
/// @return A pointer to a control socket communication object.
/// @throw BadValue if called with null or an unknown type.
ControlSocketBasePtr
controlSocketFactory(CfgControlSocketPtr ctrl_sock);
} // namespace netconf
} // namespace isc
#endif // CONTROL_SOCKET_H
|