[svn] commit: r915 - in /trunk/src/lib/config/cpp: Makefile.am ccsession.cc ccsession.h config_data.cc config_data.h config_data_unittests.cc module_spec.cc module_spec.h module_spec_unittests.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Feb 22 22:12:31 UTC 2010


Author: jelte
Date: Mon Feb 22 22:12:31 2010
New Revision: 915

Log:
added isc::config::ConfigData class for easier client-side usage of configuration values (not completely done yet)

Added:
    trunk/src/lib/config/cpp/config_data.cc
    trunk/src/lib/config/cpp/config_data.h
    trunk/src/lib/config/cpp/config_data_unittests.cc
Modified:
    trunk/src/lib/config/cpp/Makefile.am
    trunk/src/lib/config/cpp/ccsession.cc
    trunk/src/lib/config/cpp/ccsession.h
    trunk/src/lib/config/cpp/module_spec.cc
    trunk/src/lib/config/cpp/module_spec.h
    trunk/src/lib/config/cpp/module_spec_unittests.cc

Modified: trunk/src/lib/config/cpp/Makefile.am
==============================================================================
--- trunk/src/lib/config/cpp/Makefile.am (original)
+++ trunk/src/lib/config/cpp/Makefile.am Mon Feb 22 22:12:31 2010
@@ -1,14 +1,14 @@
 AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/ext -Wall -Werror
 
 lib_LIBRARIES = libcfgclient.a
-libcfgclient_a_SOURCES = module_spec.h module_spec.cc ccsession.cc ccsession.h
+libcfgclient_a_SOURCES = config_data.h config_data.cc module_spec.h module_spec.cc ccsession.cc ccsession.h
 
 CLEANFILES = *.gcno *.gcda
 
 TESTS =
 if HAVE_GTEST
 TESTS += run_unittests
-run_unittests_SOURCES = module_spec_unittests.cc run_unittests.cc
+run_unittests_SOURCES = module_spec_unittests.cc config_data_unittests.cc run_unittests.cc
 run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
 run_unittests_LDADD = libcfgclient.a $(GTEST_LDADD)

Modified: trunk/src/lib/config/cpp/ccsession.cc
==============================================================================
--- trunk/src/lib/config/cpp/ccsession.cc (original)
+++ trunk/src/lib/config/cpp/ccsession.cc Mon Feb 22 22:12:31 2010
@@ -135,7 +135,7 @@
     read_module_specification(spec_file_name);
     sleep(1);
 
-    module_name_ = module_specification_.getFullSpec()->get("module_spec")->get("module_name")->stringValue();
+    module_name_ = module_specification_.getFullSpec()->get("module_name")->stringValue();
     config_handler_ = config_handler;
     command_handler_ = command_handler;
 
@@ -150,7 +150,9 @@
     //session_.subscribe("Boss", "*");
     //session_.subscribe("statistics", "*");
     // send the data specification
-    session_.group_sendmsg(module_specification_.getFullSpec(), "ConfigManager");
+    ElementPtr spec_msg = Element::createFromString("{}");
+    spec_msg->set("module_spec", module_specification_.getFullSpec());
+    session_.group_sendmsg(spec_msg, "ConfigManager");
     session_.group_recvmsg(env, answer, false);
     
     // get any stored configuration from the manager

Modified: trunk/src/lib/config/cpp/ccsession.h
==============================================================================
--- trunk/src/lib/config/cpp/ccsession.h (original)
+++ trunk/src/lib/config/cpp/ccsession.h Mon Feb 22 22:12:31 2010
@@ -37,7 +37,11 @@
         isc::Exception(file, line, what) {}
 };
 
