[svn] commit: r62 - in /experiments/jelte-configuration: config_manager.cc config_manager.hh config_obj.cc config_obj.hh
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Oct 6 08:22:14 UTC 2009
Author: jelte
Date: Tue Oct 6 08:22:13 2009
New Revision: 62
Log:
style fix; lcase_with_underscores for method names
Modified:
experiments/jelte-configuration/config_manager.cc
experiments/jelte-configuration/config_manager.hh
experiments/jelte-configuration/config_obj.cc
experiments/jelte-configuration/config_obj.hh
Modified: experiments/jelte-configuration/config_manager.cc
==============================================================================
--- experiments/jelte-configuration/config_manager.cc (original)
+++ experiments/jelte-configuration/config_manager.cc Tue Oct 6 08:22:13 2009
@@ -29,7 +29,7 @@
}
void
-ConfigManager::loadConfiguration(std::string filename)
+ConfigManager::load_configuration(std::string filename)
{
try {
config = new Config(filename);
@@ -42,10 +42,10 @@
}
void
-ConfigManager::saveConfiguration(std::string filename)
+ConfigManager::save_configuration(std::string filename)
{
try {
- config->writeFile(filename);
+ config->write_file(filename);
} catch (ConfigError e) {
std::string err;
err = "Error writing " + filename + ": " + e.what();
@@ -54,7 +54,7 @@
}
void
-ConfigManager::initConfigManager()
+ConfigManager::init_config_manager()
{
/* set up communication channel */
return;
@@ -67,17 +67,17 @@
while (1) {
/* listen for commands, on read-type command
* (GET identifier?) do something like
- * Config *subconfig = config->getConfigPart(identifier);
- * subconfig->writeStream(outstream);
+ * Config *subconfig = config->get_config_part(identifier);
+ * subconfig->write_stream(outstream);
* delete subconfig;
*
* on set do something like
* PUT identifier
* <xmlblob>
*
- * Config *subconfig = config->readStream(intstream);
+ * Config *subconfig = config->read_stream(intstream);
* config->check_subconfig(identifier, subconfig);
- * config->setConfigPart(identifier, subconfig);
+ * config->set_config_part(identifier, subconfig);
* delete subconfig;
* write_ok_to_outstream;
* notify_registered_clients
@@ -86,20 +86,20 @@
#endif
/* just some random actions the manager can do on the config */
if (config) {
- std::string a = config->getValue("/module[@name=authoritative]@name");
+ std::string a = config->get_value("/module[@name=authoritative]@name");
cout << "module name: " << a << endl;
- config->setValue("/module at name", "recursive");
- std::string b = config->getValue("/module at name");
+ config->set_value("/module at name", "recursive");
+ std::string b = config->get_value("/module at name");
cout << "module name now: " << b << endl;
cout << endl;
cout << "Trying to get zone theo.com from the module named authoritative" << endl;
try {
Config *config_part;
- config_part = config->getConfigPart("/module[@name=authoritative]/zones/zone[@name=theo.com]");
- //config_part->setValue("@name", "asdf.com");
+ config_part = config->get_config_part("/module[@name=authoritative]/zones/zone[@name=theo.com]");
+ //config_part->set_value("@name", "asdf.com");
cout << "Selected zone: " << endl;
- config_part->writeStream(std::cout);
+ config_part->write_stream(std::cout);
} catch (ConfigError ce) {
cout << "Caught ConfigError: " << ce.what() << endl;
}
@@ -111,26 +111,26 @@
cout << "Trying to get zone theo.com from the module named recursive" << endl;
try {
Config *config_part;
- config_part = config->getConfigPart("/module[@name=recursive]/zones/zone[@name=theo.com]");
+ config_part = config->get_config_part("/module[@name=recursive]/zones/zone[@name=theo.com]");
cout << "Selected zone configuration: " << endl;
- config_part->writeStream(std::cout);
+ config_part->write_stream(std::cout);
cout << "Changing file to /tmp/myfile" << endl;
- config_part->setValue("/file", "/tmp/myfile");
+ config_part->set_value("/file", "/tmp/myfile");
cout << "Add a new element, 'auto-notify'" << endl;
- config_part->addChild("auto-notify");
+ config_part->add_child("auto-notify");
cout << "Set value of 'auto-notify' to false" << endl;
- config_part->setValue("/auto-notify", "false");
+ config_part->set_value("/auto-notify", "false");
cout << "Selected zone configuration now: " << endl;
- config_part->writeStream(std::cout);
+ config_part->write_stream(std::cout);
cout << endl;
cout << "Putting the updated configuration part back in the main config." << endl;
/* make sure this is the exact same as the getconfig part above, no checking is done atm! */
- config->setConfigPart("/module[@name=recursive]/zones/zone[@name=theo.com]", config_part);
+ config->set_config_part("/module[@name=recursive]/zones/zone[@name=theo.com]", config_part);
delete config_part;
} catch (ConfigError ce) {
@@ -146,12 +146,12 @@
main(int argc, char **argv)
{
ConfigManager cm;
- cm.loadConfiguration("./myconf.conf");
- cm.initConfigManager();
+ cm.load_configuration("./myconf.conf");
+ cm.init_config_manager();
cm.run();
cout << "Storing the main config" << endl;
- cm.saveConfiguration("./myconf_new.conf");
+ cm.save_configuration("./myconf_new.conf");
cout << "New configuration stored in ./myconf_new.conf" << endl;
}
Modified: experiments/jelte-configuration/config_manager.hh
==============================================================================
--- experiments/jelte-configuration/config_manager.hh (original)
+++ experiments/jelte-configuration/config_manager.hh Tue Oct 6 08:22:13 2009
@@ -26,12 +26,12 @@
~ConfigManager();
/* Load a specific configuration from the given file */
- void loadConfiguration(std::string file);
+ void load_configuration(std::string file);
/* Save the configuration to the given file */
- void saveConfiguration(std::string file);
+ void save_configuration(std::string file);
/* Initialize configuration manager, set up environment etc. */
- void initConfigManager();
+ void init_config_manager();
/* Run the configuration manager */
void run();
Modified: experiments/jelte-configuration/config_obj.cc
==============================================================================
--- experiments/jelte-configuration/config_obj.cc (original)
+++ experiments/jelte-configuration/config_obj.cc Tue Oct 6 08:22:13 2009
@@ -18,7 +18,7 @@
/* we could perhaps use the MemoryManager functionality
* instead of going through these hoops */
static std::string
-XMLStringToString(const XMLCh *xml_str)
+xmlstring_to_string(const XMLCh *xml_str)
{
char *str_c;
std::string str;
@@ -29,7 +29,7 @@
}
static MemBufInputSource *
-getMemBufInputSource(std::istream &in) {
+get_membuf_inputsource(std::istream &in) {
XMLCh *buf_id = XMLString::transcode("in_source");
XMLByte *bytes;
XMLSize_t size;
@@ -103,60 +103,60 @@
Config::Config(std::string filename)
{
parser = new XercesDOMParser();
- readFile(filename);
+ read_file(filename);
}
Config::Config(std::istream &in)
{
parser = new XercesDOMParser();
- readStream(in);
+ read_stream(in);
}
/*
* some simple accessors
*/
std::string
- Config::getName() {
- return getNodeName(node);
+ Config::get_name() {
+ return get_node_name(node);
}
std::string
- Config::getValue() {
- return getNodeValue(node);
+ Config::get_value() {
+ return get_node_value(node);
}
std::string
- Config::getValue(std::string identifier) {
- DOMNode *n = findSubNode(node, identifier);
- return getNodeValue(n);
- }
-
- void
- Config::setValue(std::string const &value) {
- setNodeValue(node, value);
- }
-
- void
- Config::setValue(std::string identifier, std::string const &value) {
- DOMNode *n = findSubNode(node, identifier);
- setNodeValue(n, value);
- }
-
- void
- Config::addChild(std::string name)
- {
- addNodeChild(node, name);
- }
-
- void
- Config::addChild(std::string identifier, std::string name)
- {
- DOMNode *n = findSubNode(node, identifier);
- addNodeChild(n, name);
- }
-
- void
- Config::readFile(const std::string &filename)
+ Config::get_value(std::string identifier) {
+ DOMNode *n = find_sub_node(node, identifier);
+ return get_node_value(n);
+ }
+
+ void
+ Config::set_value(std::string const &value) {
+ set_node_value(node, value);
+ }
+
+ void
+ Config::set_value(std::string identifier, std::string const &value) {
+ DOMNode *n = find_sub_node(node, identifier);
+ set_node_value(n, value);
+ }
+
+ void
+ Config::add_child(std::string name)
+ {
+ add_node_child(node, name);
+ }
+
+ void
+ Config::add_child(std::string identifier, std::string name)
+ {
+ DOMNode *n = find_sub_node(node, identifier);
+ add_node_child(n, name);
+ }
+
+ void
+ Config::read_file(const std::string &filename)
{
if (node) {
throw ConfigError("Configuration already read");
@@ -172,24 +172,24 @@
try {
parser->parse(filename.c_str());
} catch (const XMLException& toCatch) {
- throw ConfigError(XMLStringToString(toCatch.getMessage()));
+ throw ConfigError(xmlstring_to_string(toCatch.getMessage()));
} catch (const DOMException& toCatch) {
- throw ConfigError(XMLStringToString(toCatch.getMessage()));
+ throw ConfigError(xmlstring_to_string(toCatch.getMessage()));
} catch (const SAXParseException& toCatch) {
- throw ConfigError(XMLStringToString(toCatch.getMessage()));
+ throw ConfigError(xmlstring_to_string(toCatch.getMessage()));
}
node = parser->getDocument()->getDocumentElement();
/* if we have a DTD that shows what whitespace is ignorable
* we can omit this step */
- removeEmptyTextNodes(node);
+ remove_empty_text_nodes(node);
delete errHandler;
}
void
- Config::writeFile(const std::string &filename)
+ Config::write_file(const std::string &filename)
{
std::ofstream ofile;
ofile.open(filename.c_str());
@@ -203,13 +203,13 @@
}
void
- Config::readStream(std::istream &in)
+ Config::read_stream(std::istream &in)
{
if (node) {
throw ConfigError("Configuration already read");
}
/* read the stream into an inputsource */
- MemBufInputSource *in_source = getMemBufInputSource(in);
+ MemBufInputSource *in_source = get_membuf_inputsource(in);
/* we could set validation scheme and/or namespaces here */
parser->setValidationScheme(XercesDOMParser::Val_Always);
@@ -222,34 +222,34 @@
try {
parser->parse(*in_source);
} catch (const XMLException& toCatch) {
- throw ConfigError(XMLStringToString(toCatch.getMessage()));
+ throw ConfigError(xmlstring_to_string(toCatch.getMessage()));
} catch (const DOMException& toCatch) {
- throw ConfigError(XMLStringToString(toCatch.getMessage()));
+ throw ConfigError(xmlstring_to_string(toCatch.getMessage()));
} catch (const SAXParseException& toCatch) {
- throw ConfigError(XMLStringToString(toCatch.getMessage()));
+ throw ConfigError(xmlstring_to_string(toCatch.getMessage()));
}
node = parser->getDocument()->getDocumentElement();
/* if we have a DTD that shows what whitespace is ignorable
* we can omit this step */
- removeEmptyTextNodes(node);
+ remove_empty_text_nodes(node);
delete in_source;
delete errHandler;
}
void
- Config::writeStream(std::ostream &out)
+ Config::write_stream(std::ostream &out)
{
serialize(out);
}
Config *
- Config::getConfigPart(std::string const &identifier) {
+ Config::get_config_part(std::string const &identifier) {
Config *config_part = new Config();
try {
- config_part->node = findSubNode(node, identifier)->cloneNode(true);
+ config_part->node = find_sub_node(node, identifier)->cloneNode(true);
return config_part;
} catch (ConfigError ce) {
delete config_part;
@@ -258,11 +258,11 @@
}
void
- Config::setConfigPart(std::string const &identifier, Config *config_part)
+ Config::set_config_part(std::string const &identifier, Config *config_part)
{
/* should throw exception if node not found, so check
* not necessary */
- DOMNode *part_node = findSubNode(node, identifier);
+ DOMNode *part_node = find_sub_node(node, identifier);
DOMNode *parent_node = part_node->getParentNode();
parent_node->removeChild(part_node);
parent_node->appendChild(config_part->node->cloneNode(true));
@@ -278,27 +278,27 @@
/* if we use a newer version or a lib that does have direct
* serialization support, please replace this */
void
- Config::serializeDOMNode(std::ostream &out, DOMNode *n, std::string prefix="")
+ Config::serialize_dom_node(std::ostream &out, DOMNode *n, std::string prefix="")
{
if (n->getNodeType() == n->TEXT_NODE) {
out << prefix
- << XMLStringToString(n->getNodeValue())
+ << xmlstring_to_string(n->getNodeValue())
<< std::endl;
} else if (n->getNodeType() == n->ATTRIBUTE_NODE) {
out << " "
- << XMLStringToString(n->getNodeName())
+ << xmlstring_to_string(n->getNodeName())
<< "=\""
- << XMLStringToString(n->getNodeValue())
+ << xmlstring_to_string(n->getNodeValue())
<< "\"";
} else {
/* 'normal' node */
/* name of this node */
- out << prefix << "<" << XMLStringToString(n->getNodeName());
+ out << prefix << "<" << xmlstring_to_string(n->getNodeName());
/* attributes */
DOMNamedNodeMap *attrs = n->getAttributes();
if (attrs) {
for (XMLSize_t i = 0; i < attrs->getLength(); i++) {
- serializeDOMNode(out, attrs->item(i), prefix);
+ serialize_dom_node(out, attrs->item(i), prefix);
}
}
/* do we have children? */
@@ -307,9 +307,9 @@
out << ">" << std::endl;
DOMNodeList *children = n->getChildNodes();
for (XMLSize_t i = 0; i < children->getLength(); i++) {
- serializeDOMNode(out, children->item(i), new_prefix);
- }
- out << prefix << "</" << XMLStringToString(n->getNodeName());
+ serialize_dom_node(out, children->item(i), new_prefix);
+ }
+ out << prefix << "</" << xmlstring_to_string(n->getNodeName());
} else {
out << "/";
}
@@ -321,11 +321,11 @@
Config::serialize(std::ostream &out)
{
out << "<?xml version=\"1.0\"?>" << std::endl;
- serializeDOMNode(out, node, "");
- }
-
- void
- Config::removeEmptyTextNodes(DOMNode *n)
+ serialize_dom_node(out, node, "");
+ }
+
+ void
+ Config::remove_empty_text_nodes(DOMNode *n)
{
/* iterate over all children and their children,
* if a child is a text-node containing only whitespace
@@ -338,31 +338,31 @@
for (XMLSize_t i = 0; i < children->getLength(); i++) {
c = children->item(i);
if (c->getNodeType() == c->TEXT_NODE) {
- std::string str = XMLStringToString(c->getNodeValue());
+ std::string str = xmlstring_to_string(c->getNodeValue());
if (str.find_first_not_of("\t\n\r ") == str.npos) {
/* ok only whitespace, remove this child */
n->removeChild(c);
i--;
}
} else {
- removeEmptyTextNodes(children->item(i));
+ remove_empty_text_nodes(children->item(i));
}
}
}
}
std::string
- Config::getNodeName(const DOMNode *n)
+ Config::get_node_name(const DOMNode *n)
{
if (n) {
- return XMLStringToString(n->getNodeName());
+ return xmlstring_to_string(n->getNodeName());
} else {
return std::string("<empty/>");
}
}
std::string
- Config::getNodeValue(const DOMNode *n)
+ Config::get_node_value(const DOMNode *n)
{
if (!n) {
throw ConfigError("null element");
@@ -375,14 +375,14 @@
n->getFirstChild()->getNodeType() == n->TEXT_NODE
)
) {
- return XMLStringToString(n->getTextContent());
- } else {
- throw ConfigError("Not a value leaf or attribute " + getNodeName(n));
- }
- }
-
- void
- Config::setNodeValue(DOMNode *n, std::string const &value)
+ return xmlstring_to_string(n->getTextContent());
+ } else {
+ throw ConfigError("Not a value leaf or attribute " + get_node_name(n));
+ }
+ }
+
+ void
+ Config::set_node_value(DOMNode *n, std::string const &value)
{
DOMNode *c;
XMLCh *xml_str;
@@ -404,12 +404,12 @@
n->setTextContent(xml_str);
XMLString::release(&xml_str);
} else {
- throw ConfigError("Not a value leaf or attribute " + getNodeName(n));
- }
- }
-
- void
- Config::addNodeChild(DOMNode *n, std::string const &name)
+ throw ConfigError("Not a value leaf or attribute " + get_node_name(n));
+ }
+ }
+
+ void
+ Config::add_node_child(DOMNode *n, std::string const &name)
{
XMLCh *xml_str = XMLString::transcode(name.c_str());
n->appendChild(n->getOwnerDocument()->createElement(xml_str));
@@ -417,7 +417,7 @@
}
DOMNode *
- Config::findSubNode(DOMNode *n, std::string const &identifier)
+ Config::find_sub_node(DOMNode *n, std::string const &identifier)
{
/* some subset of xpath like stuff */
/* only / and @ are supported */
@@ -437,7 +437,7 @@
XMLString::release(&xml_str);
if (!result_n) {
throw ConfigError("Unknown attribute " + attribute
- + " in element " + getNodeName(n));
+ + " in element " + get_node_name(n));
}
return result_n;
} else if (new_identifier.length() > 0) {
@@ -445,12 +445,12 @@
DOMNodeList *children = n->getChildNodes();
for (XMLSize_t i = 0; i < children->getLength(); i++) {
/* name of the node must match */
- if (new_identifier.compare(getNodeName(children->item(i))) == 0) {
+ if (new_identifier.compare(get_node_name(children->item(i))) == 0) {
/* if a selector is present, so
* must the value of the selector */
if (selector_name.length() > 0) {
- DOMNode *sel_node = findSubNode(children->item(i), selector_name);
- if (selector_value.compare(getNodeValue(sel_node)) == 0) {
+ DOMNode *sel_node = find_sub_node(children->item(i), selector_name);
+ if (selector_value.compare(get_node_value(sel_node)) == 0) {
result_n = children->item(i);
}
} else {
@@ -460,7 +460,7 @@
/* found one, continue down the tree */
if (result_n) {
if (rest.length() > 0) {
- result_n = findSubNode(result_n, rest);
+ result_n = find_sub_node(result_n, rest);
}
i = children->getLength();
}
@@ -486,7 +486,7 @@
try {
XMLPlatformUtils::Initialize();
} catch (const XMLException& toCatch) {
- throw ConfigError(XMLStringToString(toCatch.getMessage()));
+ throw ConfigError(xmlstring_to_string(toCatch.getMessage()));
}
}
Modified: experiments/jelte-configuration/config_obj.hh
==============================================================================
--- experiments/jelte-configuration/config_obj.hh (original)
+++ experiments/jelte-configuration/config_obj.hh Tue Oct 6 08:22:13 2009
@@ -100,37 +100,37 @@
*/
Config(std::istream &in);
- ~Config() { if (parser) { delete parser; } }
+ ~Config() { delete parser; }
/* returns the name of the base node */
- std::string getName();
+ std::string get_name();
/* returns the value of the base node.
* If the base node is not an attribute node or an
* element node with only one text node child, a
* ConfigError is thrown */
- std::string getValue();
+ std::string get_value();
/* returns the value of a specific part of the configuration
* See IDENTIFIER STRINGS above.
* If not found, or if the node does not have a gettable value,
* a ConfigError exception is thrown
*/
- std::string getValue(std::string identifier);
+ std::string get_value(std::string identifier);
/* sets the value of the base node.
* If the base node is not an attribute node or an
* element node with only one text node child, a
* ConfigError is thrown */
- void setValue(std::string const &value);
+ void set_value(std::string const &value);
/* sets the value of a specific part of the configuration
* See IDENTIFIER STRINGS above.
* If not found, a ConfigError exception is thrown
*/
- void setValue(std::string identifier, std::string const &value);
+ void set_value(std::string identifier, std::string const &value);
/*
* Adds an empty element to the children of the current node
*/
- void addChild(std::string name);
+ void add_child(std::string name);
/*
* Adds an empty element to the children of the node specified
@@ -138,63 +138,64 @@
* See IDENTIFIER STRINGS above.
* If not found, a ConfigError exception is thrown
*/
- void addChild(std::string identifier, std::string name);
+ void add_child(std::string identifier, std::string name);
/* returns a clone of a specific subtree of this configuration
* part.
* See IDENTIFIER STRINGS above.
* If not found, a ConfigError exception is thrown
*/
- Config *getConfigPart(std::string const &identifier);
+ Config *get_config_part(std::string const &identifier);
+
/* replaces a specific subtree of this configuration
* part by a clone of the given config part.
* See IDENTIFIER STRINGS above.
* If not found, a ConfigError exception is thrown
*/
- void setConfigPart(std::string const &identifier, Config *config);
+ void set_config_part(std::string const &identifier, Config *config);
/* Read in an XML file
* Throws a ConfigError if there is a problem reading or parsing
* the file */
- void readFile(const std::string &filename);
+ void read_file(const std::string &filename);
/* Write out this configuration (part) to an XML file
* Throws a ConfigError if the file cannot be opened for
* writing */
- void writeFile(const std::string &filename);
+ void write_file(const std::string &filename);
/* Read in an XML stream
* Throws a ConfigError if there is a problem reading or parsing
* the file */
- void readStream(std::istream &in);
+ void read_stream(std::istream &in);
/* Write out this configuration (part) to the given output
* stream */
- void writeStream(std::ostream &out);
+ void write_stream(std::ostream &out);
private:
/* serialize a specific DOMNode to the given stream with
* the given prefix. Children of the node are also serialized
* with a \t character added to the prefix */
- void serializeDOMNode(std::ostream &out, DOMNode *n, std::string prefix);
+ void serialize_dom_node(std::ostream &out, DOMNode *n, std::string prefix);
/* Serialize the complete config part to the given stream,
* prepended with <?xml version="1.0"?> */
void serialize(std::ostream &out);
/* Helper function to clear out empty text nodes which are
* the result from parsing a file without a DTD */
- void removeEmptyTextNodes(DOMNode *n);
+ void remove_empty_text_nodes(DOMNode *n);
/* Returns the name of a specific DOMNode */
- std::string getNodeName(const DOMNode *n);
+ std::string get_node_name(const DOMNode *n);
/* Returns the value of a specific DOMNode */
- std::string getNodeValue(const DOMNode *n);
+ std::string get_node_value(const DOMNode *n);
/* Sets the value of a specific DOMNode */
- void setNodeValue(DOMNode *n, std::string const &value);
+ void set_node_value(DOMNode *n, std::string const &value);
/* Add an empty element node to the children of the given node*/
- void addNodeChild(DOMNode *n, std::string const &name);
+ void add_node_child(DOMNode *n, std::string const &name);
/* Returns a DOMNode identifier by the given identifier */
- DOMNode *findSubNode(DOMNode *n, std::string const &identifier);
+ DOMNode *find_sub_node(DOMNode *n, std::string const &identifier);
};
}}
More information about the bind10-changes
mailing list