From: Josh Blum Date: Sat, 29 Aug 2009 04:06:19 +0000 (-0700) Subject: made is_virtual_xxx a block level function, used by port and param classes X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=cb794a7c8703ea06a9bce110fc1041140f25e8e6;p=debian%2Fgnuradio made is_virtual_xxx a block level function, used by port and param classes --- diff --git a/grc/python/Block.py b/grc/python/Block.py index f47f7644..2df2049a 100644 --- a/grc/python/Block.py +++ b/grc/python/Block.py @@ -23,6 +23,9 @@ import extract_category class Block(_Block): + def is_virtual_sink(self): return self.get_key() == 'virtual_sink' + def is_virtual_source(self): return self.get_key() == 'virtual_source' + ##for make source to keep track of indexes _source_count = 0 ##for make sink to keep track of indexes diff --git a/grc/python/Param.py b/grc/python/Param.py index 49601f16..2ca1d0ec 100644 --- a/grc/python/Param.py +++ b/grc/python/Param.py @@ -322,15 +322,15 @@ class Param(_Param): elif t == 'stream_id': #get a list of all stream ids used in the virtual sinks ids = [param.get_value() for param in filter( - lambda p: p.get_parent().get_key() == 'virtual_sink', + lambda p: p.get_parent().is_virtual_sink(), self.get_all_params(t), )] #check that the virtual sink's stream id is unique - if self.get_parent().get_key() == 'virtual_sink': + if self.get_parent().is_virtual_sink(): try: assert ids.count(v) <= 1 #id should only appear once, or zero times if block is disabled except: raise Exception, 'Stream ID "%s" is not unique.'%v #check that the virtual source's steam id is found - if self.get_parent().get_key() == 'virtual_source': + if self.get_parent().is_virtual_source(): try: assert v in ids except: raise Exception, 'Stream ID "%s" is not found.'%v return v diff --git a/grc/python/Port.py b/grc/python/Port.py index 80d9fcaa..d6c622c4 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -34,14 +34,14 @@ def _get_source_from_virtual_source_port(vsp, traversed=[]): Recursively resolve source ports over the virtual connections. Keep track of traversed sources to avoid recursive loops. """ - if not vsp.is_virtual_source(): return vsp + if not vsp.get_parent().is_virtual_source(): return vsp if vsp in traversed: raise Exception, 'Loop found when resolving virtual source %s'%vsp try: return _get_source_from_virtual_source_port( _get_source_from_virtual_sink_port( - filter( + filter(#get all virtual sinks with a matching stream id lambda vs: vs.get_param('stream_id').get_value() == vsp.get_parent().get_param('stream_id').get_value(), - filter( - lambda b: b.get_key() == 'virtual_sink', + filter(#get all enabled blocks that are also virtual sinks + lambda b: b.is_virtual_sink(), vsp.get_parent().get_parent().get_enabled_blocks(), ), )[0].get_sink(vsp.get_key()) @@ -98,7 +98,7 @@ class Port(_Port): Handle the port cloning for virtual blocks. """ _Port.rewrite(self) - if self.is_virtual_sink() or self.is_virtual_source(): + if self.get_parent().is_virtual_sink() or self.get_parent().is_virtual_source(): try: #clone type and vlen source = self.resolve_virtual_source() self._type = str(source.get_type()) @@ -107,11 +107,9 @@ class Port(_Port): self._type = '' self._vlen = '' - def is_virtual_sink(self): return self.get_parent().get_key() == 'virtual_sink' - def is_virtual_source(self): return self.get_parent().get_key() == 'virtual_source' def resolve_virtual_source(self): - if self.is_virtual_sink(): return _get_source_from_virtual_sink_port(self) - if self.is_virtual_source(): return _get_source_from_virtual_source_port(self) + if self.get_parent().is_virtual_sink(): return _get_source_from_virtual_sink_port(self) + if self.get_parent().is_virtual_source(): return _get_source_from_virtual_source_port(self) def get_vlen(self): """