14 #include <boost/foreach.hpp> 15 #include <boost/scoped_ptr.hpp> 16 #include <boost/algorithm/string/predicate.hpp> 31 CfgControlSocket::CfgControlSocket(
Type type,
const string& name,
33 : type_(type),
name_(name), url_(url) {
39 return (CfgControlSocket::Type::UNIX);
40 }
else if (type ==
"http") {
41 return (CfgControlSocket::Type::HTTP);
42 }
else if (type ==
"stdout") {
43 return (CfgControlSocket::Type::STDOUT);
52 case CfgControlSocket::Type::UNIX:
54 case CfgControlSocket::Type::HTTP:
56 case CfgControlSocket::Type::STDOUT:
69 result->set(
"socket-type", Element::create(
typeToString(type_)));
71 result->set(
"socket-name", Element::create(name_));
73 result->set(
"socket-url", Element::create(url_.
toText()));
79 : model_(model), boot_update_(true), subscribe_changes_(true),
80 subscribe_notifications_(true), validate_changes_(true),
81 control_socket_(ctrl_sock) {
87 s <<
"model: " << model_ <<
", control socker: ";
88 if (!control_socket_) {
91 switch (control_socket_->getType()) {
92 case CfgControlSocket::Type::UNIX:
93 s <<
"UNIX:'" << control_socket_->getName() <<
"'";
95 case CfgControlSocket::Type::HTTP:
96 s <<
"HTTP:'" << control_socket_->getUrl().toText() <<
"'";
98 case CfgControlSocket::Type::STDOUT:
112 result->set(
"model", Element::create(model_));
114 result->set(
"boot-update", Element::create(boot_update_));
116 result->set(
"subscribe-changes", Element::create(subscribe_changes_));
118 result->set(
"validate-changes", Element::create(validate_changes_));
120 if (control_socket_) {
121 result->set(
"control-socket", control_socket_->toElement());
139 string type_str = getString(ctrl_sock_config,
"socket-type");
140 string name = getString(ctrl_sock_config,
"socket-name");
141 string url_str = getString(ctrl_sock_config,
"socket-url");
148 }
catch (
const std::exception& ex) {
150 << getPosition(
"socket-type", ctrl_sock_config) <<
")");
155 if (!url.isValid()) {
157 << url.getErrorMessage() <<
" '" << url_str <<
"' (" 158 << getPosition(
"socket-url", ctrl_sock_config) <<
")");
164 }
catch (
const std::exception& ex) {
166 << ctrl_sock_config->getPosition() <<
")");
171 result->setContext(user_context);
182 string model = getString(server_config,
"model");
184 ConstElementPtr ctrl_sock_config = server_config->get(
"control-socket");
186 if (ctrl_sock_config) {
188 ctrl_sock = parser.
parse(ctrl_sock_config);
191 result.reset(
new CfgServer(model, ctrl_sock));
192 }
catch (
const std::exception& ex) {
194 << server_config->getPosition() <<
")");
198 result->setBootUpdate(getBoolean(server_config,
"boot-update"));
199 result->setSubscribeChanges(getBoolean(server_config,
"subscribe-changes"));
200 result->setValidateChanges(getBoolean(server_config,
"validate-changes"));
204 result->setContext(user_context);
CfgServer(const std::string &model, CfgControlSocketPtr ctrl_sock)
Constructor.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
static const std::string typeToString(CfgControlSocket::Type type)
Converts CfgControlSocket::Type to string.
Parser for CfgControlSocket.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< CfgServer > CfgServerPtr
Defines a pointer for CfgServer instances.
static Type stringToType(const std::string &type)
Converts socket type name to CfgControlSocket::Type.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
CfgControlSocketPtr parse(data::ConstElementPtr ctrl_sock_config)
Performs the actual parsing of the given "control-socket" element.
An exception that is thrown if an error occurs while configuring any server.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
boost::shared_ptr< const Element > ConstElementPtr
Type
Defines the list of possible control socket types.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
std::string toText() const
Returns textual representation of the URL.
Defines the logger used by the top-level component of kea-lfc.
Represents a Control Socket.
Contains declarations for loggers used by the Kea netconf agent.
Represents a Managed CfgServer.
ostream & operator<<(ostream &os, const CfgServer &server)
Dumps the contents of a CfgServer as text to a output stream.
boost::shared_ptr< CfgControlSocket > CfgControlSocketPtr
Defines a pointer for CfgControlSocket instances.
CfgServerPtr parse(data::ConstElementPtr server_config)
Performs the actual parsing of the given value from the "managed-servers" map.
std::string toText() const
Returns a text representation for the server.