summaryrefslogtreecommitdiff
path: root/grc/python/Port.py
diff options
context:
space:
mode:
Diffstat (limited to 'grc/python/Port.py')
-rw-r--r--grc/python/Port.py43
1 files changed, 23 insertions, 20 deletions
diff --git a/grc/python/Port.py b/grc/python/Port.py
index 5a2b047f0..daf8f9ca3 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 ''
+ self._optional = bool(n.find('optional'))
def validate(self):
_Port.validate(self)
@@ -51,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):
"""
@@ -94,6 +95,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,
@@ -104,26 +106,27 @@ 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
- #key is port index
- n['key'] = str(block._source_count)
- block._source_count = block._source_count + 1
+ 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)
- def __del__(self):
- self.get_parent()._source_count = self.get_parent()._source_count - 1
-
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
+ 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)
-
- def __del__(self):
- self.get_parent()._sink_count = self.get_parent()._sink_count - 1