Improved stream handling code in stream manager. No pointers to pointers anymore.

This commit is contained in:
Anne de Jong 2022-10-19 11:57:51 +02:00
parent 6bd03301aa
commit 142a161283

View File

@ -270,36 +270,45 @@ void StreamMgr::startStream(const DaqConfiguration &config) {
using namespace std::placeholders;
std::unique_ptr<Daq> daq = Daq::createDaq(devinfo, config);
std::unique_ptr<Daq> *stream_placeholder;
if (isInput) {
/// Give incallback as parameter to stream
inCallback = std::bind(&StreamMgr::inCallback, this, _1);
stream_placeholder = std::addressof(_inputStream);
/// Reset handlers in case of an input stream
for (auto &handler : _inDataHandlers) {
handler->reset(daq.get());
}
}
if (isOutput) {
/// Give outcallback as parameter to stream
outCallback = std::bind(&StreamMgr::outCallback, this, _1);
/// Reset signal generator in case of an output stream
if (_siggen) {
DEBUGTRACE_PRINT("Resetting _siggen with new samplerate of ");
DEBUGTRACE_PRINT(daq->samplerate());
_siggen->reset(daq->samplerate());
}
outCallback = std::bind(&StreamMgr::outCallback, this, _1);
if(!isDuplex) {
stream_placeholder = std::addressof(_outputStream);
}
}
/// Start the DAQ. If it fails, everything is still nicely cleaned up and the
/// daq unique_ptr cleans up resources nicely.
daq->start(inCallback, outCallback);
// Move daq ptr to right place
*stream_placeholder = std::move(daq);
if (isInput) {
_inputStream = std::move(daq);
} else {
_outputStream = std::move(daq);
}
}
void StreamMgr::stopStream(const StreamType t) {
DEBUGTRACE_ENTER;
checkRightThread();
switch (t) {
case (StreamType::input): {
if (t == StreamType::input) {
if (!_inputStream) {
throw rte("Input stream is not running");
}
@ -309,21 +318,18 @@ void StreamMgr::stopStream(const StreamType t) {
for (auto &handler : _inDataHandlers) {
handler->reset(nullptr);
}
} break;
case (StreamType::output): {
} else {
/// t == output
/// Kill input stream in case that one is a duplex stream
if (_inputStream && _inputStream->duplexMode()) {
_inputStream.reset();
} else {
if (!_outputStream) {
throw rte("Output stream is not running");
}
_outputStream.reset();
} // end else
} break;
default:
throw rte("BUG");
break;
}
}