summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grc/python/Block.py3
-rw-r--r--grc/python/Param.py6
-rw-r--r--grc/python/Port.py16
3 files changed, 13 insertions, 12 deletions
diff --git a/grc/python/Block.py b/grc/python/Block.py
index f47f76446..2df2049a4 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 49601f168..2ca1d0ec0 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 80d9fcaae..d6c622c46 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):
"""