diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/block_props.cpp | 10 | ||||
-rw-r--r-- | lib/gras_impl/block_actor.hpp | 8 | ||||
-rw-r--r-- | lib/top_block_query.cpp | 33 |
3 files changed, 43 insertions, 8 deletions
diff --git a/lib/block_props.cpp b/lib/block_props.cpp index f32dc69..5d536bb 100644 --- a/lib/block_props.cpp +++ b/lib/block_props.cpp @@ -45,10 +45,8 @@ void BlockActor::handle_prop_access( PMCC Block::_handle_prop_access(const std::string &key, const PMCC &value, const bool set) { - PropertyRegistrySptr pr = (set)? - (*this)->block->setter_registry[key] : - (*this)->block->getter_registry[key] - ; + const PropertyRegistryPair &pair = (*this)->block->property_registry[key]; + PropertyRegistrySptr pr = (set)? pair.setter : pair.getter; if (not pr) throw std::invalid_argument("no property registered for key: " + key); if (set) { @@ -99,12 +97,12 @@ static PMCC prop_access_dispatcher(ActorType &actor, const std::string &key, con void Block::_register_getter(const std::string &key, void *pr) { - (*this)->block->getter_registry[key].reset(reinterpret_cast<PropertyRegistry *>(pr)); + (*this)->block->property_registry[key].getter.reset(reinterpret_cast<PropertyRegistry *>(pr)); } void Block::_register_setter(const std::string &key, void *pr) { - (*this)->block->setter_registry[key].reset(reinterpret_cast<PropertyRegistry *>(pr)); + (*this)->block->property_registry[key].setter.reset(reinterpret_cast<PropertyRegistry *>(pr)); } void Block::_set_property(const std::string &key, const PMCC &value) diff --git a/lib/gras_impl/block_actor.hpp b/lib/gras_impl/block_actor.hpp index bc4ecdd..269674c 100644 --- a/lib/gras_impl/block_actor.hpp +++ b/lib/gras_impl/block_actor.hpp @@ -24,6 +24,11 @@ namespace gras { typedef boost::shared_ptr<PropertyRegistry> PropertyRegistrySptr; +struct PropertyRegistryPair +{ + PropertyRegistrySptr setter; + PropertyRegistrySptr getter; +}; struct BlockActor : Apology::Worker { @@ -163,8 +168,7 @@ struct BlockActor : Apology::Worker std::vector<std::vector<OutputHintMessage> > output_allocation_hints; //property stuff - std::map<std::string, PropertyRegistrySptr> getter_registry; - std::map<std::string, PropertyRegistrySptr> setter_registry; + std::map<std::string, PropertyRegistryPair> property_registry; BlockStats stats; }; diff --git a/lib/top_block_query.cpp b/lib/top_block_query.cpp index 29d3bb0..3905faf 100644 --- a/lib/top_block_query.cpp +++ b/lib/top_block_query.cpp @@ -155,6 +155,38 @@ static std::string query_stats(ElementImpl *self, const boost::property_tree::pt return my_write_json(root); } +static std::string query_props(ElementImpl *self, const boost::property_tree::ptree &) +{ + boost::property_tree::ptree root; + boost::property_tree::ptree e; + BOOST_FOREACH(Apology::Worker *worker, self->executor->get_workers()) + { + BlockActor *block = dynamic_cast<BlockActor *>(worker); + boost::property_tree::ptree prop_e; + typedef std::pair<std::string, PropertyRegistryPair> PropRegistryKVP; + BOOST_FOREACH(const PropRegistryKVP &p, block->property_registry) + { + boost::property_tree::ptree attrs; + if (p.second.setter) + { + boost::property_tree::ptree type; + type.put_value(p.second.setter->type().name()); + attrs.push_back(std::make_pair("set_type", type)); + } + if (p.second.getter) + { + boost::property_tree::ptree type; + type.put_value(p.second.getter->type().name()); + attrs.push_back(std::make_pair("get_type", type)); + } + prop_e.push_back(std::make_pair(p.first, attrs)); + } + e.push_back(std::make_pair(block->block_ptr->to_string(), prop_e)); + } + root.push_back(std::make_pair("props", e)); + return my_write_json(root); +} + std::string TopBlock::query(const std::string &args) { //why the fuck does no OS ever patch boost when there is a bug @@ -168,5 +200,6 @@ std::string TopBlock::query(const std::string &args) std::string path = query_args_pt.get<std::string>("args.path"); if (path == "/blocks.json") return query_blocks(this->get(), query_args_pt); if (path == "/stats.json") return query_stats(this->get(), query_args_pt); + if (path == "/props.json") return query_props(this->get(), query_args_pt); return ""; } |