made is_virtual_xxx a block level function, used by port and param classes
authorJosh Blum <josh@joshknows.com>
Sat, 29 Aug 2009 04:06:19 +0000 (21:06 -0700)
committerJosh Blum <josh@joshknows.com>
Sat, 29 Aug 2009 04:06:19 +0000 (21:06 -0700)
grc/python/Block.py
grc/python/Param.py
grc/python/Port.py

index f47f764466d8a191f9a251a12b64c10ee5cf6b70..2df2049a4d9b8bfa24dac854148cdcd4e6a02691 100644 (file)
@@ -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
index 49601f1687388e1dae752294348217f7d92a1cde..2ca1d0ec00c3e02a7038539ed05bab5b1023cb4a 100644 (file)
@@ -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
index 80d9fcaae1f2bdbf8afb5b665a788685cb33cbcf..d6c622c461243cc7ad8df0abe80e9ea6824c35f2 100644 (file)
@@ -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):
                """