-
+///
+/// \brief This modules keeps a connection to the command channel,
+/// holds configuration information, and handles messages from
+/// the command channel
+///
 class ModuleCCSession {
 public:
     /**

Modified: trunk/src/lib/config/cpp/module_spec.cc
==============================================================================
--- trunk/src/lib/config/cpp/module_spec.cc (original)
+++ trunk/src/lib/config/cpp/module_spec.cc Mon Feb 22 22:12:31 2010
@@ -160,11 +160,7 @@
 static void
 check_module_specification(const ElementPtr& def)
 {
-    if (!def->contains("module_spec")) {
-        throw ModuleSpecError("Data specification does not contain module_spec element");
-    } else {
-        check_data_specification(def->get("module_spec"));
-    }
+    check_data_specification(def);
 }
 
 //
@@ -183,7 +179,7 @@
 }
 
 const ElementPtr
-ModuleSpec::getCommandsSpec()
+ModuleSpec::getCommandsSpec() const
 {
     if (module_specification->contains("commands")) {
         return module_specification->get("commands");
@@ -193,7 +189,7 @@
 }
 
 const ElementPtr
-ModuleSpec::getConfigSpec()
+ModuleSpec::getConfigSpec() const
 {
     if (module_specification->contains("config_data")) {
         return module_specification->get("config_data");
@@ -203,7 +199,7 @@
 }
 
 const std::string
-ModuleSpec::getModuleName()
+ModuleSpec::getModuleName() const
 {
     return module_specification->get("module_name")->stringValue();
 }
@@ -211,14 +207,14 @@
 bool
 ModuleSpec::validate_config(const ElementPtr data, const bool full)
 {
-    ElementPtr spec = module_specification->find("module_spec/config_data");
+    ElementPtr spec = module_specification->find("config_data");
     return validate_spec_list(spec, data, full, ElementPtr());
 }
 
 bool
 ModuleSpec::validate_config(const ElementPtr data, const bool full, ElementPtr errors)
 {
-    ElementPtr spec = module_specification->find("module_spec/config_data");
+    ElementPtr spec = module_specification->find("config_data");
     return validate_spec_list(spec, data, full, errors);
 }
 
@@ -236,14 +232,22 @@
     }
 
     ElementPtr module_spec_element = Element::createFromString(file, file_name);
-    return ModuleSpec(module_spec_element, check);
+    if (module_spec_element->contains("module_spec")) {
+        return ModuleSpec(module_spec_element->get("module_spec"), check);
+    } else {
+        throw ModuleSpecError("No module_spec in specification");
+    }
 }
 
 ModuleSpec
 moduleSpecFromFile(std::ifstream& in, const bool check)
                    throw(ParseError, ModuleSpecError) {
     ElementPtr module_spec_element = Element::createFromString(in);
-    return ModuleSpec(module_spec_element, check);
+    if (module_spec_element->contains("module_spec")) {
+        return ModuleSpec(module_spec_element->get("module_spec"), check);
+    } else {
+        throw ModuleSpecError("No module_spec in specification");
+    }
 }
 
 

Modified: trunk/src/lib/config/cpp/module_spec.h
==============================================================================
--- trunk/src/lib/config/cpp/module_spec.h (original)
+++ trunk/src/lib/config/cpp/module_spec.h Mon Feb 22 22:12:31 2010
@@ -62,20 +62,20 @@
         /// ElementPtr, returns an empty ElementPtr if there is none
         /// \return ElementPtr Shared pointer to the commands
         ///                    part of the specification
-        const ElementPtr getCommandsSpec();
+        const ElementPtr getCommandsSpec() const;
 
         /// Returns the configuration part of the specification as an
         /// ElementPtr
         /// \return ElementPtr Shared pointer to the configuration
         ///                    part of the specification
-        const ElementPtr getConfigSpec();
+        const ElementPtr getConfigSpec() const;
 
         /// Returns the full module specification as an ElementPtr
         /// \return ElementPtr Shared pointer to the specification
-        const ElementPtr getFullSpec() { return module_specification; };
+        const ElementPtr getFullSpec() const { return module_specification; };
 
         /// Returns the module name as specified by the specification
-        const std::string getModuleName();
+        const std::string getModuleName() const;
         
         // returns true if the given element conforms to this data
         // configuration specification

Modified: trunk/src/lib/config/cpp/module_spec_unittests.cc
==============================================================================
--- trunk/src/lib/config/cpp/module_spec_unittests.cc (original)
+++ trunk/src/lib/config/cpp/module_spec_unittests.cc Mon Feb 22 22:12:31 2010
@@ -48,12 +48,10 @@
     // Tests whether we can open specfiles and if we get the
     // right parse errors
     ModuleSpec dd = moduleSpecFromFile(specfile("spec1.spec"));
-    EXPECT_EQ(dd.getFullSpec()->get("module_spec")
-                                ->get("module_name")
-                                ->stringValue(), "Spec1");
+    EXPECT_EQ(dd.getFullSpec()->get("module_name")
+                              ->stringValue(), "Spec1");
     dd = moduleSpecFromFile(specfile("spec2.spec"));
-    EXPECT_EQ(dd.getFullSpec()->get("module_spec")
-                                ->get("config_data")->size(), 6);
+    EXPECT_EQ(dd.getFullSpec()->get("config_data")->size(), 6);
     module_spec_error("doesnotexist",
                    "Error opening ",
                    specfile("doesnotexist"),
@@ -62,9 +60,8 @@
     std::ifstream file;
     file.open(specfile("spec1.spec").c_str());
     dd = moduleSpecFromFile(file);
-    EXPECT_EQ(dd.getFullSpec()->get("module_spec")
-                                ->get("module_name")
-                                ->stringValue(), "Spec1");
+    EXPECT_EQ(dd.getFullSpec()->get("module_name")
+                              ->stringValue(), "Spec1");
 }
 
 TEST(ModuleSpec, SpecfileItems) {
@@ -97,7 +94,7 @@
     module_spec_error("spec7.spec",
                    "module_name missing in {}");
     module_spec_error("spec8.spec",
-                   "Data specification does not contain module_spec element");
+                   "No module_spec in specification");
     module_spec_error("spec16.spec",
                    "config_data is not a list of elements");
     module_spec_error("spec21.spec",




More information about the bind10-changes mailing list