diff --git a/src/bin/netconf/netconf.cc b/src/bin/netconf/netconf.cc index 50f3f9ef82..f0937dce38 100644 --- a/src/bin/netconf/netconf.cc +++ b/src/bin/netconf/netconf.cc @@ -713,8 +713,8 @@ NetconfAgent::logChanges(Session sess, string_view const& model) { msg << " (list)"; } else { optional const str( - TranslatorBasic::translateToYang(TranslatorBasic::translateFromYang(change.node), - LeafBaseType::Unknown)); + Translator::translateToYang(Translator::translateFromYang(change.node), + LeafBaseType::Unknown)); if (str) { msg << " = " << *str; } diff --git a/src/lib/yang/tests/config_unittests.cc b/src/lib/yang/tests/config_unittests.cc index a5c1d17c12..8096bad199 100644 --- a/src/lib/yang/tests/config_unittests.cc +++ b/src/lib/yang/tests/config_unittests.cc @@ -62,7 +62,7 @@ public: virtual ~ConfigTest() = default; void SetUp() override { - translator_.reset(new TranslatorBasic(session_, model_)); + translator_.reset(new Translator(session_, model_)); cleanModelData(); } @@ -181,7 +181,7 @@ public: /// @brief The sysrepo session. Session session_; - std::unique_ptr translator_; + std::unique_ptr translator_; }; // ConfigTest struct ConfigTestKeaV4 : ConfigTest { diff --git a/src/lib/yang/tests/translator_unittests.cc b/src/lib/yang/tests/translator_unittests.cc index b2c79ff1b0..f1de44c83f 100644 --- a/src/lib/yang/tests/translator_unittests.cc +++ b/src/lib/yang/tests/translator_unittests.cc @@ -20,7 +20,7 @@ using namespace isc::yang::test; using namespace libyang; using namespace sysrepo; -struct TranslatorBasicTest : ::testing::Test { +struct TranslatorTest : ::testing::Test { void SetUp() override { SysrepoSetup::cleanSharedMemory(); cleanUp(); @@ -42,27 +42,27 @@ private: session.deleteItem("/keatest-module:presence-container"); session.applyChanges(); } -}; // TranslatorBasicTest +}; // TranslatorTest namespace { // Test constructor. -TEST_F(TranslatorBasicTest, constructor) { +TEST_F(TranslatorTest, constructor) { // Get a session. Session sess(Connection{}.sessionStart()); sess.switchDatastore(sysrepo::Datastore::Candidate); // Get a translator object. - std::unique_ptr t_obj; - EXPECT_NO_THROW_LOG(t_obj.reset(new TranslatorBasic(sess, ""))); + std::unique_ptr t_obj; + EXPECT_NO_THROW_LOG(t_obj.reset(new Translator(sess, ""))); } // Test basic YANG to JSON value conversion using sysrepo test models. -TEST_F(TranslatorBasicTest, getItem) { +TEST_F(TranslatorTest, getItem) { // Get a translator object to play with. Session sess(Connection{}.sessionStart()); sess.switchDatastore(sysrepo::Datastore::Candidate); - std::unique_ptr t_obj; - ASSERT_NO_THROW_LOG(t_obj.reset(new TranslatorBasic(sess, ""))); + std::unique_ptr t_obj; + ASSERT_NO_THROW_LOG(t_obj.reset(new Translator(sess, ""))); string value; ConstElementPtr elem; string xpath; @@ -237,100 +237,100 @@ TEST_F(TranslatorBasicTest, getItem) { } // Test JSON to basic YANG value conversion using the static method. -TEST_F(TranslatorBasicTest, valueTo) { +TEST_F(TranslatorTest, valueTo) { optional value; // Null. ConstElementPtr elem; - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::String)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::String)); EXPECT_EQ(nullopt, value); EXPECT_FALSE(elem); // Container. elem = Element::createMap(); - EXPECT_THROW_MSG(TranslatorBasic::translateToYang(elem, LeafBaseType::Unknown), NotImplemented, - "TranslatorBasic::value(): map element"); + EXPECT_THROW_MSG(Translator::translateToYang(elem, LeafBaseType::Unknown), NotImplemented, + "Translator::value(): map element"); // List. elem = Element::createList(); - EXPECT_THROW_MSG(TranslatorBasic::translateToYang(elem, LeafBaseType::Unknown), NotImplemented, - "TranslatorBasic::value(): list element"); + EXPECT_THROW_MSG(Translator::translateToYang(elem, LeafBaseType::Unknown), NotImplemented, + "Translator::value(): list element"); // String. string str("foo"); elem = Element::create(str); - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::String)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::String)); EXPECT_EQ(elem->stringValue(), value); // Bool. elem = Element::create(false); - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::Bool)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::Bool)); EXPECT_EQ(elem->str(), value); // Unsigned 8 bit integer. elem = Element::create(123); - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::Uint8)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::Uint8)); EXPECT_EQ(elem->str(), value); elem.reset(); // Unsigned 16 bit integer. elem = Element::create(12345); - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::Uint16)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::Uint16)); EXPECT_EQ(elem->str(), value); elem.reset(); // Unsigned 32 bit integer. elem = Element::create(123456789); - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::Uint32)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::Uint32)); EXPECT_EQ(elem->str(), value); elem.reset(); // Signed 8 bit integer. elem = Element::create(-123); - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::Int8)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::Int8)); EXPECT_EQ(elem->str(), value); elem.reset(); // Signed 16 bit integer. elem = Element::create(-12345); - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::Int16)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::Int16)); EXPECT_EQ(elem->str(), value); elem.reset(); // Signed 32 bit integer. elem = Element::create(-123456789); - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::Int32)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::Int32)); EXPECT_EQ(elem->str(), value); elem.reset(); // Identity reference. elem = Element::create(str); - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::IdentityRef)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::IdentityRef)); EXPECT_EQ(elem->stringValue(), value); // Enumeration item. - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::Enum)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::Enum)); EXPECT_EQ(elem->stringValue(), value); // Binary. elem = Element::create(string("foobar")); - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::Binary)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::Binary)); EXPECT_EQ("Zm9vYmFy", value); // Decimal 64. double d64(.1234); elem = Element::create(d64); - EXPECT_NO_THROW_LOG(value = TranslatorBasic::translateToYang(elem, LeafBaseType::Dec64)); + EXPECT_NO_THROW_LOG(value = Translator::translateToYang(elem, LeafBaseType::Dec64)); EXPECT_EQ(elem->str(), value); } // Test JSON to basic YANG value conversion using sysrepo test models. -TEST_F(TranslatorBasicTest, setItem) { +TEST_F(TranslatorTest, setItem) { // Get a translator object to play with. Session sess(Connection{}.sessionStart()); sess.switchDatastore(sysrepo::Datastore::Candidate); - std::unique_ptr t_obj; - ASSERT_NO_THROW_LOG(t_obj.reset(new TranslatorBasic(sess, ""))); + std::unique_ptr t_obj; + ASSERT_NO_THROW_LOG(t_obj.reset(new Translator(sess, ""))); ElementPtr elem; string xpath; @@ -519,12 +519,12 @@ TEST_F(TranslatorBasicTest, setItem) { } // Test YANG list item retrieval. -TEST_F(TranslatorBasicTest, list) { +TEST_F(TranslatorTest, list) { // Get a translator object to play with. Session sess(Connection{}.sessionStart()); sess.switchDatastore(sysrepo::Datastore::Candidate); - std::unique_ptr t_obj; - ASSERT_NO_THROW_LOG(t_obj.reset(new TranslatorBasic(sess, ""))); + std::unique_ptr t_obj; + ASSERT_NO_THROW_LOG(t_obj.reset(new Translator(sess, ""))); string xpath; // Empty list. diff --git a/src/lib/yang/tests/translator_utils_unittests.cc b/src/lib/yang/tests/translator_utils_unittests.cc index e463d73bda..a4593cd052 100644 --- a/src/lib/yang/tests/translator_utils_unittests.cc +++ b/src/lib/yang/tests/translator_utils_unittests.cc @@ -240,7 +240,7 @@ void sanityCheckConfig(const std::string& model, const YRTree& tree) { sess.switchDatastore(sysrepo::Datastore::Candidate); // Cleanup. - TranslatorBasic translator(sess, model); + Translator translator(sess, model); if (model == "keatest-module") { translator.deleteItem("/keatest-module:container"); translator.deleteItem("/keatest-module:kernel-modules"); diff --git a/src/lib/yang/testutils/translator_test.cc b/src/lib/yang/testutils/translator_test.cc index ecf18fc6dd..ca6f09a1b6 100644 --- a/src/lib/yang/testutils/translator_test.cc +++ b/src/lib/yang/testutils/translator_test.cc @@ -99,7 +99,7 @@ YangRepr::YangReprItem::get(const string& xpath, Session session) { // Get the underlying type. type = data_node->schema().asLeaf().valueType().asLeafRef().resolvedType().base(); } - value = TranslatorBasic::translateToYang(TranslatorBasic::translateFromYang(data_node), + value = Translator::translateToYang(Translator::translateFromYang(data_node), type); val_xpath = string(data_node->path()); } catch (Error const& ex) { @@ -113,7 +113,7 @@ YangRepr::Tree YangRepr::get(Session session) const { Tree result; try { - TranslatorBasic tb(session, model_); + Translator tb(session, model_); string const xpath0("/" + model_ + ":*//."); tb.forAll(xpath0, [&](libyang::DataNode const& node) { string const& xpath(node.path()); diff --git a/src/lib/yang/translator.cc b/src/lib/yang/translator.cc index 77e6e13fc5..55e7990807 100644 --- a/src/lib/yang/translator.cc +++ b/src/lib/yang/translator.cc @@ -24,14 +24,14 @@ using namespace sysrepo; namespace isc { namespace yang { -TranslatorBasic::TranslatorBasic(Session session, const string& model) +Translator::Translator(Session session, const string& model) : session_(session), model_(model) { } void -TranslatorBasic::checkAndGetLeaf(ElementPtr& storage, - DataNode const& data_node, - string const& name) const { +Translator::checkAndGetLeaf(ElementPtr& storage, + DataNode const& data_node, + string const& name) const { ElementPtr const& x(getItem(data_node, name)); if (x) { storage->set(name, x); @@ -39,10 +39,10 @@ TranslatorBasic::checkAndGetLeaf(ElementPtr& storage, } void -TranslatorBasic::checkAndGetDivergingLeaf(ElementPtr& storage, - DataNode const& data_node, - string const& name, - string const& yang_name) const { +Translator::checkAndGetDivergingLeaf(ElementPtr& storage, + DataNode const& data_node, + string const& name, + string const& yang_name) const { ElementPtr const& x(getItem(data_node, yang_name)); if (x) { storage->set(name, x); @@ -50,9 +50,9 @@ TranslatorBasic::checkAndGetDivergingLeaf(ElementPtr& storage, } void -TranslatorBasic::checkAndGetAndJsonifyLeaf(ElementPtr& storage, - DataNode const& data_node, - string const& name) const { +Translator::checkAndGetAndJsonifyLeaf(ElementPtr& storage, + DataNode const& data_node, + string const& name) const { ElementPtr const& x(getItem(data_node, name)); if (x) { storage->set(name, Element::fromJSON(x->stringValue())); @@ -60,9 +60,9 @@ TranslatorBasic::checkAndGetAndJsonifyLeaf(ElementPtr& storage, } void -TranslatorBasic::checkAndJsonifyAndSetLeaf(ConstElementPtr const& from, - string const& xpath, - string const& name) { +Translator::checkAndJsonifyAndSetLeaf(ConstElementPtr const& from, + string const& xpath, + string const& name) { ConstElementPtr const& x(from->get(name)); if (x) { ElementPtr const& json(Element::create(x->str())); @@ -70,31 +70,31 @@ TranslatorBasic::checkAndJsonifyAndSetLeaf(ConstElementPtr const& from, } } -void TranslatorBasic::checkAndSetLeaf(ConstElementPtr const& from, - string const& xpath, - string const& name, - LeafBaseType const type) { +void Translator::checkAndSetLeaf(ConstElementPtr const& from, + string const& xpath, + string const& name, + LeafBaseType const type) { ConstElementPtr const& x(from->get(name)); if (x) { setItem(xpath + "/" + name, x, type); } } -void TranslatorBasic::checkAndSetDivergingLeaf(ConstElementPtr const& from, - string const& xpath, - string const& name, - string const& yang_name, - LeafBaseType const type) { +void Translator::checkAndSetDivergingLeaf(ConstElementPtr const& from, + string const& xpath, + string const& name, + string const& yang_name, + LeafBaseType const type) { ConstElementPtr const& x(from->get(name)); if (x) { setItem(xpath + "/" + yang_name, x, type); } } -void TranslatorBasic::checkAndSetLeafList(ConstElementPtr const& from, - string const& xpath, - string const& name, - LeafBaseType const type) { +void Translator::checkAndSetLeafList(ConstElementPtr const& from, + string const& xpath, + string const& name, + LeafBaseType const type) { ConstElementPtr const& leaf_list(from->get(name)); if (leaf_list && !leaf_list->empty()) { for (ElementPtr const& leaf : leaf_list->listValue()) { @@ -103,8 +103,8 @@ void TranslatorBasic::checkAndSetLeafList(ConstElementPtr const& from, } } -void TranslatorBasic::checkAndSetUserContext(ConstElementPtr const& from, - string const& xpath) { +void Translator::checkAndSetUserContext(ConstElementPtr const& from, + string const& xpath) { ConstElementPtr const& user_context(Adaptor::getContext(from)); if (user_context) { setItem(xpath + "/user-context", Element::create(user_context->str()), @@ -113,7 +113,7 @@ void TranslatorBasic::checkAndSetUserContext(ConstElementPtr const& from, } string -TranslatorBasic::decode64(string const& input) { +Translator::decode64(string const& input) { vector binary; decodeBase64(input, binary); string result; @@ -123,7 +123,7 @@ TranslatorBasic::decode64(string const& input) { } void -TranslatorBasic::deleteItem(string const& xpath) { +Translator::deleteItem(string const& xpath) { /// @todo: Remove this if convenient. It is not strictly required and only done to detect /// missing schema nodes and throw an exception to keep old behavior. try { @@ -148,7 +148,7 @@ TranslatorBasic::deleteItem(string const& xpath) { string -TranslatorBasic::encode64(string const& input) { +Translator::encode64(string const& input) { vector binary; binary.resize(input.size()); memmove(&binary[0], input.c_str(), binary.size()); @@ -156,7 +156,7 @@ TranslatorBasic::encode64(string const& input) { } DataNode -TranslatorBasic::findXPath(string const& xpath) { +Translator::findXPath(string const& xpath) { optional const& data_node(getData(xpath)); if (!data_node) { isc_throw(NetconfError, "no data"); @@ -169,7 +169,7 @@ TranslatorBasic::findXPath(string const& xpath) { } optional -TranslatorBasic::getData(string const& xpath) const { +Translator::getData(string const& xpath) const { /// @todo: Remove this if convenient. It is not strictly required and only done to detect /// missing schema nodes and throw an exception to keep old behavior. try { @@ -192,7 +192,8 @@ TranslatorBasic::getData(string const& xpath) const { } ElementPtr -TranslatorBasic::getItem(DataNode const& data_node, string const& xpath) const { +Translator::getItem(DataNode const& data_node, + string const& xpath) const { try { Set const& nodes(data_node.findXPath(xpath)); if (nodes.empty()) { @@ -227,7 +228,7 @@ TranslatorBasic::getItem(DataNode const& data_node, string const& xpath) const { } ElementPtr -TranslatorBasic::getItemFromAbsoluteXpath(string const& xpath) const { +Translator::getItemFromAbsoluteXpath(string const& xpath) const { optional const& data_node(getData(xpath)); if (!data_node) { /// @todo: @@ -238,9 +239,9 @@ TranslatorBasic::getItemFromAbsoluteXpath(string const& xpath) const { } void -TranslatorBasic::getMandatoryLeaf(ElementPtr& storage, - DataNode const& data_node, - string const& name) const { +Translator::getMandatoryLeaf(ElementPtr& storage, + DataNode const& data_node, + string const& name) const { ElementPtr const& x(getItem(data_node, name)); if (!x) { isc_throw(MissingNode, name); @@ -250,10 +251,10 @@ TranslatorBasic::getMandatoryLeaf(ElementPtr& storage, void -TranslatorBasic::getMandatoryDivergingLeaf(ElementPtr& storage, - DataNode const& data_node, - string const& name, - string const& yang_name) const { +Translator::getMandatoryDivergingLeaf(ElementPtr& storage, + DataNode const& data_node, + string const& name, + string const& yang_name) const { ElementPtr const& x(getItem(data_node, yang_name)); if (!x) { isc_throw(MissingNode, yang_name); @@ -262,7 +263,7 @@ TranslatorBasic::getMandatoryDivergingLeaf(ElementPtr& storage, } void -TranslatorBasic::setItem(const string& xpath, ConstElementPtr elem, +Translator::setItem(const string& xpath, ConstElementPtr elem, LeafBaseType type) { optional const value(translateToYang(elem, type)); try { @@ -275,10 +276,10 @@ TranslatorBasic::setItem(const string& xpath, ConstElementPtr elem, } void -TranslatorBasic::setMandatoryLeaf(ConstElementPtr const& from, - string const& xpath, - string const& name, - LeafBaseType const type) { +Translator::setMandatoryLeaf(ConstElementPtr const& from, + string const& xpath, + string const& name, + LeafBaseType const type) { ConstElementPtr const& x(from->get(name)); if (!x) { isc_throw(MissingNode, "xpath: " << xpath << ", name: " << name); @@ -287,11 +288,11 @@ TranslatorBasic::setMandatoryLeaf(ConstElementPtr const& from, } void -TranslatorBasic::setMandatoryDivergingLeaf(ConstElementPtr const& from, - string const& xpath, - string const& name, - string const& yang_name, - LeafBaseType const type) { +Translator::setMandatoryDivergingLeaf(ConstElementPtr const& from, + string const& xpath, + string const& name, + string const& yang_name, + LeafBaseType const type) { ConstElementPtr const& x(from->get(name)); if (!x) { isc_throw(MissingNode, "xpath: " << xpath << ", name: " << name); @@ -300,7 +301,7 @@ TranslatorBasic::setMandatoryDivergingLeaf(ConstElementPtr const& from, } ElementPtr -TranslatorBasic::translateFromYang(optional data_node) { +Translator::translateFromYang(optional data_node) { NodeType const node_type(data_node->schema().nodeType()); if (node_type == NodeType::Leaf || node_type == NodeType::Leaflist) { DataNodeTerm const& leaf(data_node->asTerm()); @@ -322,8 +323,8 @@ TranslatorBasic::translateFromYang(optional data_node) { } optional -TranslatorBasic::translateToYang(ConstElementPtr const& element, - LeafBaseType const type) { +Translator::translateToYang(ConstElementPtr const& element, + LeafBaseType const type) { if (!element) { // A null ElementPtr is how we signal that this item requires no value. // Useful when setting YANG lists which is the only way to set their @@ -331,10 +332,10 @@ TranslatorBasic::translateToYang(ConstElementPtr const& element, return nullopt; } else if (element->getType() == Element::map) { /// @todo: implement - isc_throw(NotImplemented, "TranslatorBasic::value(): map element"); + isc_throw(NotImplemented, "Translator::value(): map element"); } else if (element->getType() == Element::list) { /// @todo: implement - isc_throw(NotImplemented, "TranslatorBasic::value(): list element"); + isc_throw(NotImplemented, "Translator::value(): list element"); } if (type == LeafBaseType::Enum || type == LeafBaseType::String || diff --git a/src/lib/yang/translator.h b/src/lib/yang/translator.h index 0dbdc01705..6576d64e12 100644 --- a/src/lib/yang/translator.h +++ b/src/lib/yang/translator.h @@ -17,16 +17,16 @@ namespace isc { namespace yang { /// @brief Between YANG and JSON translator class for basic values. -class TranslatorBasic { +class Translator { public: /// @brief Constructor. /// /// @param session Sysrepo session. /// @param model Model name (used and shared by derived classes). - TranslatorBasic(sysrepo::Session session, const std::string& model); + Translator(sysrepo::Session session, const std::string& model); /// @brief Destructor. - virtual ~TranslatorBasic() = default; + virtual ~Translator() = default; /// @brief Retrieves a child YANG data node identified by name from the /// given parent YANG container node and stores it in the specified storage. @@ -337,7 +337,7 @@ protected: /// @brief The model. std::string model_; -}; // TranslatorBasic +}; // Translator } // namespace yang } // namespace isc diff --git a/src/lib/yang/translator_class.cc b/src/lib/yang/translator_class.cc index bf774a510a..18e56b6ed9 100644 --- a/src/lib/yang/translator_class.cc +++ b/src/lib/yang/translator_class.cc @@ -20,7 +20,7 @@ namespace isc { namespace yang { TranslatorClass::TranslatorClass(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model), TranslatorOptionDef(session, model), @@ -142,7 +142,7 @@ TranslatorClass::setClassKea(string const& xpath, ConstElementPtr elem) { } TranslatorClasses::TranslatorClasses(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model), TranslatorOptionDef(session, model), diff --git a/src/lib/yang/translator_config.cc b/src/lib/yang/translator_config.cc index be849fc507..a74d5eb54e 100644 --- a/src/lib/yang/translator_config.cc +++ b/src/lib/yang/translator_config.cc @@ -21,7 +21,7 @@ namespace isc { namespace yang { TranslatorConfig::TranslatorConfig(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorControlSocket(session, model), TranslatorDatabase(session, model), TranslatorDatabases(session, model), diff --git a/src/lib/yang/translator_control_socket.cc b/src/lib/yang/translator_control_socket.cc index d9cc3c4b3b..2f1d3f1bea 100644 --- a/src/lib/yang/translator_control_socket.cc +++ b/src/lib/yang/translator_control_socket.cc @@ -21,7 +21,7 @@ namespace yang { TranslatorControlSocket::TranslatorControlSocket(Session session, const string& model) - : TranslatorBasic(session, model) { + : Translator(session, model) { } ElementPtr diff --git a/src/lib/yang/translator_control_socket.h b/src/lib/yang/translator_control_socket.h index 39aabc3f71..5b591c110b 100644 --- a/src/lib/yang/translator_control_socket.h +++ b/src/lib/yang/translator_control_socket.h @@ -65,7 +65,7 @@ namespace yang { /// - kea-dhcp6-server /// - kea-dhcp-ddns /// - kea-ctrl-agent -class TranslatorControlSocket : virtual public TranslatorBasic { +class TranslatorControlSocket : virtual public Translator { public: /// @brief Constructor. /// diff --git a/src/lib/yang/translator_database.cc b/src/lib/yang/translator_database.cc index 74f4b8c771..f3945497b1 100644 --- a/src/lib/yang/translator_database.cc +++ b/src/lib/yang/translator_database.cc @@ -20,7 +20,7 @@ namespace isc { namespace yang { TranslatorDatabase::TranslatorDatabase(Session session, const string& model) - : TranslatorBasic(session, model) { + : Translator(session, model) { } ElementPtr @@ -131,7 +131,7 @@ TranslatorDatabase::setDatabaseKea(string const& xpath, TranslatorDatabases::TranslatorDatabases(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorDatabase(session, model) { } diff --git a/src/lib/yang/translator_database.h b/src/lib/yang/translator_database.h index 0657a34e79..3e890f891e 100644 --- a/src/lib/yang/translator_database.h +++ b/src/lib/yang/translator_database.h @@ -101,7 +101,7 @@ namespace yang { /// Supports the following models: /// - kea-dhcp4-server /// - kea-dhcp6-server -class TranslatorDatabase : virtual public TranslatorBasic { +class TranslatorDatabase : virtual public Translator { public: /// @brief Constructor. /// diff --git a/src/lib/yang/translator_host.cc b/src/lib/yang/translator_host.cc index 522e3ea480..9292ccd442 100644 --- a/src/lib/yang/translator_host.cc +++ b/src/lib/yang/translator_host.cc @@ -20,7 +20,7 @@ namespace isc { namespace yang { TranslatorHost::TranslatorHost(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model) { } @@ -128,7 +128,7 @@ TranslatorHost::setHostKea(string const& xpath, ConstElementPtr elem) { } TranslatorHosts::TranslatorHosts(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model), TranslatorHost(session, model) { diff --git a/src/lib/yang/translator_logger.cc b/src/lib/yang/translator_logger.cc index 9d04e5768c..74b0114991 100644 --- a/src/lib/yang/translator_logger.cc +++ b/src/lib/yang/translator_logger.cc @@ -20,7 +20,7 @@ namespace isc { namespace yang { TranslatorLogger::TranslatorLogger(Session session, const string& model) - : TranslatorBasic(session, model) { + : Translator(session, model) { } ElementPtr @@ -139,7 +139,7 @@ TranslatorLogger::setOutputOptions(string const& xpath, ConstElementPtr elem) { } TranslatorLoggers::TranslatorLoggers(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorLogger(session, model) { } diff --git a/src/lib/yang/translator_logger.h b/src/lib/yang/translator_logger.h index af0e5f7199..7629fab638 100644 --- a/src/lib/yang/translator_logger.h +++ b/src/lib/yang/translator_logger.h @@ -90,7 +90,7 @@ namespace yang { /// - kea-dhcp6-server /// - kea-dhcp-ddns /// - kea-ctrl-agent -class TranslatorLogger : virtual public TranslatorBasic { +class TranslatorLogger : virtual public Translator { public: /// @brief Constructor. /// diff --git a/src/lib/yang/translator_option_data.cc b/src/lib/yang/translator_option_data.cc index 47e836f475..34e7fd26bb 100644 --- a/src/lib/yang/translator_option_data.cc +++ b/src/lib/yang/translator_option_data.cc @@ -21,7 +21,7 @@ namespace yang { TranslatorOptionData::TranslatorOptionData(Session session, const string& model) - : TranslatorBasic(session, model) { + : Translator(session, model) { } ElementPtr @@ -100,7 +100,7 @@ TranslatorOptionData::setOptionDataKea(string const& xpath, TranslatorOptionDataList::TranslatorOptionDataList(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model) { } diff --git a/src/lib/yang/translator_option_data.h b/src/lib/yang/translator_option_data.h index ace9a36770..2bdfd7f1d1 100644 --- a/src/lib/yang/translator_option_data.h +++ b/src/lib/yang/translator_option_data.h @@ -72,7 +72,7 @@ namespace yang { /// YANG and JSON. /// /// Currently supports on kea-dhcp[46]-server, not yet ietf-dhcpv6-server. -class TranslatorOptionData : virtual public TranslatorBasic { +class TranslatorOptionData : virtual public Translator { public: /// @brief Constructor. /// diff --git a/src/lib/yang/translator_option_def.cc b/src/lib/yang/translator_option_def.cc index b9ab01ea0a..f354a6812a 100644 --- a/src/lib/yang/translator_option_def.cc +++ b/src/lib/yang/translator_option_def.cc @@ -21,7 +21,7 @@ namespace yang { TranslatorOptionDef::TranslatorOptionDef(Session session, const string& model) - : TranslatorBasic(session, model) { + : Translator(session, model) { } ElementPtr @@ -102,7 +102,7 @@ TranslatorOptionDef::setOptionDefKea(string const& xpath, TranslatorOptionDefList::TranslatorOptionDefList(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionDef(session, model) { } diff --git a/src/lib/yang/translator_option_def.h b/src/lib/yang/translator_option_def.h index 1a32b9e23d..a1caa11bd4 100644 --- a/src/lib/yang/translator_option_def.h +++ b/src/lib/yang/translator_option_def.h @@ -76,7 +76,7 @@ namespace yang { /// /// Currently supports kea-dhcp[46]-server models. /// @todo: Support for ietf-dhcpv6-server model. -class TranslatorOptionDef : virtual public TranslatorBasic { +class TranslatorOptionDef : virtual public Translator { public: /// @brief Constructor. /// diff --git a/src/lib/yang/translator_pd_pool.cc b/src/lib/yang/translator_pd_pool.cc index efc4fd15bf..92bc0e6081 100644 --- a/src/lib/yang/translator_pd_pool.cc +++ b/src/lib/yang/translator_pd_pool.cc @@ -22,7 +22,7 @@ namespace isc { namespace yang { TranslatorPdPool::TranslatorPdPool(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model) { } @@ -234,7 +234,7 @@ TranslatorPdPool::setPdPoolKea(string const& xpath, ConstElementPtr elem) { } TranslatorPdPools::TranslatorPdPools(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model), TranslatorPdPool(session, model) { diff --git a/src/lib/yang/translator_pool.cc b/src/lib/yang/translator_pool.cc index 5db1effd72..24940c73d6 100644 --- a/src/lib/yang/translator_pool.cc +++ b/src/lib/yang/translator_pool.cc @@ -25,7 +25,7 @@ namespace isc { namespace yang { TranslatorPool::TranslatorPool(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model) { } @@ -225,7 +225,7 @@ TranslatorPool::getAddresses(const string& prefix, } TranslatorPools::TranslatorPools(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model), TranslatorPool(session, model) { diff --git a/src/lib/yang/translator_shared_network.cc b/src/lib/yang/translator_shared_network.cc index dccc41b9cc..5c2de97663 100644 --- a/src/lib/yang/translator_shared_network.cc +++ b/src/lib/yang/translator_shared_network.cc @@ -21,7 +21,7 @@ namespace yang { TranslatorSharedNetwork::TranslatorSharedNetwork(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model), TranslatorPool(session, model), @@ -232,7 +232,7 @@ TranslatorSharedNetwork::setSharedNetworkKea(string const& xpath, TranslatorSharedNetworks::TranslatorSharedNetworks(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model), TranslatorPool(session, model), diff --git a/src/lib/yang/translator_subnet.cc b/src/lib/yang/translator_subnet.cc index ed2421338b..6ac373d810 100644 --- a/src/lib/yang/translator_subnet.cc +++ b/src/lib/yang/translator_subnet.cc @@ -21,7 +21,7 @@ namespace isc { namespace yang { TranslatorSubnet::TranslatorSubnet(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model), TranslatorPool(session, model), @@ -333,7 +333,7 @@ TranslatorSubnet::setSubnetKea(string const& xpath, ConstElementPtr elem) { } TranslatorSubnets::TranslatorSubnets(Session session, const string& model) - : TranslatorBasic(session, model), + : Translator(session, model), TranslatorOptionData(session, model), TranslatorOptionDataList(session, model), TranslatorPool(session, model), diff --git a/src/lib/yang/yang.dox b/src/lib/yang/yang.dox index 592942c12e..9978db6a5e 100644 --- a/src/lib/yang/yang.dox +++ b/src/lib/yang/yang.dox @@ -16,7 +16,7 @@ data between YANG and JSON that is understandable by Kea. An essential concept is the idea of translator. It is a primitive that is able to convert certain data structure between YANG and JSON. It is envisaged that more complex translators will use other translators to handle more -complex data structures. For details, see @ref isc::yang::TranslatorBasic. +complex data structures. For details, see @ref isc::yang::Translator. It is also envisioned that translators could do the translation automatically by relying on capabilities of iterating through data, retrieving data type information and value information from nodes through the libyang and sysrepo @@ -43,24 +43,24 @@ All translators take a Session pointer (a structure provided by Sysrepo that is responsible for maintaining a connection) in constructors and derive from the basic / base class and recursively from translators for embedded parts. -@c isc::yang::TranslatorBasic provides some methods: - - @c isc::yang::TranslatorBasic::checkAndGetLeaf() is a convenience wrapper - over @c isc::yang::TranslatorBasic::getItem(). - - @c isc::yang::TranslatorBasic::checkAndSetLeaf() is a convenience wrapper - over @c isc::yang::TranslatorBasic::setItem(). - - @c isc::yang::TranslatorBasic::deleteItem() deletes the data node found at +@c isc::yang::Translator provides some methods: + - @c isc::yang::Translator::checkAndGetLeaf() is a convenience wrapper + over @c isc::yang::Translator::getItem(). + - @c isc::yang::Translator::checkAndSetLeaf() is a convenience wrapper + over @c isc::yang::Translator::setItem(). + - @c isc::yang::Translator::deleteItem() deletes the data node found at given xpth. - - @c isc::yang::TranslatorBasic::forAll() iterates over the node found at + - @c isc::yang::Translator::forAll() iterates over the node found at given xpath and all its descendants and calls the given function. - - @c isc::yang::TranslatorBasic::getItem() retrieves and translates a leaf + - @c isc::yang::Translator::getItem() retrieves and translates a leaf from YANG to JSON. - - @c isc::yang::TranslatorBasic::getList() retrieves a list from Sysrepo and + - @c isc::yang::Translator::getList() retrieves a list from Sysrepo and translates it form YANG to JSON. - - @c isc::yang::TranslatorBasic::setItem() translates a leaf from JSON to + - @c isc::yang::Translator::setItem() translates a leaf from JSON to YANG and sets it in Sysrepo. - - @c isc::yang::TranslatorBasic::translateFromYang(optional, string) translates a YANG + - @c isc::yang::Translator::translateFromYang(optional, string) translates a YANG leaf to a JSON node. - - @c isc::yang::TranslatorBasic::translateToYang(ConstElementPtr, LeafBaseType) + - @c isc::yang::Translator::translateToYang(ConstElementPtr, LeafBaseType) translates a JSON leaf to a string. @section yangTranslatorPool Pool translator @@ -78,7 +78,7 @@ Note pools show two shortcomings in IETF modules: - prefix and start - end forms of pool ranges are both mandatory. (reported to authors' so should be fixed in the next version). -All structure translators depend on @c isc::yang::TranslatorBasic and +All structure translators depend on @c isc::yang::Translator and some of them depend on other structures, for instance @c isc::yang::TranslatorPool depends on @c isc::yang::TranslatorOptionDataList which itself, as all list translators,