"""
self.get_param('_enabled').set_value(str(enabled))
+ def rewrite(self):
+ """
+ Rewrite critical structures.
+ Call rewrite on all sub elements.
+ """
+ Element.rewrite(self)
+ for elem in self.get_ports() + self.get_params(): elem.rewrite()
+
def validate(self):
"""
Validate the block.
"""
-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
def add_error_message(self, msg): self._error_messages.append(msg)
def get_error_messages(self): return self._error_messages
+ def rewrite(self): pass
+
def get_enabled(self): return True
def get_parent(self): return self._parent
"""
raise NotImplementedError
+ def rewrite(self):
+ """
+ Rewrite critical structures.
+ Call rewrite on all sub elements.
+ """
+ Element.rewrite(self)
+ for elem in self.get_elements(): elem.rewrite()
+
def validate(self):
"""
Validate the flow graph.
#only load the block when the block key was valid
if block: block.import_data(block_n)
else: Messages.send_error_load('Block key "%s" not found in %s'%(key, self.get_parent()))
- self.validate() #validate all blocks before connections are made (in case of nports)
+ self.rewrite() #rewrite all blocks before connections are made (ex: nports)
#build the connections
for connection_n in connections_n:
#try to make the connection
#build the connection
self.connect(source, sink)
except AssertionError: Messages.send_error_load('Connection between %s(%s) and %s(%s) could not be made.'%(source_block_id, source_key, sink_block_id, sink_key))
+ self.rewrite() #global rewrite
def update(self):
"""
+ Do a global rewrite and validate.
Call update on all elements.
- Validate twice:
- 1) elements call special rewrite rules that may break validation
- 2) elements should come up with the same results, validation can pass
"""
- self.validate()
+ self.rewrite()
self.validate()
for element in self.get_elements(): element.update()
Validate this block.
Call the base class validate.
Evaluate the checks: each check must evaluate to True.
- Adjust the nports.
"""
_Block.validate(self)
#evaluate the checks
try: assert check_eval
except AssertionError: self.add_error_message('Check "%s" failed.'%check)
except: self.add_error_message('Check "%s" did not evaluate.'%check)
+
+ def rewrite(self):
+ """
+ Add and remove ports to adjust for the nports.
+ """
+ _Block.rewrite(self)
#adjust nports
for get_ports, get_port in (
(self.get_sources, self.get_source),
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.')
- ################################################################
- # message port logic
- ################################################################
+ #message port logic
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.')
- ################################################################
- # virtual sink logic
- ################################################################
+
+ def rewrite(self):
+ """
+ Handle the port cloning for virtual blocks.
+ """
+ _Port.rewrite(self)
+ #virtual sink logic
if self.get_parent().get_key() == 'virtual_sink':
if self.get_enabled_connections(): #clone type and vlen
source = self.get_enabled_connections()[0].get_source()