From 9cdea550a868695d3b75dc79ccde4a4cc3b78851 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 10 Aug 2009 22:29:55 -0700 Subject: apply diff from previous commits --- grc/python/Port.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'grc/python/Port.py') diff --git a/grc/python/Port.py b/grc/python/Port.py index 5a2b047f0..c01884cc3 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -23,27 +23,23 @@ import Constants class Port(_Port): ##possible port types - TYPES = ['complex', 'float', 'int', 'short', 'byte'] + TYPES = ['complex', 'float', 'int', 'short', 'byte', 'msg'] def __init__(self, block, n): """ Make a new port from nested data. @param block the parent element @param n the nested odict - @return a new port """ - vlen = n.find('vlen') or '1' - nports = n.find('nports') or '' - optional = n.find('optional') or '' #build the port _Port.__init__( self, block=block, n=n, ) - self._nports = nports - self._vlen = vlen - self._optional = bool(optional) + self._nports = n.find('nports') or '' + self._vlen = n.find('vlen') or '1' + self._optional = bool(n.find('optional')) def validate(self): _Port.validate(self) @@ -94,6 +90,7 @@ class Port(_Port): 'int': Constants.INT_COLOR_SPEC, 'short': Constants.SHORT_COLOR_SPEC, 'byte': Constants.BYTE_COLOR_SPEC, + 'msg': Constants.MSG_COLOR_SPEC, }[self.get_type()] return {#vlen is non 1 'complex': Constants.COMPLEX_VECTOR_COLOR_SPEC, @@ -108,10 +105,10 @@ class Source(Port): def __init__(self, block, n): self._n = n #save n - #key is port index - n['key'] = str(block._source_count) - block._source_count = block._source_count + 1 - Port.__init__(self, block, n) + if n['type'] != 'msg': #key is port index + n['key'] = str(block._source_count) + block._source_count = block._source_count + 1 + Port.__init__(self, block, n) def __del__(self): self.get_parent()._source_count = self.get_parent()._source_count - 1 @@ -120,10 +117,14 @@ class Sink(Port): def __init__(self, block, n): self._n = n #save n - #key is port index - n['key'] = str(block._sink_count) - block._sink_count = block._sink_count + 1 - Port.__init__(self, block, n) + if n['type'] != 'msg': #key is port index + n['key'] = str(block._sink_count) + block._sink_count = block._sink_count + 1 + Port.__init__(self, block, n) def __del__(self): self.get_parent()._sink_count = self.get_parent()._sink_count - 1 + +#TODO merge source and sink classes into port class +#TODO check that key is only defined if and only if type is message +#TODO check that nports is undefined when type is message -- cgit From 0a73facce3ce4eba23676df5f22f222df319ed87 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 13 Aug 2009 23:59:06 -0700 Subject: this time commit the file changes --- grc/python/Port.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'grc/python/Port.py') diff --git a/grc/python/Port.py b/grc/python/Port.py index c01884cc3..14adc0618 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -105,10 +105,11 @@ class Source(Port): def __init__(self, block, n): self._n = n #save n - if n['type'] != 'msg': #key is port index + if n['type'] == 'msg': n['key'] = 'msg' + else: n['key'] = str(block._source_count) block._source_count = block._source_count + 1 - Port.__init__(self, block, n) + Port.__init__(self, block, n) def __del__(self): self.get_parent()._source_count = self.get_parent()._source_count - 1 @@ -117,14 +118,14 @@ class Sink(Port): def __init__(self, block, n): self._n = n #save n - if n['type'] != 'msg': #key is port index + if n['type'] == 'msg': n['key'] = 'msg' + else: n['key'] = str(block._sink_count) block._sink_count = block._sink_count + 1 - Port.__init__(self, block, n) + Port.__init__(self, block, n) def __del__(self): self.get_parent()._sink_count = self.get_parent()._sink_count - 1 -#TODO merge source and sink classes into port class -#TODO check that key is only defined if and only if type is message -#TODO check that nports is undefined when type is message +#TODO check that nports and vlen is undefined when type is message +#TODO only allow up to one port of type msg -- cgit From de213686dfa9608bcf59e2c14a4e326049e9779e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 14 Aug 2009 23:23:53 -0700 Subject: params, sources, and sinks now stored internally as lists. The keys for said objects are now only stored in one place (in the object). --- grc/python/Port.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'grc/python/Port.py') diff --git a/grc/python/Port.py b/grc/python/Port.py index 14adc0618..0b6d20bbe 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -111,9 +111,6 @@ class Source(Port): block._source_count = block._source_count + 1 Port.__init__(self, block, n) - def __del__(self): - self.get_parent()._source_count = self.get_parent()._source_count - 1 - class Sink(Port): def __init__(self, block, n): @@ -124,8 +121,5 @@ class Sink(Port): block._sink_count = block._sink_count + 1 Port.__init__(self, block, n) - def __del__(self): - self.get_parent()._sink_count = self.get_parent()._sink_count - 1 - #TODO check that nports and vlen is undefined when type is message #TODO only allow up to one port of type msg -- cgit From 8e1a2c4ac1a43fd989c06856dae27b0c2559c6b3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 15 Aug 2009 00:29:11 -0700 Subject: added validation check for msg type ports, added copy method for ports to cleanup nports code --- grc/python/Port.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'grc/python/Port.py') diff --git a/grc/python/Port.py b/grc/python/Port.py index 0b6d20bbe..daf8f9ca3 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -38,7 +38,7 @@ class Port(_Port): n=n, ) self._nports = n.find('nports') or '' - self._vlen = n.find('vlen') or '1' + self._vlen = n.find('vlen') or '' self._optional = bool(n.find('optional')) def validate(self): @@ -47,6 +47,11 @@ class Port(_Port): except AssertionError: self.add_error_message('Port is not connected.') try: assert self.is_source() or len(self.get_enabled_connections()) <= 1 except AssertionError: self.add_error_message('Port has too many connections.') + if self.get_type() == 'msg': + try: assert not self.get_nports() + except AssertionError: self.add_error_message('A port of type "msg" cannot have "nports" set.') + try: assert self.get_vlen() == 1 + except AssertionError: self.add_error_message('A port of type "msg" must have a "vlen" of 1.') def get_vlen(self): """ @@ -101,12 +106,17 @@ class Port(_Port): }[self.get_type()] except: return _Port.get_color(self) + 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' - else: + if not n.find('key'): n['key'] = str(block._source_count) block._source_count = block._source_count + 1 Port.__init__(self, block, n) @@ -116,10 +126,7 @@ class Sink(Port): def __init__(self, block, n): self._n = n #save n if n['type'] == 'msg': n['key'] = 'msg' - else: + if not n.find('key'): n['key'] = str(block._sink_count) block._sink_count = block._sink_count + 1 Port.__init__(self, block, n) - -#TODO check that nports and vlen is undefined when type is message -#TODO only allow up to one port of type msg -- cgit