From fb1d5f822e3a273db88b2087b8d53be67725d232 Mon Sep 17 00:00:00 2001
From: Tom Rondeau <tom@trondeau.com>
Date: Sat, 3 May 2014 12:27:08 -0400
Subject: 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.
---
 gnuradio-runtime/lib/basic_block.cc | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

(limited to 'gnuradio-runtime/lib/basic_block.cc')

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);
-- 
cgit v1.2.3