[Zrouter-src] ZRouter.org: push to zconf++ zconf++/zconfig.cc
zrouter-src at zrouter.org
zrouter-src at zrouter.org
Wed Feb 22 15:14:47 UTC 2012
details: /rev/be9bc2e311d7
changeset: 66:be9bc2e311d7
user: "Nicolai Petri <nicolai at petri.dk>"
date: Wed Feb 22 16:14:02 2012 +0100
description:
Add initial versions of config_save and config_load actions.
diffstat:
zconf++/zconfig.cc | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diffs (42 lines):
diff -r f95e4d975a6c -r be9bc2e311d7 zconf++/zconfig.cc
--- a/zconf++/zconfig.cc Wed Feb 22 16:06:52 2012 +0100
+++ b/zconf++/zconfig.cc Wed Feb 22 16:14:02 2012 +0100
@@ -117,8 +117,38 @@
return l;
}
+ Leaf action_save_config(const std::string &uri, LeafRef pSelf, LeafRef pRequest ) {
+ Leaf res;
+ std::string filepath = pRequest["path"].get_string();
+ LeafRef l = m_running->parent().parent()[pRequest["target"].get_string()];
+ try {
+ std::ofstream cfgfile(filepath.c_str());
+ ModelWriter::write(cfgfile, l, "");
+ res["success"] = "File saved";
+ } catch (...) {
+ res["error"] = "Unknown error";
+ }
+ return res;
+ }
+ Leaf action_load_config(const std::string &uri, LeafRef pSelf, LeafRef pRequest ) {
+ Leaf res;
+ std::string filepath = pRequest["path"].get_string();
+ if (boost::filesystem::exists(filepath)) {
+ std::cout << " - loading saved configuration from " << filepath << std::endl;
+ std::ifstream cfgfile(filepath.c_str());
+ Json::Reader r;
+ LeafRef l = m_running->parent().parent()[pRequest["target"].get_string()];
+ r.parse(cfgfile, l);
+ res["success"]="File loaded";
+ } else {
+ res["error"]="File not found";
+ }
+ return res;
+ }
bool self_init(boost::asio::io_service &io, Model &model) {
LeafRef cfg = model["configuration"];
+ cfg["config_load"] = ACTION_HANDLER(Z_Config_Module, this, action_load_config, describe_dummy);
+ cfg["config_save"] = ACTION_HANDLER(Z_Config_Module, this, action_save_config, describe_dummy);
m_running = &cfg["running"];
m_configured = &cfg["configured"];
if (boost::filesystem::exists("saved_configuration.json")) {
More information about the Zrouter-src
mailing list