Removed Source and Sink classes as Port subclasses.
authorJosh Blum <josh@joshknows.com>
Mon, 17 Aug 2009 07:54:11 +0000 (00:54 -0700)
committerJosh Blum <josh@joshknows.com>
Mon, 17 Aug 2009 07:54:11 +0000 (00:54 -0700)
A port can be a source or a sink based on the dir parameter.

grc/base/Block.py
grc/base/Platform.py
grc/base/Port.py
grc/gui/Platform.py
grc/gui/Port.py
grc/python/Platform.py
grc/python/Port.py

index d5e1047852b7df5bfcd71b89135483debc183f18..82d27656785609e3b8eb12b7e68a85b2e12f0380 100644 (file)
@@ -98,7 +98,7 @@ class Block(Element):
                        self.get_params().append(param)
                #create the source objects
                self._sources = list()
-               for source in map(lambda n: self.get_parent().get_parent().Source(self, n), sources):
+               for source in map(lambda n: self.get_parent().get_parent().Port(self, n, dir='source'), sources):
                        key = source.get_key()
                        #test against repeated keys
                        try: assert key not in self.get_source_keys()
@@ -107,7 +107,7 @@ class Block(Element):
                        self.get_sources().append(source)
                #create the sink objects
                self._sinks = list()
-               for sink in map(lambda n: self.get_parent().get_parent().Sink(self, n), sinks):
+               for sink in map(lambda n: self.get_parent().get_parent().Port(self, n, dir='sink'), sinks):
                        key = sink.get_key()
                        #test against repeated keys
                        try: assert key not in self.get_sink_keys()
index 02d6d2319257e969c1b8b4f151b02556698df6ab..db7ade9a3a941f097c0873ae0295e106e27e024c 100644 (file)
@@ -171,6 +171,5 @@ class Platform(_Element):
        FlowGraph = _FlowGraph
        Connection = _Connection
        Block = _Block
-       Source = _Port
-       Sink = _Port
+       Port = _Port
        Param = _Param
index f4e8e5e1fb2a6f648aef6118b545b5a9e0d3354d..8e60d50931c3e91f60203c6d3c93c9d911c472f4 100644 (file)
@@ -24,22 +24,20 @@ class Port(Element):
        ##possible port types
        TYPES = []
 
-       def __init__(self, block, n):
+       def __init__(self, block, n, dir):
                """
                Make a new port from nested data.
                @param block the parent element
                @param n the nested odict
-               @return a new port
+               @param dir the direction source or sink
                """
-               #grab the data
-               name = n['name']
-               key = n['key']
-               type = n['type']
                #build the port
                Element.__init__(self, block)
-               self._name = name
-               self._key = key
-               self._type = type
+               #grab the data
+               self._name = n['name']
+               self._key = n['key']
+               self._type = n['type']
+               self._dir = dir
 
        def validate(self):
                """
@@ -60,8 +58,8 @@ class Port(Element):
        def get_color(self): return '#FFFFFF'
        def get_name(self): return self._name
        def get_key(self): return self._key
-       def is_sink(self): return self in self.get_parent().get_sinks()
-       def is_source(self): return self in self.get_parent().get_sources()
+       def is_sink(self): return self._dir == 'sink'
+       def is_source(self): return self._dir == 'source'
        def get_type(self): return self.get_parent().resolve_dependencies(self._type)
 
        def get_connections(self):
index a32b0209ffb2815c2e769a673dac58af1239b26a..1530a69d63f11cbe7d74eb8d92836a946337e4bc 100644 (file)
@@ -1,5 +1,5 @@
 """
-Copyright 2008 Free Software Foundation, Inc.
+Copyright 2008, 2009 Free Software Foundation, Inc.
 This file is part of GNU Radio
 
 GNU Radio Companion is free software; you can redistribute it and/or
@@ -38,8 +38,7 @@ def Platform(platform):
                ('FlowGraph', FlowGraph),
                ('Connection', Connection),
                ('Block', Block),
-               ('Source', Port),
-               ('Sink', Port),
+               ('Port', Port),
                ('Param', Param),
        ):
                old_value = getattr(platform, attr)
index d1f36f8b963659aea5d5e8130c8def7ffb3bd965..6fc2c4b155aeec04f26cb69131aa3065d0aab628 100644 (file)
@@ -1,5 +1,5 @@
 """
-Copyright 2007 Free Software Foundation, Inc.
+Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
 This file is part of GNU Radio
 
 GNU Radio Companion is free software; you can redistribute it and/or
index d55dbf4ce71a224fa89fd710a396f466db7c2391..cab25d348fd3d29665095c77bc3ba2eb33f8f729 100644 (file)
@@ -23,7 +23,7 @@ from .. base.Platform import Platform as _Platform
 from FlowGraph import FlowGraph as _FlowGraph
 from Connection import Connection as _Connection
 from Block import Block as _Block
-from Port import Source,Sink
+from Port import Port as _Port
 from Param import Param as _Param
 from Generator import Generator
 from Constants import \
@@ -77,6 +77,5 @@ class Platform(_Platform):
        FlowGraph = _FlowGraph
        Connection = _Connection
        Block = _Block
-       Source = Source
-       Sink = Sink
+       Port = _Port
        Param = _Param
index daf8f9ca34c1f687fffc3e54dac26af3dc35b6e3..f71c5fa35f87e768a979c4cc84e471deb3408704 100644 (file)
@@ -25,17 +25,27 @@ class Port(_Port):
        ##possible port types
        TYPES = ['complex', 'float', 'int', 'short', 'byte', 'msg']
 
-       def __init__(self, block, n):
+       def __init__(self, block, n, dir):
                """
                Make a new port from nested data.
                @param block the parent element
                @param n the nested odict
+               @param dir the direction
                """
+               self._n = n
+               if n['type'] == 'msg': n['key'] = 'msg'
+               if dir == 'source' and not n.find('key'):
+                       n['key'] = str(block._source_count)
+                       block._source_count += 1
+               if dir == 'sink' and not n.find('key'):
+                       n['key'] = str(block._sink_count)
+                       block._sink_count += 1
                #build the port
                _Port.__init__(
                        self,
                        block=block,
                        n=n,
+                       dir=dir,
                )
                self._nports = n.find('nports') or ''
                self._vlen = n.find('vlen') or ''
@@ -109,24 +119,4 @@ class Port(_Port):
        def copy(self, new_key=None):
                n = self._n.copy()
                if new_key: n['key'] = new_key
-               return self.__class__(self.get_parent(), n)
-
-class Source(Port):
-
-       def __init__(self, block, n):
-               self._n = n #save n
-               if n['type'] == 'msg': n['key'] = 'msg'
-               if not n.find('key'):
-                       n['key'] = str(block._source_count)
-                       block._source_count = block._source_count + 1
-               Port.__init__(self, block, n)
-
-class Sink(Port):
-
-       def __init__(self, block, n):
-               self._n = n #save n
-               if n['type'] == 'msg': n['key'] = 'msg'
-               if not n.find('key'):
-                       n['key'] = str(block._sink_count)
-                       block._sink_count = block._sink_count + 1
-               Port.__init__(self, block, n)
+               return self.__class__(self.get_parent(), n, self._dir)