[svn] commit: r84 - in /experiments/jelte-configuration: config_manager.cc config_obj.hh
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Oct 12 09:46:16 UTC 2009
Author: jelte
Date: Mon Oct 12 09:46:16 2009
New Revision: 84
Log:
added a way to use config subparts by reference (although the parser object currently is still created)
config_manager.cc now shows the three ways that one can modify values in the config structure
Modified:
experiments/jelte-configuration/config_manager.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 Mon Oct 12 09:46:16 2009
@@ -111,32 +111,53 @@
cout << "Trying to get zone theo.com from the module named recursive" << endl;
try {
+ // There are three methods to change values;
+
+ //
+ // 1) Setting directly, with set_value(identifier, value)
+ //
+
+ config->set_value("/module[@name=recursive]/zones/zone[@name=tjeb.nl]/file", "/var/zones/tjeb.nl.signed");
+
+ //
+ // 2) Get a clone config part, which has to be set back
+ //
Config *config_part;
config_part = config->get_config_part("/module[@name=recursive]/zones/zone[@name=theo.com]");
+
cout << "Selected zone configuration: " << endl;
config_part->write_stream(std::cout);
cout << "Changing file to /tmp/myfile" << endl;
config_part->set_value("/file", "/tmp/myfile");
+ 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->set_config_part("/module[@name=recursive]/zones/zone[@name=theo.com]", config_part);
+
+ delete config_part;
+
+ //
+ // 3) Get a reference to a part. Since this is a reference,
+ // the original structure is modified directly, and we
+ // do not have to set the part back
+ //
+ Config *config_part2 = new Config(config->get_reference("/module[@name=recursive]/zones/zone[@name=theo.com]"));
+ //config_part = config->get_config_part("/module[@name=recursive]/zones/zone[@name=theo.com]");
cout << "Add a new element, 'auto-notify'" << endl;
- config_part->add_element("auto-notify");
+ config_part2->add_element("auto-notify");
cout << "Set value of 'auto-notify' to false" << endl;
- config_part->set_value("/auto-notify", "false");
+ config_part2->set_value("/auto-notify", "false");
cout << "Remove the 'foo' element" << endl;
- config_part->remove_element("/foo");
+ config_part2->remove_element("/foo");
cout << "Selected zone configuration now: " << endl;
- config_part->write_stream(std::cout);
+ config_part2->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->set_config_part("/module[@name=recursive]/zones/zone[@name=theo.com]", config_part);
-
- delete config_part;
+ delete config_part2;
} catch (ConfigError& ce) {
cout << "Caught ConfigError: " << ce.what() << endl;
}
Modified: experiments/jelte-configuration/config_obj.hh
==============================================================================
--- experiments/jelte-configuration/config_obj.hh (original)
+++ experiments/jelte-configuration/config_obj.hh Mon Oct 12 09:46:16 2009
@@ -89,9 +89,16 @@
public:
/* constructs an empty config element */
Config() : node(NULL) { parser = new xercesc::XercesDOMParser(); }
+
+ /* constructs a Config element from a reference (which is returned
+ * by get_reference(). Please refrain from using a DOMNode directly
+ * as an argument for this constructor, as the type may change */
+ Config(xercesc::DOMNode *n) { node = n; parser = new xercesc::XercesDOMParser(); }
+
/* constructs a config element with the xml data found in
* the given file, throws ConfigError on error */
Config(std::string filename);
+
/* constructs a config element with the xml data found in
* the given input stream. Throws ConfigError on error.
* Stream functionality is not completely implemented yet
@@ -177,6 +184,19 @@
* stream */
void write_stream(std::ostream &out);
+ /* Returns a DOMNode reference to the current root node */
+ xercesc::DOMNode *get_reference() { return node; }
+
+ /* returns a (DOMNode) reference to the node specified by the
+ * given identifier. See IDENTIFIER STRINGS above.
+ * The result value of this method can be used to select
+ * a specific part of the base Config without cloning the
+ * whole structure.
+ * Please refrain from using the DOMNode return value for
+ * anything else than the Config constructor, as the type may
+ * change */
+ xercesc::DOMNode *get_reference(std::string identifier) { return find_sub_node(node, identifier); }
+
private:
/* serialize a specific DOMNode to the given stream with
* the given prefix. Children of the node are also serialized
More information about the bind10-changes
mailing list