From fc80d2c0acec4f668b58a05bd5a3a06b0a2a2280 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 5 Jul 2013 18:50:01 -0700 Subject: gras: begin replacing set/get with callable --- lib/block_props.cpp | 68 ++++++++++++------------------------------- lib/gras_impl/block_actor.hpp | 4 +-- lib/gras_impl/block_data.hpp | 10 ------- lib/gras_impl/messages.hpp | 8 ++--- lib/register_messages.cpp | 2 +- lib/top_block_query.cpp | 4 +++ 6 files changed, 30 insertions(+), 66 deletions(-) (limited to 'lib') diff --git a/lib/block_props.cpp b/lib/block_props.cpp index ae687be..172282d 100644 --- a/lib/block_props.cpp +++ b/lib/block_props.cpp @@ -5,26 +5,23 @@ using namespace gras; -PropertyRegistry::PropertyRegistry(void){} -PropertyRegistry::~PropertyRegistry(void){} - /*********************************************************************** * The actual thread-safe implementation of property handling **********************************************************************/ -void BlockActor::handle_prop_access( - const PropAccessMessage &message, +void BlockActor::handle_callable( + const CallableMessage &message, const Theron::Address from ) { //setup reply - PropAccessMessage reply; - reply.set = not message.set; + CallableMessage reply; reply.key = message.key; + reply.args = NULL; //call into the handler overload to do the property access try { - reply.value = data->block->_handle_prop_access(message.key, message.value, message.set); + reply.ret = data->block->_handle_call_ts(message.key, message.args); } catch (const std::exception &e) { @@ -43,73 +40,46 @@ void BlockActor::handle_prop_access( this->Send(SelfKickMessage(), this->GetAddress()); } -PMCC Block::_handle_prop_access(const std::string &key, const PMCC &value, const bool set) +PMCC Block::_handle_call_ts(const std::string &key, const PMCC *args) { - const PropertyRegistryPair &pair = (*this)->block_data->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) - { - pr->set(value); - return PMCC(); - } - return pr->get(); + //got here, so we call the base class unless this got overloaded + return Callable::_handle_call(key, args); } /*********************************************************************** * A special receiver to handle the property access result **********************************************************************/ -struct PropAccessReceiver : Theron::Receiver +struct CallableReceiver : Theron::Receiver { - PropAccessReceiver(void) + CallableReceiver(void) { - this->RegisterHandler(this, &PropAccessReceiver::handle_prop_access); + this->RegisterHandler(this, &CallableReceiver::handle_callable); } - void handle_prop_access(const PropAccessMessage &msg, const Theron::Address) + void handle_callable(const CallableMessage &msg, const Theron::Address) { this->message = msg; } - PropAccessMessage message; + CallableMessage message; }; /*********************************************************************** * Handle the get and set calls from the user's call-stack **********************************************************************/ -static PMCC prop_access_dispatcher(boost::shared_ptr actor, const std::string &key, const PMCC &value, const bool set) +PMCC Block::_handle_call(const std::string &key, const PMCC *args) { - PropAccessReceiver receiver; - PropAccessMessage message; + CallableReceiver receiver; + CallableMessage message; + boost::shared_ptr actor = (*this)->block_actor; message.prio_token = actor->prio_token; - message.set = set; message.key = key; - message.value = value; + message.args = (PMCC *)args; actor->GetFramework().Send(message, receiver.GetAddress(), actor->GetAddress()); receiver.Wait(); if (not receiver.message.error.empty()) { throw std::runtime_error(receiver.message.error); } - return receiver.message.value; -} - -void Block::_register_getter(const std::string &key, void *pr) -{ - (*this)->block_data->property_registry[key].getter.reset(reinterpret_cast(pr)); -} - -void Block::_register_setter(const std::string &key, void *pr) -{ - (*this)->block_data->property_registry[key].setter.reset(reinterpret_cast(pr)); -} - -void Block::_set_property(const std::string &key, const PMCC &value) -{ - prop_access_dispatcher((*this)->block_actor, key, value, true); -} - -PMCC Block::_get_property(const std::string &key) -{ - return prop_access_dispatcher((*this)->block_actor, key, PMCC(), false); + return receiver.message.ret; } diff --git a/lib/gras_impl/block_actor.hpp b/lib/gras_impl/block_actor.hpp index 9a5c7b8..cfbc2c0 100644 --- a/lib/gras_impl/block_actor.hpp +++ b/lib/gras_impl/block_actor.hpp @@ -52,7 +52,7 @@ struct BlockActor : Theron::Actor this->RegisterHandler(this, &BlockActor::handle_output_alloc); this->RegisterHandler(this, &BlockActor::handle_output_update); - this->RegisterHandler(this, &BlockActor::handle_prop_access); + this->RegisterHandler(this, &BlockActor::handle_callable); this->RegisterHandler(this, &BlockActor::handle_self_kick); this->RegisterHandler(this, &BlockActor::handle_get_stats); } @@ -82,7 +82,7 @@ struct BlockActor : Theron::Actor void handle_output_alloc(const OutputAllocMessage &, const Theron::Address); void handle_output_update(const OutputUpdateMessage &, const Theron::Address); - void handle_prop_access(const PropAccessMessage &, const Theron::Address); + void handle_callable(const CallableMessage &, const Theron::Address); void handle_self_kick(const SelfKickMessage &, const Theron::Address); void handle_get_stats(const GetStatsMessage &, const Theron::Address); diff --git a/lib/gras_impl/block_data.hpp b/lib/gras_impl/block_data.hpp index cbc657e..d6af53d 100644 --- a/lib/gras_impl/block_data.hpp +++ b/lib/gras_impl/block_data.hpp @@ -18,13 +18,6 @@ namespace gras { -typedef boost::shared_ptr PropertyRegistrySptr; -struct PropertyRegistryPair -{ - PropertyRegistrySptr setter; - PropertyRegistrySptr getter; -}; - enum BlockState { BLOCK_STATE_INIT, @@ -80,9 +73,6 @@ struct BlockData std::vector > output_allocation_hints; - //property stuff - std::map property_registry; - BlockStats stats; }; diff --git a/lib/gras_impl/messages.hpp b/lib/gras_impl/messages.hpp index a959bef..88d0d79 100644 --- a/lib/gras_impl/messages.hpp +++ b/lib/gras_impl/messages.hpp @@ -131,12 +131,12 @@ struct OutputUpdateMessage //-- do not ack //---------------------------------------------------------------------- -struct PropAccessMessage +struct CallableMessage { Token prio_token; - bool set; std::string key; - PMCC value; + PMCC *args; + PMCC ret; std::string error; }; @@ -182,7 +182,7 @@ THERON_DECLARE_REGISTERED_MESSAGE(gras::OutputHintMessage); THERON_DECLARE_REGISTERED_MESSAGE(gras::OutputAllocMessage); THERON_DECLARE_REGISTERED_MESSAGE(gras::OutputUpdateMessage); -THERON_DECLARE_REGISTERED_MESSAGE(gras::PropAccessMessage); +THERON_DECLARE_REGISTERED_MESSAGE(gras::CallableMessage); THERON_DECLARE_REGISTERED_MESSAGE(gras::SelfKickMessage); THERON_DECLARE_REGISTERED_MESSAGE(gras::GetStatsMessage); diff --git a/lib/register_messages.cpp b/lib/register_messages.cpp index 058f308..eda73ce 100644 --- a/lib/register_messages.cpp +++ b/lib/register_messages.cpp @@ -26,6 +26,6 @@ THERON_DEFINE_REGISTERED_MESSAGE(gras::OutputHintMessage); THERON_DEFINE_REGISTERED_MESSAGE(gras::OutputAllocMessage); THERON_DEFINE_REGISTERED_MESSAGE(gras::OutputUpdateMessage); -THERON_DEFINE_REGISTERED_MESSAGE(gras::PropAccessMessage); +THERON_DEFINE_REGISTERED_MESSAGE(gras::CallableMessage); THERON_DEFINE_REGISTERED_MESSAGE(gras::SelfKickMessage); THERON_DEFINE_REGISTERED_MESSAGE(gras::GetStatsMessage); diff --git a/lib/top_block_query.cpp b/lib/top_block_query.cpp index 7707e32..7a5e13e 100644 --- a/lib/top_block_query.cpp +++ b/lib/top_block_query.cpp @@ -36,6 +36,7 @@ static ptree query_blocks(ElementImpl *self, const ptree &) { BlockActor *actor = dynamic_cast(w->get_actor()); ptree prop_e; + /* typedef std::pair PropRegistryKVP; BOOST_FOREACH(const PropRegistryKVP &p, actor->data->property_registry) { @@ -56,6 +57,7 @@ static ptree query_blocks(ElementImpl *self, const ptree &) block_attrs.push_back(std::make_pair(p.first, prop_attrs)); prop_e.push_back(std::make_pair("props", block_attrs)); } + */ e.push_back(std::make_pair(actor->data->block->get_uid(), prop_e)); } root.push_back(std::make_pair("blocks", e)); @@ -182,6 +184,7 @@ static ptree query_props(ElementImpl *self, const ptree &query) { BlockActor *actor = dynamic_cast(w->get_actor()); if (actor->data->block->get_uid() != block_id) continue; + /* if (set) { const std::type_info &t = actor->data->property_registry[prop_key].setter->type(); @@ -196,6 +199,7 @@ static ptree query_props(ElementImpl *self, const ptree &query) root.push_back(std::make_pair("key", query.get_child("key"))); root.push_back(std::make_pair("value", v)); } + */ } return root; } -- cgit