summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib
diff options
context:
space:
mode:
authorTom Rondeau <tom@trondeau.com>2014-05-03 12:27:08 -0400
committerTom Rondeau <tom@trondeau.com>2014-05-17 17:45:14 -0400
commitfb1d5f822e3a273db88b2087b8d53be67725d232 (patch)
treedbc3694e025b541efa9b88f30eb354bcd7a0c438 /gnuradio-runtime/lib
parent4c2cb19a23a0b608617330bba80dd19cbb0c37dc (diff)
grc: adding advanced tab feature to set a block's alias.
Does not allow for setting individual block aliases underneath a hier_block. runtime: updates block registery to support updating block's alias that's then accessible through alias(). Adds an update_symbolic_name to the block_registry to delete the old key and add the new one. The block_registry only keeps the symbol_name (which never changes during the lifetime of the block) and the latest alias name that was set.
Diffstat (limited to 'gnuradio-runtime/lib')
-rw-r--r--gnuradio-runtime/lib/basic_block.cc27
-rw-r--r--gnuradio-runtime/lib/block.cc2
-rw-r--r--gnuradio-runtime/lib/block_registry.cc20
3 files changed, 39 insertions, 10 deletions
diff --git a/gnuradio-runtime/lib/basic_block.cc b/gnuradio-runtime/lib/basic_block.cc
index 40edf09b01..686c1d6e65 100644
--- a/gnuradio-runtime/lib/basic_block.cc
+++ b/gnuradio-runtime/lib/basic_block.cc
@@ -71,8 +71,17 @@ namespace gr {
void
basic_block::set_block_alias(std::string name)
- {
- global_block_registry.register_symbolic_name(this, name);
+ {
+ // Only keep one alias'd name around for each block. If we don't
+ // have an alias, add it; if we do, update the entry in the
+ // registry.
+ if(alias_set())
+ global_block_registry.update_symbolic_name(this, name);
+ else
+ global_block_registry.register_symbolic_name(this, name);
+
+ // set the block's alias
+ d_symbol_alias = name;
}
// ** Message passing interface **
@@ -131,7 +140,7 @@ namespace gr {
if(!pmt::dict_has_key(d_message_subscribers, port_id)) {
throw std::runtime_error("port does not exist");
}
-
+
pmt::pmt_t currlist = pmt::dict_ref(d_message_subscribers, port_id, pmt::PMT_NIL);
// iterate through subscribers on port
while(pmt::is_pair(currlist)) {
@@ -139,7 +148,7 @@ namespace gr {
pmt::pmt_t block = pmt::car(target);
pmt::pmt_t port = pmt::cdr(target);
-
+
currlist = pmt::cdr(currlist);
basic_block_sptr blk = global_block_registry.block_lookup(block);
//blk->post(msg);
@@ -150,14 +159,14 @@ namespace gr {
// - subscribe to a message port
void
basic_block::message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target){
- if(!pmt::dict_has_key(d_message_subscribers, port_id)){
+ if(!pmt::dict_has_key(d_message_subscribers, port_id)){
std::stringstream ss;
ss << "Port does not exist: \"" << pmt::write_string(port_id) << "\" on block: "
<< pmt::write_string(target) << std::endl;
throw std::runtime_error(ss.str());
}
pmt::pmt_t currlist = pmt::dict_ref(d_message_subscribers,port_id,pmt::PMT_NIL);
-
+
// ignore re-adds of the same target
if(!pmt::list_has(currlist, target))
d_message_subscribers = pmt::dict_add(d_message_subscribers,port_id,pmt::list_add(currlist,target));
@@ -166,13 +175,13 @@ namespace gr {
void
basic_block::message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target)
{
- if(!pmt::dict_has_key(d_message_subscribers, port_id)) {
+ if(!pmt::dict_has_key(d_message_subscribers, port_id)) {
std::stringstream ss;
ss << "Port does not exist: \"" << pmt::write_string(port_id) << "\" on block: "
<< pmt::write_string(target) << std::endl;
throw std::runtime_error(ss.str());
}
-
+
// ignore unsubs of unknown targets
pmt::pmt_t currlist = pmt::dict_ref(d_message_subscribers,port_id,pmt::PMT_NIL);
d_message_subscribers = pmt::dict_add(d_message_subscribers,port_id,pmt::list_rm(currlist,target));
@@ -230,7 +239,7 @@ namespace gr {
return m;
}
- pmt::pmt_t
+ pmt::pmt_t
basic_block::message_subscribers(pmt::pmt_t port)
{
return pmt::dict_ref(d_message_subscribers,port,pmt::PMT_NIL);
diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc
index bdf484e8db..80d59c4fee 100644
--- a/gnuradio-runtime/lib/block.cc
+++ b/gnuradio-runtime/lib/block.cc
@@ -109,7 +109,7 @@ namespace gr {
block::~block()
{
- global_block_registry.unregister_primitive(alias());
+ global_block_registry.unregister_primitive(symbol_name());
}
unsigned
diff --git a/gnuradio-runtime/lib/block_registry.cc b/gnuradio-runtime/lib/block_registry.cc
index c4dc7647d6..5241ef9922 100644
--- a/gnuradio-runtime/lib/block_registry.cc
+++ b/gnuradio-runtime/lib/block_registry.cc
@@ -90,6 +90,26 @@ namespace gr {
d_ref_map = pmt::dict_add(d_ref_map, pmt::intern(name), pmt::make_any(block));
}
+ void
+ block_registry::update_symbolic_name(basic_block* block, std::string name)
+ {
+ gr::thread::scoped_lock guard(d_mutex);
+
+ if(pmt::dict_has_key(d_ref_map, pmt::intern(name))) {
+ throw std::runtime_error("symbol already exists, can not re-use!");
+ }
+
+ // If we don't already have an alias, don't try and delete it.
+ if(block->alias_set()) {
+ // And make sure that the registry has the alias key.
+ // We test both in case the block's and registry ever get out of sync.
+ if(pmt::dict_has_key(d_ref_map, block->alias_pmt())) {
+ d_ref_map = pmt::dict_delete(d_ref_map, block->alias_pmt());
+ }
+ }
+ d_ref_map = pmt::dict_add(d_ref_map, pmt::intern(name), pmt::make_any(block));
+ }
+
basic_block_sptr
block_registry::block_lookup(pmt::pmt_t symbol)
{