[svn] commit: r868 - in /branches/jelte-configuration/src/lib/config: cpp/ccsession.cc cpp/ccsession.h cpp/data_def.cc cpp/data_def.h cpp/data_def_unittests.cc python/isc/config/module_spec.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Feb 18 12:20:56 UTC 2010
Author: jelte
Date: Thu Feb 18 12:20:55 2010
New Revision: 868
Log:
rename DataDefinition[Error] to ModuleSpec[Error]
Modified:
branches/jelte-configuration/src/lib/config/cpp/ccsession.cc
branches/jelte-configuration/src/lib/config/cpp/ccsession.h
branches/jelte-configuration/src/lib/config/cpp/data_def.cc
branches/jelte-configuration/src/lib/config/cpp/data_def.h
branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc
branches/jelte-configuration/src/lib/config/python/isc/config/module_spec.py
Modified: branches/jelte-configuration/src/lib/config/cpp/ccsession.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/ccsession.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/ccsession.cc Thu Feb 18 12:20:55 2010
@@ -45,9 +45,9 @@
using isc::data::Element;
using isc::data::ElementPtr;
-using isc::data::DataDefinition;
+using isc::data::ModuleSpec;
using isc::data::ParseError;
-using isc::data::DataDefinitionError;
+using isc::data::ModuleSpecError;
void
CommandSession::read_data_definition(const std::string& filename) {
@@ -61,11 +61,11 @@
}
try {
- data_definition_ = DataDefinition(file, true);
+ data_definition_ = ModuleSpec(file, true);
} catch (ParseError pe) {
cout << "Error parsing definition file: " << pe.what() << endl;
exit(1);
- } catch (DataDefinitionError dde) {
+ } catch (ModuleSpecError dde) {
cout << "Error reading definition file: " << dde.what() << endl;
exit(1);
}
Modified: branches/jelte-configuration/src/lib/config/cpp/ccsession.h
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/ccsession.h (original)
+++ branches/jelte-configuration/src/lib/config/cpp/ccsession.h Thu Feb 18 12:20:55 2010
@@ -75,7 +75,7 @@
std::string module_name_;
isc::cc::Session session_;
- isc::data::DataDefinition data_definition_;
+ isc::data::ModuleSpec data_definition_;
isc::data::ElementPtr config_;
isc::data::ElementPtr(*config_handler_)(isc::data::ElementPtr new_config);
Modified: branches/jelte-configuration/src/lib/config/cpp/data_def.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/data_def.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/data_def.cc Thu Feb 18 12:20:55 2010
@@ -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"
@@ -8,7 +22,7 @@
#include <boost/foreach.hpp>
-// todo: add more context to thrown DataDefinitionErrors?
+// todo: add more context to thrown ModuleSpecErrors?
using namespace isc::data;
@@ -51,7 +65,7 @@
} else if (type_name == "any") {
return Element::any;
} 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 @@
if (spec->get(name)->getType() == type) {
return;
} else {
- throw DataDefinitionError(name + " not of type " + getType_string(type));
+ throw ModuleSpecError(name + " not of type " + getType_string(type));
}
} else if (mandatory) {
// todo: want parent item name, and perhaps some info about location
// in list? or just catch and throw new...
// 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 @@
static void
check_config_item_list(const ElementPtr& spec) {
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()) {
check_config_item(item);
@@ -116,7 +130,7 @@
static void
check_command_list(const ElementPtr& spec) {
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()) {
check_command(item);
@@ -137,27 +151,27 @@
}
// 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
check_definition(const ElementPtr& def)
{
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 {
check_data_specification(def->get("module_spec"));
}
}
-DataDefinition::DataDefinition(const std::string& file_name,
+ModuleSpec::ModuleSpec(const std::string& file_name,
const bool check)
- throw(ParseError, DataDefinitionError) {
+ throw(ParseError, ModuleSpecError) {
std::ifstream file;
file.open(file_name.c_str());
if (!file) {
std::stringstream errs;
errs << "Error opening " << file_name << ": " << strerror(errno);
- throw DataDefinitionError(errs.str());
+ throw ModuleSpecError(errs.str());
}
definition = Element::createFromString(file, file_name);
@@ -166,8 +180,8 @@
}
}
-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);
// make sure the whole structure is complete and valid
if (check) {
@@ -210,7 +224,7 @@
}
bool
-DataDefinition::validate_item(const ElementPtr spec, const ElementPtr data) {
+ModuleSpec::validate_item(const ElementPtr spec, const ElementPtr data) {
if (!check_type(spec, data)) {
// we should do some proper error feedback here
// std::cout << "type mismatch; not " << spec->get("item_type") << ": " << data << std::endl;
@@ -240,7 +254,7 @@
// spec is a map with item_name etc, data is a map
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();
bool optional = spec->get("item_optional")->boolValue();
ElementPtr data_el;
@@ -260,7 +274,7 @@
// spec is a list of maps, data is a map
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;
std::string cur_item_name;
BOOST_FOREACH(ElementPtr cur_spec_el, spec->listValue()) {
@@ -275,7 +289,7 @@
// this function does *not* check if the specification is in correct
// form, we should do that in the constructor
bool
-DataDefinition::validate(const ElementPtr data) {
+ModuleSpec::validate(const ElementPtr data) {
ElementPtr spec = definition->find("module_spec/config_data");
return validate_spec_list(spec, data);
}
Modified: branches/jelte-configuration/src/lib/config/cpp/data_def.h
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/data_def.h (original)
+++ branches/jelte-configuration/src/lib/config/cpp/data_def.h Thu Feb 18 12:20:55 2010
@@ -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>
@@ -8,22 +23,22 @@
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.
///
/// TODO: use jinmei's exception class as a base and not c_str in
/// what() there
- class DataDefinitionError : public std::exception {
+ class ModuleSpecError : public std::exception {
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(); }
private:
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
/// for configuration and commands for that module.
/// This class holds that specification, and provides a function to
@@ -32,36 +47,36 @@
///
/// The form of the specification is described in doc/ (TODO)
///
- class DataDefinition {
+ class ModuleSpec {
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
/// \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.
/// 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.
/// \param file_name The file to be opened and parsed
/// \param check If true, the data definition in the file is
/// 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?
- /// 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.
/// 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.
/// \param in The std::istream containing the .spec file data
/// \param check If true, the data definition is checked to be
/// 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
/// by this instance
Modified: branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc Thu Feb 18 12:20:55 2010
@@ -34,23 +34,23 @@
const std::string& error2 = "",
const std::string& error3 = "")
{
- EXPECT_THROW(DataDefinition(specfile(file)), DataDefinitionError);
+ EXPECT_THROW(ModuleSpec(specfile(file)), ModuleSpecError);
try {
- DataDefinition dd = DataDefinition(specfile(file));
- } catch (DataDefinitionError dde) {
+ ModuleSpec dd = ModuleSpec(specfile(file));
+ } catch (ModuleSpecError dde) {
std::string ddew = dde.what();
EXPECT_EQ(error1 + error2 + error3, ddew);
}
}
-TEST(DataDefinition, ReadingSpecfiles) {
+TEST(ModuleSpec, ReadingSpecfiles) {
// Tests whether we can open specfiles and if we get the
// right parse errors
- DataDefinition dd = DataDefinition(specfile("spec1.spec"));
+ ModuleSpec dd = ModuleSpec(specfile("spec1.spec"));
EXPECT_EQ(dd.getDefinition()->get("module_spec")
->get("module_name")
->stringValue(), "Spec1");
- dd = DataDefinition(specfile("spec2.spec"));
+ dd = ModuleSpec(specfile("spec2.spec"));
EXPECT_EQ(dd.getDefinition()->get("module_spec")
->get("config_data")->size(), 6);
data_def_error("doesnotexist",
@@ -60,13 +60,13 @@
std::ifstream file;
file.open(specfile("spec1.spec").c_str());
- dd = DataDefinition(file);
+ dd = ModuleSpec(file);
EXPECT_EQ(dd.getDefinition()->get("module_spec")
->get("module_name")
->stringValue(), "Spec1");
}
-TEST(DataDefinition, SpecfileItems) {
+TEST(ModuleSpec, SpecfileItems) {
data_def_error("spec3.spec",
"item_name missing in {\"item_default\": 1, \"item_optional\": False, \"item_type\": \"integer\"}");
data_def_error("spec4.spec",
@@ -91,7 +91,7 @@
"badname is not a valid type name");
}
-TEST(DataDefinition, SpecfileConfigData)
+TEST(ModuleSpec, SpecfileConfigData)
{
data_def_error("spec7.spec",
"module_name missing in {}");
@@ -103,7 +103,7 @@
"commands is not a list of elements");
}
-TEST(DataDefinition, SpecfileCommands)
+TEST(ModuleSpec, SpecfileCommands)
{
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\"}");
@@ -120,7 +120,7 @@
}
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;
@@ -131,8 +131,8 @@
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_FALSE(data_test(dd, "data22_2.data"));
Modified: branches/jelte-configuration/src/lib/config/python/isc/config/module_spec.py
==============================================================================
--- branches/jelte-configuration/src/lib/config/python/isc/config/module_spec.py (original)
+++ branches/jelte-configuration/src/lib/config/python/isc/config/module_spec.py Thu Feb 18 12:20:55 2010
@@ -57,7 +57,7 @@
"""Initializes a ModuleSpec object from the specification in
the given module_spec (which must be a dict). If check is
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:
raise ModuleSpecError("module_spec is of type " + str(type(module_spec)) + ", not dict")
if check:
More information about the bind10-changes
mailing list