From 487fcf990f3c536d7e1d2f66daa0c34c0407eac5 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 27 Jan 2014 12:24:41 +0000 Subject: NT resinstated as HTTP server --- NT/src/factory.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'NT/src/factory.cpp') diff --git a/NT/src/factory.cpp b/NT/src/factory.cpp index b8f4642..2bd51ac 100644 --- a/NT/src/factory.cpp +++ b/NT/src/factory.cpp @@ -10,14 +10,39 @@ Node_factory::Node_factory(std::string _log_id){ add_type(new Multiply(),"nodes"); add_type(new Print(),"nodes"); } -bool Node_factory::list_node(const string &_type,Json::Value &json){ +Json::Value Node_factory::list_node(const string &_type){ + Json::Value json; for (auto& type: type_map) { if (type.first==_type) { json["node"]=type.second->to_json(); - return true; + return json; } } json["error"]="Node '"+_type+"' not found"; - return false; + return json; }; +Json::Value Node_factory::list_nodes(){ + Json::Value json; + json["nodeslist"]=Json::arrayValue; + for (auto& type: type_map) { + if (type.second->get_description()!="") { //blank description = internal/ testing node + json["nodeslist"].append(list_node(type.first)); + } + } + return json; +} +Json::Value Node_factory::list_categories(){ + Json::Value json; + json["category"]=Json::arrayValue; + for (auto& _category: category_map) { + Json::Value category; + category["name"]=_category.first; + category["nodes"]=Json::arrayValue; + for (auto& _node: _category.second){ + category["nodes"].append(list_node(_node->get_type())); + } + json["category"].append(category); + } + return json; +} -- cgit v1.2.3