27 CfgControlSocket::CfgControlSocket(
Type type,
const string& name,
29 : type_(type),
name_(name), url_(url) {
35 return (CfgControlSocket::Type::UNIX);
36 }
else if (type ==
"http") {
37 return (CfgControlSocket::Type::HTTP);
38 }
else if (type ==
"stdout") {
39 return (CfgControlSocket::Type::STDOUT);
48 case CfgControlSocket::Type::UNIX:
50 case CfgControlSocket::Type::HTTP:
52 case CfgControlSocket::Type::STDOUT:
65 result->set(
"socket-type", Element::create(
typeToString(type_)));
67 result->set(
"socket-name", Element::create(name_));
69 result->set(
"socket-url", Element::create(url_.
toText()));
75 : model_(model), boot_update_(true), subscribe_changes_(true),
76 subscribe_notifications_(true), validate_changes_(true),
77 control_socket_(ctrl_sock) {
83 s <<
"model: " << model_ <<
", control socker: ";
84 if (!control_socket_) {
87 switch (control_socket_->getType()) {
88 case CfgControlSocket::Type::UNIX:
89 s <<
"UNIX:'" << control_socket_->getName() <<
"'";
91 case CfgControlSocket::Type::HTTP:
92 s <<
"HTTP:'" << control_socket_->getUrl().toText() <<
"'";
94 case CfgControlSocket::Type::STDOUT:
108 result->set(
"model", Element::create(model_));
110 result->set(
"boot-update", Element::create(boot_update_));
112 result->set(
"subscribe-changes", Element::create(subscribe_changes_));
114 result->set(
"validate-changes", Element::create(validate_changes_));
116 if (control_socket_) {
117 result->set(
"control-socket", control_socket_->toElement());
135 string type_str =
getString(ctrl_sock_config,
"socket-type");
136 string name =
getString(ctrl_sock_config,
"socket-name");
137 string url_str =
getString(ctrl_sock_config,
"socket-url");
144 }
catch (exception
const& ex) {
146 <<
getPosition(
"socket-type", ctrl_sock_config) <<
")");
154 <<
getPosition(
"socket-url", ctrl_sock_config) <<
")");
160 }
catch (exception
const& ex) {
162 << ctrl_sock_config->getPosition() <<
")");
167 result->setContext(user_context);
178 string model =
getString(server_config,
"model");
180 ConstElementPtr ctrl_sock_config = server_config->get(
"control-socket");
182 if (ctrl_sock_config) {
184 ctrl_sock = parser.
parse(ctrl_sock_config);
187 result.reset(
new CfgServer(model, ctrl_sock));
188 }
catch (exception
const& ex) {
190 << server_config->getPosition() <<
")");
194 result->setBootUpdate(
getBoolean(server_config,
"boot-update"));
195 result->setSubscribeChanges(
getBoolean(server_config,
"subscribe-changes"));
196 result->setValidateChanges(
getBoolean(server_config,
"validate-changes"));
200 result->setContext(user_context);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
An exception that is thrown if an error occurs while configuring any server.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static const data::Element::Position & getPosition(const std::string &name, const data::ConstElementPtr parent)
Utility method that returns position of an element.
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
std::string toText() const
Returns textual representation of the URL.
std::string getErrorMessage() const
Returns parsing error message.
bool isValid() const
Checks if the URL is valid.
Represents a Control Socket.
isc::data::ElementPtr toElement() const override final
Unparse a configuration object.
Type
Defines the list of possible control socket types.
static const std::string typeToString(CfgControlSocket::Type type)
Converts CfgControlSocket::Type to string.
static Type stringToType(const std::string &type)
Converts socket type name to CfgControlSocket::Type.
Represents a Managed CfgServer.
CfgServer(const std::string &model, CfgControlSocketPtr ctrl_sock)
Constructor.
isc::data::ElementPtr toElement() const override final
Unparse a configuration object.
std::string toText() const
Returns a text representation for the server.
Parser for CfgControlSocket.
CfgControlSocketPtr parse(data::ConstElementPtr ctrl_sock_config)
Performs the actual parsing of the given "control-socket" element.
CfgServerPtr parse(data::ConstElementPtr server_config)
Performs the actual parsing of the given value from the "managed-servers" map.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
ostream & operator<<(ostream &os, const CfgServer &server)
Dumps the contents of a CfgServer as text to a output stream.
std::shared_ptr< CfgServer > CfgServerPtr
Defines a pointer for CfgServer instances.
std::shared_ptr< CfgControlSocket > CfgControlSocketPtr
Defines a pointer for CfgControlSocket instances.
Defines the logger used by the top-level component of kea-lfc.
Contains declarations for loggers used by the Kea netconf agent.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.