Browse Source

rename DataDefinition[Error] to ModuleSpec[Error]

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/jelte-configuration@868 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 15 years ago
parent
commit
d66ddb0553

+ 4 - 4
src/lib/config/cpp/ccsession.cc

@@ -45,9 +45,9 @@ using namespace std;
 
 
 using isc::data::Element;
 using isc::data::Element;
 using isc::data::ElementPtr;
 using isc::data::ElementPtr;
-using isc::data::DataDefinition;
+using isc::data::ModuleSpec;
 using isc::data::ParseError;
 using isc::data::ParseError;
-using isc::data::DataDefinitionError;
+using isc::data::ModuleSpecError;
 
 
 void
 void
 CommandSession::read_data_definition(const std::string& filename) {
 CommandSession::read_data_definition(const std::string& filename) {
@@ -61,11 +61,11 @@ CommandSession::read_data_definition(const std::string& filename) {
     }
     }
 
 
     try {
     try {
-        data_definition_ = DataDefinition(file, true);
+        data_definition_ = ModuleSpec(file, true);
     } catch (ParseError pe) {
     } catch (ParseError pe) {
         cout << "Error parsing definition file: " << pe.what() << endl;
         cout << "Error parsing definition file: " << pe.what() << endl;
         exit(1);
         exit(1);
-    } catch (DataDefinitionError dde) {
+    } catch (ModuleSpecError dde) {
         cout << "Error reading definition file: " << dde.what() << endl;
         cout << "Error reading definition file: " << dde.what() << endl;
         exit(1);
         exit(1);
     }
     }

+ 1 - 1
src/lib/config/cpp/ccsession.h

@@ -75,7 +75,7 @@ private:
     
     
     std::string module_name_;
     std::string module_name_;
     isc::cc::Session session_;
     isc::cc::Session session_;
-    isc::data::DataDefinition data_definition_;
+    isc::data::ModuleSpec data_definition_;
     isc::data::ElementPtr config_;
     isc::data::ElementPtr config_;
 
 
     isc::data::ElementPtr(*config_handler_)(isc::data::ElementPtr new_config);
     isc::data::ElementPtr(*config_handler_)(isc::data::ElementPtr new_config);

+ 31 - 17
src/lib/config/cpp/data_def.cc

@@ -1,3 +1,17 @@
+// Copyright (C) 2010  Internet Systems Consortium.
+//
+// Permission to use, copy, modify, and distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
+// DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+// INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+// NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 
 #include "data_def.h"
 #include "data_def.h"
 
 
@@ -8,7 +22,7 @@
 
 
 #include <boost/foreach.hpp>
 #include <boost/foreach.hpp>
 
 
-// todo: add more context to thrown DataDefinitionErrors?
+// todo: add more context to thrown ModuleSpecErrors?
 
 
 using namespace isc::data;
 using namespace isc::data;
 
 
@@ -51,7 +65,7 @@ getType_value(const std::string& type_name) {
     } else if (type_name == "any") {
     } else if (type_name == "any") {
         return Element::any;
         return Element::any;
     } else {
     } else {
-        throw DataDefinitionError(type_name + " is not a valid type name");
+        throw ModuleSpecError(type_name + " is not a valid type name");
     }
     }
 }
 }
 
 
@@ -62,13 +76,13 @@ check_leaf_item(const ElementPtr& spec, const std::string& name, Element::types
         if (spec->get(name)->getType() == type) {
         if (spec->get(name)->getType() == type) {
             return;
             return;
         } else {
         } else {
-            throw DataDefinitionError(name + " not of type " + getType_string(type));
+            throw ModuleSpecError(name + " not of type " + getType_string(type));
         }
         }
     } else if (mandatory) {
     } else if (mandatory) {
         // todo: want parent item name, and perhaps some info about location
         // todo: want parent item name, and perhaps some info about location
         // in list? or just catch and throw new...
         // in list? or just catch and throw new...
         // or make this part non-throwing and check return value...
         // or make this part non-throwing and check return value...
-        throw DataDefinitionError(name + " missing in " + spec->str());
+        throw ModuleSpecError(name + " missing in " + spec->str());
     }
     }
 }
 }
 
 
