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; using namespace std::placeholders;
std::unique_ptr<Daq> daq = Daq::createDaq(devinfo, config); std::unique_ptr<Daq> daq = Daq::createDaq(devinfo, config);
std::unique_ptr<Daq> *stream_placeholder;
if (isInput) { if (isInput) {
/// Give incallback as parameter to stream
inCallback = std::bind(&StreamMgr::inCallback, this, _1); inCallback = std::bind(&StreamMgr::inCallback, this, _1);
stream_placeholder = std::addressof(_inputStream);
/// Reset handlers in case of an input stream
for (auto &handler : _inDataHandlers) { for (auto &handler : _inDataHandlers) {
handler->reset(daq.get()); handler->reset(daq.get());
} }
} }
if (isOutput) { 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) { if (_siggen) {
DEBUGTRACE_PRINT("Resetting _siggen with new samplerate of "); DEBUGTRACE_PRINT("Resetting _siggen with new samplerate of ");
DEBUGTRACE_PRINT(daq->samplerate()); DEBUGTRACE_PRINT(daq->samplerate());
_siggen->reset(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); daq->start(inCallback, outCallback);
// Move daq ptr to right place // 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) { void StreamMgr::stopStream(const StreamType t) {
DEBUGTRACE_ENTER; DEBUGTRACE_ENTER;
checkRightThread(); checkRightThread();
switch (t) {
case (StreamType::input): { if (t == StreamType::input) {
if (!_inputStream) { if (!_inputStream) {
throw rte("Input stream is not running"); throw rte("Input stream is not running");
} }
@ -309,21 +318,18 @@ void StreamMgr::stopStream(const StreamType t) {
for (auto &handler : _inDataHandlers) { for (auto &handler : _inDataHandlers) {
handler->reset(nullptr); handler->reset(nullptr);
} }
} break; } else {
case (StreamType::output): { /// t == output
/// Kill input stream in case that one is a duplex stream
if (_inputStream && _inputStream->duplexMode()) { if (_inputStream && _inputStream->duplexMode()) {
_inputStream.reset(); _inputStream.reset();
} else { } else {
if (!_outputStream) { if (!_outputStream) {
throw rte("Output stream is not running"); throw rte("Output stream is not running");
} }
_outputStream.reset(); _outputStream.reset();
} // end else } // end else
} break;
default:
throw rte("BUG");
break;
} }
} }