diff options
Diffstat (limited to 'gnuradio-runtime/lib')
-rw-r--r-- | gnuradio-runtime/lib/basic_block.cc | 27 | ||||
-rw-r--r-- | gnuradio-runtime/lib/block.cc | 2 | ||||
-rw-r--r-- | gnuradio-runtime/lib/block_registry.cc | 20 | ||||
-rw-r--r-- | gnuradio-runtime/lib/flowgraph.cc | 8 | ||||
-rwxr-xr-x | gnuradio-runtime/lib/pmt/generate_unv.py | 1 | ||||
-rw-r--r-- | gnuradio-runtime/lib/pmt/pmt_int.h | 1 | ||||
-rw-r--r-- | gnuradio-runtime/lib/pmt/pmt_io.cc | 13 | ||||
-rw-r--r-- | gnuradio-runtime/lib/pmt/unv_template.cc.t | 6 | ||||
-rw-r--r-- | gnuradio-runtime/lib/pmt/unv_template.h.t | 1 |
9 files changed, 65 insertions, 14 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 9e4fcf5cca..6309bca9b1 100644 --- a/gnuradio-runtime/lib/block.cc +++ b/gnuradio-runtime/lib/block.cc @@ -111,7 +111,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) { diff --git a/gnuradio-runtime/lib/flowgraph.cc b/gnuradio-runtime/lib/flowgraph.cc index 3d8dfea65a..abe51f741d 100644 --- a/gnuradio-runtime/lib/flowgraph.cc +++ b/gnuradio-runtime/lib/flowgraph.cc @@ -155,8 +155,14 @@ namespace gr { if(FLOWGRAPH_DEBUG) std::cout << "check_valid_port( " << e.block() << ", " << e.port() << ")\n"; - if(!e.block()->has_msg_port(e.port())) + if(!e.block()->has_msg_port(e.port())) { + const gr::basic_block::msg_queue_map_t& msg_map = e.block()->get_msg_map(); + std::cout << "Could not find port: " << e.port() << " in:" << std::endl; + for (gr::basic_block::msg_queue_map_t::const_iterator it = msg_map.begin(); it != msg_map.end(); ++it) + std::cout << it->first << std::endl; + std::cout << std::endl; throw std::invalid_argument("invalid msg port in connect() or disconnect()"); + } } void diff --git a/gnuradio-runtime/lib/pmt/generate_unv.py b/gnuradio-runtime/lib/pmt/generate_unv.py index 7562df46f8..6218099fc1 100755 --- a/gnuradio-runtime/lib/pmt/generate_unv.py +++ b/gnuradio-runtime/lib/pmt/generate_unv.py @@ -76,6 +76,7 @@ includes = """ #endif #include <vector> #include <pmt/pmt.h> +#include <boost/lexical_cast.hpp> #include "pmt_int.h" """ diff --git a/gnuradio-runtime/lib/pmt/pmt_int.h b/gnuradio-runtime/lib/pmt/pmt_int.h index ca90c5a475..49bde52063 100644 --- a/gnuradio-runtime/lib/pmt/pmt_int.h +++ b/gnuradio-runtime/lib/pmt/pmt_int.h @@ -239,6 +239,7 @@ public: virtual void *uniform_writable_elements(size_t &len) = 0; virtual size_t length() const = 0; virtual size_t itemsize() const = 0; + virtual const std::string string_ref(size_t k) const { return std::string("not implemented"); } }; #include "pmt_unv_int.h" diff --git a/gnuradio-runtime/lib/pmt/pmt_io.cc b/gnuradio-runtime/lib/pmt/pmt_io.cc index 17bdee408f..e63bae4994 100644 --- a/gnuradio-runtime/lib/pmt/pmt_io.cc +++ b/gnuradio-runtime/lib/pmt/pmt_io.cc @@ -110,9 +110,16 @@ write(pmt_t obj, std::ostream &port) port << "#<dict>"; } else if (is_uniform_vector(obj)){ - // FIXME - // port << "#<uniform-vector " << obj << ">"; - port << "#<uniform-vector>"; + port << "#["; + size_t len = length(obj); + if (len) + { + pmt_uniform_vector *uv = static_cast<pmt_uniform_vector*>(obj.get()); + port << uv->string_ref(0); + for (size_t i = 1; i < len; i++) + port << " " << uv->string_ref(i); + } + port << "]"; } else { error: diff --git a/gnuradio-runtime/lib/pmt/unv_template.cc.t b/gnuradio-runtime/lib/pmt/unv_template.cc.t index 8678894973..c8020e7de2 100644 --- a/gnuradio-runtime/lib/pmt/unv_template.cc.t +++ b/gnuradio-runtime/lib/pmt/unv_template.cc.t @@ -138,4 +138,10 @@ const std::vector< @TYPE@ > return _@TAG@vector(vector)->writable_elements(len); } +const std::string +pmt_@TAG@vector::string_ref(size_t k) const +{ + return boost::lexical_cast< std::string, @TYPE@ > (ref(k)); +} + } /* namespace pmt */ diff --git a/gnuradio-runtime/lib/pmt/unv_template.h.t b/gnuradio-runtime/lib/pmt/unv_template.h.t index 93ca684463..ab5c163570 100644 --- a/gnuradio-runtime/lib/pmt/unv_template.h.t +++ b/gnuradio-runtime/lib/pmt/unv_template.h.t @@ -21,4 +21,5 @@ public: @TYPE@ *writable_elements(size_t &len); const void *uniform_elements(size_t &len); void *uniform_writable_elements(size_t &len); + virtual const std::string string_ref(size_t k) const; }; |