@@ -99,7 +113,7 @@ check_config_item(const ElementPtr& spec) {
 static void
 static void
 check_config_item_list(const ElementPtr& spec) {
 check_config_item_list(const ElementPtr& spec) {
     if (spec->getType() != Element::list) {
     if (spec->getType() != Element::list) {
-        throw DataDefinitionError("config_data is not a list of elements");
+        throw ModuleSpecError("config_data is not a list of elements");
     }
     }
     BOOST_FOREACH(ElementPtr item, spec->listValue()) {
     BOOST_FOREACH(ElementPtr item, spec->listValue()) {
         check_config_item(item);
         check_config_item(item);
@@ -116,7 +130,7 @@ check_command(const ElementPtr& spec) {
 static void
 static void
 check_command_list(const ElementPtr& spec) {
 check_command_list(const ElementPtr& spec) {
     if (spec->getType() != Element::list) {
     if (spec->getType() != Element::list) {
-        throw DataDefinitionError("commands is not a list of elements");
+        throw ModuleSpecError("commands is not a list of elements");
     }
     }
     BOOST_FOREACH(ElementPtr item, spec->listValue()) {
     BOOST_FOREACH(ElementPtr item, spec->listValue()) {
         check_command(item);
         check_command(item);
@@ -137,27 +151,27 @@ check_data_specification(const ElementPtr& spec) {
 }
 }
 
 
 // checks whether the given element is a valid data definition
 // checks whether the given element is a valid data definition
-// throws a DataDefinitionError if the specification is bad
+// throws a ModuleSpecError if the specification is bad
 static void
 static void
 check_definition(const ElementPtr& def)
 check_definition(const ElementPtr& def)
 {
 {
     if (!def->contains("module_spec")) {
     if (!def->contains("module_spec")) {
-        throw DataDefinitionError("Data specification does not contain module_spec element");
+        throw ModuleSpecError("Data specification does not contain module_spec element");
     } else {
     } else {
         check_data_specification(def->get("module_spec"));
         check_data_specification(def->get("module_spec"));
     }
     }
 }
 }
 
 
-DataDefinition::DataDefinition(const std::string& file_name,
+ModuleSpec::ModuleSpec(const std::string& file_name,
                                const bool check)
                                const bool check)
-                               throw(ParseError, DataDefinitionError) {
+                               throw(ParseError, ModuleSpecError) {
     std::ifstream file;
     std::ifstream file;
 
 
     file.open(file_name.c_str());
     file.open(file_name.c_str());
     if (!file) {
     if (!file) {
         std::stringstream errs;
         std::stringstream errs;
         errs << "Error opening " << file_name << ": " << strerror(errno);
         errs << "Error opening " << file_name << ": " << strerror(errno);
-        throw DataDefinitionError(errs.str());
+        throw ModuleSpecError(errs.str());
     }
     }
 
 
     definition = Element::createFromString(file, file_name);
     definition = Element::createFromString(file, file_name);
@@ -166,8 +180,8 @@ DataDefinition::DataDefinition(const std::string& file_name,
     }
     }
 }
 }
 
 
-DataDefinition::DataDefinition(std::istream& in, const bool check)
-                               throw(ParseError, DataDefinitionError) {
+ModuleSpec::ModuleSpec(std::istream& in, const bool check)
+                               throw(ParseError, ModuleSpecError) {
     definition = Element::createFromString(in);
     definition = Element::createFromString(in);
     // make sure the whole structure is complete and valid
     // make sure the whole structure is complete and valid
     if (check) {
     if (check) {
@@ -210,7 +224,7 @@ check_type(ElementPtr spec, ElementPtr element)
 }
 }
 
 
 bool
 bool
-DataDefinition::validate_item(const ElementPtr spec, const ElementPtr data) {
+ModuleSpec::validate_item(const ElementPtr spec, const ElementPtr data) {
     if (!check_type(spec, data)) {
     if (!check_type(spec, data)) {
         // we should do some proper error feedback here
         // we should do some proper error feedback here
         // std::cout << "type mismatch; not " << spec->get("item_type") << ": " << data << std::endl;
         // std::cout << "type mismatch; not " << spec->get("item_type") << ": " << data << std::endl;
@@ -240,7 +254,7 @@ DataDefinition::validate_item(const ElementPtr spec, const ElementPtr data) {
 
 
 // spec is a map with item_name etc, data is a map
 // spec is a map with item_name etc, data is a map
 bool
 bool
-DataDefinition::validate_spec(const ElementPtr spec, const ElementPtr data) {
+ModuleSpec::validate_spec(const ElementPtr spec, const ElementPtr data) {
     std::string item_name = spec->get("item_name")->stringValue();
     std::string item_name = spec->get("item_name")->stringValue();
     bool optional = spec->get("item_optional")->boolValue();
     bool optional = spec->get("item_optional")->boolValue();
     ElementPtr data_el;
     ElementPtr data_el;
@@ -260,7 +274,7 @@ DataDefinition::validate_spec(const ElementPtr spec, const ElementPtr data) {
 
 
 // spec is a list of maps, data is a map
 // spec is a list of maps, data is a map
 bool
 bool
-DataDefinition::validate_spec_list(const ElementPtr spec, const ElementPtr data) {
+ModuleSpec::validate_spec_list(const ElementPtr spec, const ElementPtr data) {
     ElementPtr cur_data_el;
     ElementPtr cur_data_el;
     std::string cur_item_name;
     std::string cur_item_name;
     BOOST_FOREACH(ElementPtr cur_spec_el, spec->listValue()) {
     BOOST_FOREACH(ElementPtr cur_spec_el, spec->listValue()) {
@@ -275,7 +289,7 @@ DataDefinition::validate_spec_list(const ElementPtr spec, const ElementPtr data)
 // this function does *not* check if the specification is in correct
 // this function does *not* check if the specification is in correct
 // form, we should do that in the constructor
 // form, we should do that in the constructor
 bool
 bool
-DataDefinition::validate(const ElementPtr data) {
+ModuleSpec::validate(const ElementPtr data) {
     ElementPtr spec = definition->find("module_spec/config_data");
     ElementPtr spec = definition->find("module_spec/config_data");
     return validate_spec_list(spec, data);
     return validate_spec_list(spec, data);
 }
 }

+ 34 - 19
src/lib/config/cpp/data_def.h

@@ -1,5 +1,20 @@
-#ifndef _DATA_DEF_H
-#define _DATA_DEF_H 1
+// Copyright (C) 2010  Internet Systems Consortium.
+//
+// Permission to use, copy, modify, and distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
+// DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+// INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+// NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef _MODULE_SPEC_H
+#define _MODULE_SPEC_H 1
 
 
 #include <cc/data.h>
 #include <cc/data.h>
 
 
@@ -8,22 +23,22 @@
 namespace isc { namespace data {
 namespace isc { namespace data {
 
 
     ///
     ///
-    /// A standard DataDefinition exception that is thrown when a
+    /// A standard ModuleSpec exception that is thrown when a
     /// specification is not in the correct form.
     /// specification is not in the correct form.
     ///
     ///
     /// TODO: use jinmei's exception class as a base and not c_str in
     /// TODO: use jinmei's exception class as a base and not c_str in
     /// what() there
     /// what() there
-    class DataDefinitionError : public std::exception {
+    class ModuleSpecError : public std::exception {
     public:
     public:
-        DataDefinitionError(std::string m = "Data definition is invalid") : msg(m) {}
-        ~DataDefinitionError() throw() {}
+        ModuleSpecError(std::string m = "Data definition is invalid") : msg(m) {}
+        ~ModuleSpecError() throw() {}
         const char* what() const throw() { return msg.c_str(); }
         const char* what() const throw() { return msg.c_str(); }
     private:
     private:
         std::string msg;
         std::string msg;
     };
     };
 
 
     ///
     ///
-    /// The \c DataDefinition class holds a data specification.
+    /// The \c ModuleSpec class holds a data specification.
     /// Each module should have a .spec file containing the specification
     /// Each module should have a .spec file containing the specification
     /// for configuration and commands for that module.
     /// for configuration and commands for that module.
     /// This class holds that specification, and provides a function to
     /// This class holds that specification, and provides a function to
@@ -32,36 +47,36 @@ namespace isc { namespace data {
     ///
     ///
     /// The form of the specification is described in doc/ (TODO)
     /// The form of the specification is described in doc/ (TODO)
     ///
     ///
-    class DataDefinition {
+    class ModuleSpec {
     public:
     public:
-        explicit DataDefinition() {};
-        /// Create a \c DataDefinition instance with the given data as
+        explicit ModuleSpec() {};
+        /// Create a \c ModuleSpec instance with the given data as
         /// the specification
         /// the specification
         /// \param e The Element containing the data specification
         /// \param e The Element containing the data specification
-        explicit DataDefinition(ElementPtr e) : definition(e) {};
+        explicit ModuleSpec(ElementPtr e) : definition(e) {};
 
 
-        /// Creates a \c DataDefinition instance from the contents
+        /// Creates a \c ModuleSpec instance from the contents
         /// of the file given by file_name.
         /// of the file given by file_name.
         /// If check is true, and the definition is not of the correct
         /// If check is true, and the definition is not of the correct
-        /// form, a DataDefinitionError is thrown. If the file could
+        /// form, a ModuleSpecError is thrown. If the file could
         /// not be parse, a ParseError is thrown.
         /// not be parse, a ParseError is thrown.
         /// \param file_name The file to be opened and parsed
         /// \param file_name The file to be opened and parsed
         /// \param check If true, the data definition in the file is
         /// \param check If true, the data definition in the file is
         /// checked to be of the correct form
         /// checked to be of the correct form
-        DataDefinition(const std::string& file_name, const bool check = true)
-                       throw(ParseError, DataDefinitionError);
+        ModuleSpec(const std::string& file_name, const bool check = true)
+                       throw(ParseError, ModuleSpecError);
 
 
         // todo: make check default false, or leave out option completely and always check?
         // todo: make check default false, or leave out option completely and always check?
-        /// Creates a \c DataDefinition instance from the given input
+        /// Creates a \c ModuleSpec instance from the given input
         /// stream that contains the contents of a .spec file.
         /// stream that contains the contents of a .spec file.
         /// If check is true, and the definition is not of
         /// If check is true, and the definition is not of
-        /// the correct form, a DataDefinitionError is thrown. If the
+        /// the correct form, a ModuleSpecError is thrown. If the
         /// file could not be parsed, a ParseError is thrown.
         /// file could not be parsed, a ParseError is thrown.
         /// \param in The std::istream containing the .spec file data
         /// \param in The std::istream containing the .spec file data
         /// \param check If true, the data definition is checked to be
         /// \param check If true, the data definition is checked to be
         /// of the correct form
         /// of the correct form
-        explicit DataDefinition(std::istream& in, const bool check = true)
-                                throw(ParseError, DataDefinitionError);
+        explicit ModuleSpec(std::istream& in, const bool check = true)
+                                throw(ParseError, ModuleSpecError);
 
 
         /// Returns the base \c element of the data definition contained
         /// Returns the base \c element of the data definition contained
         /// by this instance
         /// by this instance

+ 13 - 13
src/lib/config/cpp/data_def_unittests.cc

@@ -34,23 +34,23 @@ data_def_error(const std::string& file,
                const std::string& error2 = "",
                const std::string& error2 = "",
                const std::string& error3 = "")
                const std::string& error3 = "")
 {
 {
-    EXPECT_THROW(DataDefinition(specfile(file)), DataDefinitionError);
+    EXPECT_THROW(ModuleSpec(specfile(file)), ModuleSpecError);
     try {
     try {
-        DataDefinition dd = DataDefinition(specfile(file));
-    } catch (DataDefinitionError dde) {
+        ModuleSpec dd = ModuleSpec(specfile(file));
+    } catch (ModuleSpecError dde) {
         std::string ddew = dde.what();
         std::string ddew = dde.what();
         EXPECT_EQ(error1 + error2 + error3, ddew);
         EXPECT_EQ(error1 + error2 + error3, ddew);
     }
     }
 }
 }
 
 
-TEST(DataDefinition, ReadingSpecfiles) {
+TEST(ModuleSpec, ReadingSpecfiles) {
     // Tests whether we can open specfiles and if we get the
     // Tests whether we can open specfiles and if we get the
     // right parse errors
     // right parse errors
-    DataDefinition dd = DataDefinition(specfile("spec1.spec"));
+    ModuleSpec dd = ModuleSpec(specfile("spec1.spec"));
     EXPECT_EQ(dd.getDefinition()->get("module_spec")
     EXPECT_EQ(dd.getDefinition()->get("module_spec")
                                 ->get("module_name")
                                 ->get("module_name")
                                 ->stringValue(), "Spec1");
                                 ->stringValue(), "Spec1");
-    dd = DataDefinition(specfile("spec2.spec"));
+    dd = ModuleSpec(specfile("spec2.spec"));
     EXPECT_EQ(dd.getDefinition()->get("module_spec")
     EXPECT_EQ(dd.getDefinition()->get("module_spec")
                                 ->get("config_data")->size(), 6);
                                 ->get("config_data")->size(), 6);
     data_def_error("doesnotexist",
     data_def_error("doesnotexist",
@@ -60,13 +60,13 @@ TEST(DataDefinition, ReadingSpecfiles) {
 
 
     std::ifstream file;
     std::ifstream file;
     file.open(specfile("spec1.spec").c_str());
     file.open(specfile("spec1.spec").c_str());
-    dd = DataDefinition(file);
+    dd = ModuleSpec(file);
     EXPECT_EQ(dd.getDefinition()->get("module_spec")
     EXPECT_EQ(dd.getDefinition()->get("module_spec")
                                 ->get("module_name")
                                 ->get("module_name")
                                 ->stringValue(), "Spec1");
                                 ->stringValue(), "Spec1");
 }
 }
 
 
-TEST(DataDefinition, SpecfileItems) {
+TEST(ModuleSpec, SpecfileItems) {
     data_def_error("spec3.spec",
     data_def_error("spec3.spec",
                    "item_name missing in {\"item_default\": 1, \"item_optional\": False, \"item_type\": \"integer\"}");
                    "item_name missing in {\"item_default\": 1, \"item_optional\": False, \"item_type\": \"integer\"}");
     data_def_error("spec4.spec",
     data_def_error("spec4.spec",
@@ -91,7 +91,7 @@ TEST(DataDefinition, SpecfileItems) {
                    "badname is not a valid type name");
                    "badname is not a valid type name");
 }
 }
 
 
-TEST(DataDefinition, SpecfileConfigData)
+TEST(ModuleSpec, SpecfileConfigData)
 {
 {
     data_def_error("spec7.spec",
     data_def_error("spec7.spec",
                    "module_name missing in {}");
                    "module_name missing in {}");
@@ -103,7 +103,7 @@ TEST(DataDefinition, SpecfileConfigData)
                    "commands is not a list of elements");
                    "commands is not a list of elements");
 }
 }
 
 
-TEST(DataDefinition, SpecfileCommands)
+TEST(ModuleSpec, SpecfileCommands)
 {
 {
     data_def_error("spec17.spec",
     data_def_error("spec17.spec",
                    "command_name missing in {\"command_args\": [ {\"item_default\": \"\", \"item_name\": \"message\", \"item_optional\": False, \"item_type\": \"string\"} ], \"command_description\": \"Print the given message to stdout\"}");
                    "command_name missing in {\"command_args\": [ {\"item_default\": \"\", \"item_name\": \"message\", \"item_optional\": False, \"item_type\": \"string\"} ], \"command_description\": \"Print the given message to stdout\"}");
@@ -120,7 +120,7 @@ TEST(DataDefinition, SpecfileCommands)
 }
 }
 
 
 bool
 bool
-data_test(DataDefinition dd, const std::string& data_file_name)
+data_test(ModuleSpec dd, const std::string& data_file_name)
 {
 {
     std::ifstream data_file;
     std::ifstream data_file;
 
 
@@ -131,8 +131,8 @@ data_test(DataDefinition dd, const std::string& data_file_name)
     return dd.validate(data);
     return dd.validate(data);
 }
 }
 
 
-TEST(DataDefinition, DataValidation) {
-    DataDefinition dd = DataDefinition(specfile("spec22.spec"));
+TEST(ModuleSpec, DataValidation) {
+    ModuleSpec dd = ModuleSpec(specfile("spec22.spec"));
 
 
     EXPECT_TRUE(data_test(dd, "data22_1.data"));
     EXPECT_TRUE(data_test(dd, "data22_1.data"));
     EXPECT_FALSE(data_test(dd, "data22_2.data"));
     EXPECT_FALSE(data_test(dd, "data22_2.data"));

+ 1 - 1
src/lib/config/python/isc/config/module_spec.py

@@ -57,7 +57,7 @@ class ModuleSpec:
         """Initializes a ModuleSpec object from the specification in
         """Initializes a ModuleSpec object from the specification in
            the given module_spec (which must be a dict). If check is
            the given module_spec (which must be a dict). If check is
            True, the contents are verified. Raises a ModuleSpec error
            True, the contents are verified. Raises a ModuleSpec error
-           if there is something wrong with the contents of the dict""".
+           if there is something wrong with the contents of the dict"""
         if type(module_spec) != dict:
         if type(module_spec) != dict:
             raise ModuleSpecError("module_spec is of type " + str(type(module_spec)) + ", not dict")
             raise ModuleSpecError("module_spec is of type " + str(type(module_spec)) + ", not dict")
         if check:
         if check: