commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 27/57: grc: adding advanced tab feature to


From: git
Subject: [Commit-gnuradio] [gnuradio] 27/57: grc: adding advanced tab feature to set a block's alias.
Date: Wed, 21 May 2014 03:10:27 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

trondeau pushed a commit to branch master
in repository gnuradio.

commit fb1d5f822e3a273db88b2087b8d53be67725d232
Author: Tom Rondeau <address@hidden>
Date:   Sat May 3 12:27:08 2014 -0400

    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/include/gnuradio/basic_block.h    | 27 ++++++++
 gnuradio-runtime/include/gnuradio/block_registry.h |  3 +-
 gnuradio-runtime/lib/basic_block.cc                | 27 +++++---
 gnuradio-runtime/lib/block.cc                      |  2 +-
 gnuradio-runtime/lib/block_registry.cc             | 20 ++++++
 grc/base/Block.py                                  | 71 ++++++++++++----------
 grc/python/flow_graph.tmpl                         |  4 +-
 7 files changed, 111 insertions(+), 43 deletions(-)

diff --git a/gnuradio-runtime/include/gnuradio/basic_block.h 
b/gnuradio-runtime/include/gnuradio/basic_block.h
index 6977586..28552a4 100644
--- a/gnuradio-runtime/include/gnuradio/basic_block.h
+++ b/gnuradio-runtime/include/gnuradio/basic_block.h
@@ -144,14 +144,41 @@ namespace gr {
     virtual ~basic_block();
     long unique_id() const { return d_unique_id; }
     long symbolic_id() const { return d_symbolic_id; }
+
+    /*! The name of the block */
     std::string name() const { return d_name; }
+
+    /*!
+     * The sybolic name of the block, which is used in the
+     * block_registry. The name is assigned by the block's constructor
+     * and never changes during the life of the block.
+     */
     std::string symbol_name() const { return d_symbol_name; }
+
     gr::io_signature::sptr input_signature() const  { return 
d_input_signature; }
     gr::io_signature::sptr output_signature() const { return 
d_output_signature; }
     basic_block_sptr to_basic_block(); // Needed for Python type coercion
+
+    /*!
+     * True if the block has an alias (see set_block_alias).
+     */
     bool alias_set() { return !d_symbol_alias.empty(); }
+
+    /*!
+     * Returns the block's alias as a string.
+     */
     std::string alias(){ return alias_set()?d_symbol_alias:symbol_name(); }
+
+    /*!
+     * Returns the block's alias as PMT.
+     */
     pmt::pmt_t alias_pmt(){ return pmt::intern(alias()); }
+
+    /*!
+     * Set's a new alias for the block; also adds an entry into the
+     * block_registry to get the block using either the alias or the
+     * original symbol name.
+     */
     void set_block_alias(std::string name);
 
     // ** Message passing interface **
diff --git a/gnuradio-runtime/include/gnuradio/block_registry.h 
b/gnuradio-runtime/include/gnuradio/block_registry.h
index 49f0b72..86e5528 100644
--- a/gnuradio-runtime/include/gnuradio/block_registry.h
+++ b/gnuradio-runtime/include/gnuradio/block_registry.h
@@ -44,9 +44,10 @@ namespace gr {
 
     std::string register_symbolic_name(basic_block* block);
     void register_symbolic_name(basic_block* block, std::string name);
+    void update_symbolic_name(basic_block* block, std::string name);
 
     basic_block_sptr block_lookup(pmt::pmt_t symbol);
- 
+
     void register_primitive(std::string blk, gr::block* ref);
     void unregister_primitive(std::string blk);
     void notify_blk(std::string blk);
diff --git a/gnuradio-runtime/lib/basic_block.cc 
b/gnuradio-runtime/lib/basic_block.cc
index 40edf09..686c1d6 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 bdf484e..80d59c4 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 c4dc764..5241ef9 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)
   {
diff --git a/grc/base/Block.py b/grc/base/Block.py
index 5a91810..a14ffd9 100644
--- a/grc/base/Block.py
+++ b/grc/base/Block.py
@@ -56,11 +56,11 @@ class Block(Element):
     def __init__(self, flow_graph, n):
         """
         Make a new block from nested data.
-        
+
         Args:
             flow: graph the parent element
             n: the nested odict
-        
+
         Returns:
             block a new block
         """
@@ -141,6 +141,17 @@ class Block(Element):
                                      and (self._key != "pad_source") \
                                      and (self._key != "pad_sink"))
 
+        if is_not_virtual_or_pad:
+            self.get_params().append(self.get_parent().get_parent().Param(
+                block=self,
+                n=odict({'name': 'Block Alias',
+                         'key': 'alias',
+                         'type': 'string',
+                         'hide': 'part',
+                         'tab': ADVANCED_PARAM_TAB
+                     })
+            ))
+
         if (len(sources) or len(sinks)) and is_not_virtual_or_pad:
             self.get_params().append(self.get_parent().get_parent().Param(
                     block=self,
@@ -177,7 +188,7 @@ class Block(Element):
     def back_ofthe_bus(self, portlist):
         portlist.sort(key=lambda a: a.get_type() == 'bus');
 
-    def filter_bus_port(self, ports): 
+    def filter_bus_port(self, ports):
         buslist = [i for i in ports if i.get_type() == 'bus'];
         if len(buslist) == 0:
             return ports;
@@ -187,7 +198,7 @@ class Block(Element):
     def get_enabled(self):
         """
         Get the enabled state of the block.
-        
+
         Returns:
             true for enabled
         """
@@ -197,7 +208,7 @@ class Block(Element):
     def set_enabled(self, enabled):
         """
         Set the enabled state of the block.
-        
+
         Args:
             enabled: true for enabled
         """
@@ -225,11 +236,11 @@ class Block(Element):
     def get_param_keys(self): return _get_keys(self._params)
     def get_param(self, key): return _get_elem(self._params, key)
     def get_params(self): return self._params
-    def has_param(self, key):   
-        try: 
-            _get_elem(self._params, key); 
-            return True; 
-        except: 
+    def has_param(self, key):
+        try:
+            _get_elem(self._params, key);
+            return True;
+        except:
             return False;
 
     ##############################################
@@ -246,7 +257,7 @@ class Block(Element):
     def get_source_keys(self): return _get_keys(self._sources)
     def get_source(self, key): return _get_elem(self._sources, key)
     def get_sources(self): return self._sources
-    def get_sources_gui(self): return 
self.filter_bus_port(self.get_sources()); 
+    def get_sources_gui(self): return self.filter_bus_port(self.get_sources());
 
     def get_connections(self):
         return sum([port.get_connections() for port in self.get_ports()], [])
@@ -254,10 +265,10 @@ class Block(Element):
     def resolve_dependencies(self, tmpl):
         """
         Resolve a paramater dependency with cheetah templates.
-        
+
         Args:
             tmpl: the string with dependencies
-        
+
         Returns:
             the resolved value
         """
@@ -273,10 +284,10 @@ class Block(Element):
     def type_controller_modify(self, direction):
         """
         Change the type controller.
-        
+
         Args:
             direction: +1 or -1
-        
+
         Returns:
             true for change
         """
@@ -302,10 +313,10 @@ class Block(Element):
     def port_controller_modify(self, direction):
         """
         Change the port controller.
-        
+
         Args:
             direction: +1 or -1
-        
+
         Returns:
             true for change
         """
@@ -323,7 +334,7 @@ class Block(Element):
 
         struct = [range(len(get_p()))];
         if True in map(lambda a: isinstance(a.get_nports(), int), get_p()):
-                
+
 
             structlet = [];
             last = 0;
@@ -332,7 +343,7 @@ class Block(Element):
                 last = structlet[-1] + 1;
                 struct = [structlet];
         if bus_structure:
-                
+
             struct = bus_structure
 
         self.current_bus_structure[direc] = struct;
@@ -353,10 +364,10 @@ class Block(Element):
             for connect in elt.get_connections():
                 self.get_parent().remove_element(connect);
 
-        
-        
-        
-        
+
+
+
+
 
         if (not 'bus' in map(lambda a: a.get_type(), get_p())) and 
len(get_p()) > 0:
 
@@ -364,16 +375,16 @@ class Block(Element):
             self.current_bus_structure[direc] = struct;
             if get_p()[0].get_nports():
                 n['nports'] = str(1);
-        
+
             for i in range(len(struct)):
                 n['key'] = str(len(get_p()));
                 n = odict(n);
                 port = self.get_parent().get_parent().Port(block=self, n=n, 
dir=direc);
                 get_p().append(port);
-                
 
-            
-                
+
+
+
         elif 'bus' in map(lambda a: a.get_type(), get_p()):
             for elt in get_p_gui():
                 get_p().remove(elt);
@@ -384,7 +395,7 @@ class Block(Element):
     def export_data(self):
         """
         Export this block's params to nested data.
-        
+
         Returns:
             a nested data odict
         """
@@ -405,7 +416,7 @@ class Block(Element):
         call rewrite, and repeat the load until the params stick.
         This call to rewrite will also create any dynamic ports
         that are needed for the connections creation phase.
-        
+
         Args:
             n: the nested data odict
         """
@@ -434,5 +445,3 @@ class Block(Element):
         elif len(bussrcs) > 0:
             self.bussify({'name':'bus','type':'bus'}, 'source')
             self.bussify({'name':'bus','type':'bus'}, 'source')
-
-
diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl
index 7c6998a..4cd7cc0 100644
--- a/grc/python/flow_graph.tmpl
+++ b/grc/python/flow_graph.tmpl
@@ -161,6 +161,9 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', 
'.join($size_strs))])
         $indent($blk.get_make())
     #else
         self.$blk.get_id() = $indent($blk.get_make())
+        #if $blk.has_param('alias') and $blk.get_param('alias').get_evaluated()
+        
(self.$blk.get_id()).set_block_alias("$blk.get_param('alias').get_evaluated()")
+        #end if
         #if $blk.has_param('affinity') and 
$blk.get_param('affinity').get_evaluated()
         
(self.$blk.get_id()).set_processor_affinity($blk.get_param('affinity').get_evaluated())
         #end if
@@ -362,4 +365,3 @@ if __name__ == '__main__':
     tb.wait()
     #end if
 #end if
-



reply via email to

[Prev in Thread] Current Thread [Next in Thread]