diff options
author | Josh Blum | 2013-03-17 15:47:30 -0700 |
---|---|---|
committer | Josh Blum | 2013-03-17 15:47:30 -0700 |
commit | c70c996658138d0f38a1670f073cc327ff5ab920 (patch) | |
tree | 21a869c9df27675f8ef2552746b2109cbdd14a84 /lib/block_props.cpp | |
parent | f637a4081cef9d28d98e209efbd02099c56777a9 (diff) | |
download | sandhi-c70c996658138d0f38a1670f073cc327ff5ab920.tar.gz sandhi-c70c996658138d0f38a1670f073cc327ff5ab920.tar.bz2 sandhi-c70c996658138d0f38a1670f073cc327ff5ab920.zip |
gras: property tweaks and c++ unit tests
Diffstat (limited to 'lib/block_props.cpp')
-rw-r--r-- | lib/block_props.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/block_props.cpp b/lib/block_props.cpp index bba9441..99edce7 100644 --- a/lib/block_props.cpp +++ b/lib/block_props.cpp @@ -8,18 +8,20 @@ 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, const Theron::Address from ) { - ASSERT(this->prio_count.Load() != 0); - this->prio_count.Decrement(); - + //setup reply PropAccessMessage reply; reply.set = not message.set; reply.key = message.key; + //try to call the property bound method PropertyRegistrySptr pr = prop_registry[message.key]; if (not pr) reply.error = "no property registered for key: " + message.key; else try @@ -36,14 +38,14 @@ void BlockActor::handle_prop_access( reply.error = "unknown error"; } + //send the reply this->Send(reply, from); //ACK + this->highPrioAck(); } -void Block::_register_property(const std::string &key, PropertyRegistrySptr pr) -{ - (*this)->block->prop_registry[key] = pr; -} - +/*********************************************************************** + * A special receiver to handle the property access result + **********************************************************************/ struct PropAccessReceiver : Theron::Receiver { PropAccessReceiver(void) @@ -59,6 +61,9 @@ struct PropAccessReceiver : Theron::Receiver PropAccessMessage message; }; +/*********************************************************************** + * Handle the get and set calls from the user's call-stack + **********************************************************************/ PMCC BlockActor::prop_access_dispatcher(const std::string &key, const PMCC &value, const bool set) { PropAccessReceiver receiver; @@ -67,7 +72,7 @@ PMCC BlockActor::prop_access_dispatcher(const std::string &key, const PMCC &valu message.key = key; message.value = value; this->Push(message, receiver.GetAddress()); - this->prio_count.Increment(); + this->highPrioPreNotify(); receiver.Wait(); if (not receiver.message.error.empty()) { @@ -76,6 +81,11 @@ PMCC BlockActor::prop_access_dispatcher(const std::string &key, const PMCC &valu return receiver.message.value; } +void Block::_register_property(const std::string &key, PropertyRegistrySptr pr) +{ + (*this)->block->prop_registry[key] = pr; +} + void Block::_set_property(const std::string &key, const PMCC &value) { (*this)->block->prop_access_dispatcher(key, value, true); |