2021-01-02 02:12:21 +00:00
|
|
|
from pycsdr.modules import Buffer
|
|
|
|
from pycsdr.api import Flow
|
2020-12-25 19:27:30 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2021-01-02 02:12:21 +00:00
|
|
|
class Chain(Flow):
|
2020-12-16 17:52:00 +00:00
|
|
|
def __init__(self, *workers):
|
2020-12-25 19:27:30 +00:00
|
|
|
self.input = None
|
|
|
|
self.output = None
|
2020-12-16 17:52:00 +00:00
|
|
|
self.workers = workers
|
2020-12-25 19:27:30 +00:00
|
|
|
for i in range(1, len(self.workers)):
|
|
|
|
self._connect(self.workers[i - 1], self.workers[i])
|
|
|
|
|
|
|
|
def _connect(self, w1, w2):
|
|
|
|
buffer = Buffer()
|
|
|
|
w1.setOutput(buffer)
|
|
|
|
w2.setInput(buffer)
|
2020-12-16 17:52:00 +00:00
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
for w in self.workers:
|
|
|
|
w.stop()
|
|
|
|
|
2020-12-19 15:28:18 +00:00
|
|
|
def setInput(self, buffer):
|
2020-12-25 19:27:30 +00:00
|
|
|
if self.input == buffer:
|
|
|
|
return
|
|
|
|
self.input = buffer
|
2020-12-19 15:28:18 +00:00
|
|
|
self.workers[0].setInput(buffer)
|
|
|
|
|
2020-12-25 19:27:30 +00:00
|
|
|
def setOutput(self, buffer):
|
|
|
|
if self.output == buffer:
|
|
|
|
return
|
|
|
|
self.output = buffer
|
|
|
|
self.workers[-1].setOutput(buffer)
|