diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/boost_fail/json_parser_read_104900.hpp (renamed from lib/json_parser_read_104900.hpp) | 0 | ||||
-rw-r--r-- | lib/json_parser.cpp | 2 | ||||
-rw-r--r-- | lib/top_block_query.cpp | 59 |
3 files changed, 37 insertions, 24 deletions
diff --git a/lib/json_parser_read_104900.hpp b/lib/boost_fail/json_parser_read_104900.hpp index f7c6515..f7c6515 100644 --- a/lib/json_parser_read_104900.hpp +++ b/lib/boost_fail/json_parser_read_104900.hpp diff --git a/lib/json_parser.cpp b/lib/json_parser.cpp index 4a75f3d..d66297f 100644 --- a/lib/json_parser.cpp +++ b/lib/json_parser.cpp @@ -5,7 +5,7 @@ //why the fuck does no OS ever patch boost when there is a bug //https://svn.boost.org/trac/boost/ticket/6785 #if BOOST_VERSION == 104900 -#include "json_parser_read_104900.hpp" +#include "boost_fail/json_parser_read_104900.hpp" #endif //--------- end bullshit --------------// diff --git a/lib/top_block_query.cpp b/lib/top_block_query.cpp index 671168c..9d8afbe 100644 --- a/lib/top_block_query.cpp +++ b/lib/top_block_query.cpp @@ -9,6 +9,8 @@ using namespace gras; +using namespace boost::property_tree; + ThreadPool get_active_thread_pool(void); struct GetStatsReceiver : Theron::Receiver @@ -26,31 +28,31 @@ struct GetStatsReceiver : Theron::Receiver std::vector<GetStatsMessage> messages; }; -static boost::property_tree::ptree query_blocks(ElementImpl *self, const boost::property_tree::ptree &) +static ptree query_blocks(ElementImpl *self, const ptree &) { - boost::property_tree::ptree root; - boost::property_tree::ptree e; + ptree root; + ptree e; BOOST_FOREACH(Apology::Worker *worker, self->executor->get_workers()) { BlockActor *block = dynamic_cast<BlockActor *>(worker); - boost::property_tree::ptree prop_e; + ptree prop_e; typedef std::pair<std::string, PropertyRegistryPair> PropRegistryKVP; BOOST_FOREACH(const PropRegistryKVP &p, block->property_registry) { - boost::property_tree::ptree prop_attrs; + ptree prop_attrs; if (p.second.setter) { - boost::property_tree::ptree type; + ptree type; type.put_value(p.second.setter->type().name()); prop_attrs.push_back(std::make_pair("setter", type)); } if (p.second.getter) { - boost::property_tree::ptree type; + ptree type; type.put_value(p.second.getter->type().name()); prop_attrs.push_back(std::make_pair("getter", type)); } - boost::property_tree::ptree block_attrs; + ptree block_attrs; block_attrs.push_back(std::make_pair(p.first, prop_attrs)); prop_e.push_back(std::make_pair("props", block_attrs)); } @@ -60,14 +62,13 @@ static boost::property_tree::ptree query_blocks(ElementImpl *self, const boost:: return root; } -static boost::property_tree::ptree query_stats(ElementImpl *self, const boost::property_tree::ptree &query) +static ptree query_stats(ElementImpl *self, const ptree &query) { - //parse list of block ids needed in this query std::vector<std::string> block_ids; if (query.count("blocks") != 0) { - BOOST_FOREACH(const boost::property_tree::ptree::value_type &v, query.get_child("blocks")) + BOOST_FOREACH(const ptree::value_type &v, query.get_child("blocks")) { block_ids.push_back(v.second.get<std::string>("")); } @@ -91,7 +92,7 @@ static boost::property_tree::ptree query_stats(ElementImpl *self, const boost::p while (outstandingCount) outstandingCount -= receiver.Wait(outstandingCount); //create root level node - boost::property_tree::ptree root; + ptree root; root.put("now", time_now()); root.put("tps", time_tps()); @@ -115,11 +116,11 @@ static boost::property_tree::ptree query_stats(ElementImpl *self, const boost::p } //iterate through blocks - boost::property_tree::ptree blocks; + ptree blocks; BOOST_FOREACH(const GetStatsMessage &message, receiver.messages) { const BlockStats &stats = message.stats; - boost::property_tree::ptree block; + ptree block; block.put("tps", time_tps()); block.put("stats_time", message.stats_time); block.put("init_time", stats.init_time); @@ -134,9 +135,9 @@ static boost::property_tree::ptree query_stats(ElementImpl *self, const boost::p block.put("total_time_output", stats.total_time_output); block.put("actor_queue_depth", stats.actor_queue_depth); #define my_block_ptree_append(l) { \ - boost::property_tree::ptree e; \ + ptree e; \ for (size_t i = 0; i < stats.l.size(); i++) { \ - boost::property_tree::ptree t; t.put_value(stats.l[i]); \ + ptree t; t.put_value(stats.l[i]); \ e.push_back(std::make_pair("", t)); \ } \ block.push_back(std::make_pair(#l, e)); \ @@ -159,18 +160,30 @@ static boost::property_tree::ptree query_stats(ElementImpl *self, const boost::p return root; } -boost::property_tree::ptree json_to_ptree(const std::string &s); -std::string ptree_to_json(const boost::property_tree::ptree &p); +static ptree query_props(ElementImpl *self, const ptree &query) +{ + ptree root; + const std::string block_id = query.get<std::string>("block"); + const std::string prop_key = query.get<std::string>("key"); + const std::string action = query.get<std::string>("action"); + const std::string value = query.get<std::string>("value"); + //TODO :-) + return root; +} + +ptree json_to_ptree(const std::string &s); +std::string ptree_to_json(const ptree &p); std::string TopBlock::query(const std::string &args) { //convert json args into property tree - const boost::property_tree::ptree query_args_pt = json_to_ptree(args); + const ptree query = json_to_ptree(args); //dispatch based on path arg - std::string path = query_args_pt.get<std::string>("path"); - boost::property_tree::ptree result; - if (path == "/blocks.json") result = query_blocks(this->get(), query_args_pt); - if (path == "/stats.json") result = query_stats(this->get(), query_args_pt); + std::string path = query.get<std::string>("path"); + ptree result; + if (path == "/blocks.json") result = query_blocks(this->get(), query); + if (path == "/stats.json") result = query_stats(this->get(), query); + if (path == "/props.json") result = query_props(this->get(), query); return ptree_to_json(result); } |