2023-06-06 14:05:24 +00:00
|
|
|
/* #define DEBUGTRACE_ENABLED */
|
|
|
|
#include "lasp_indatahandler.h"
|
2023-06-07 19:49:07 +00:00
|
|
|
#include "debugtrace.hpp"
|
2023-06-06 14:05:24 +00:00
|
|
|
#include "lasp_streammgr.h"
|
2023-06-07 19:49:07 +00:00
|
|
|
#include <thread>
|
2023-06-06 14:05:24 +00:00
|
|
|
|
2023-06-09 08:43:04 +00:00
|
|
|
InDataHandler::InDataHandler(SmgrHandle mgr, const InCallbackType cb,
|
|
|
|
const InResetType resetfcn)
|
|
|
|
: _mgr(mgr), inCallback(cb), reset(resetfcn)
|
2023-06-07 19:49:07 +00:00
|
|
|
#if LASP_DEBUG == 1
|
|
|
|
,
|
2023-06-09 08:43:04 +00:00
|
|
|
main_thread_id(std::this_thread::get_id())
|
2023-06-06 14:05:24 +00:00
|
|
|
#endif
|
2023-06-07 19:49:07 +00:00
|
|
|
{
|
|
|
|
DEBUGTRACE_ENTER;
|
2023-06-09 08:43:04 +00:00
|
|
|
#if LASP_DEBUG == 1
|
|
|
|
assert(mgr->main_thread_id == main_thread_id);
|
|
|
|
#endif
|
2023-06-07 19:49:07 +00:00
|
|
|
}
|
2023-06-06 14:05:24 +00:00
|
|
|
void InDataHandler::start() {
|
|
|
|
DEBUGTRACE_ENTER;
|
2023-06-09 08:43:04 +00:00
|
|
|
checkRightThread();
|
2023-06-07 19:49:07 +00:00
|
|
|
if (SmgrHandle handle = _mgr.lock()) {
|
|
|
|
handle->addInDataHandler(this);
|
2023-06-06 14:05:24 +00:00
|
|
|
#if LASP_DEBUG == 1
|
2023-06-09 08:43:04 +00:00
|
|
|
assert(handle->main_thread_id == main_thread_id);
|
2023-06-06 14:05:24 +00:00
|
|
|
#endif
|
2023-06-07 19:49:07 +00:00
|
|
|
}
|
2023-06-06 14:05:24 +00:00
|
|
|
}
|
|
|
|
void InDataHandler::stop() {
|
2023-06-09 08:43:04 +00:00
|
|
|
DEBUGTRACE_ENTER;
|
|
|
|
checkRightThread();
|
2023-06-06 14:05:24 +00:00
|
|
|
#if LASP_DEBUG == 1
|
|
|
|
stopCalled = true;
|
|
|
|
#endif
|
2023-06-07 19:49:07 +00:00
|
|
|
if (SmgrHandle handle = _mgr.lock()) {
|
2023-06-09 08:43:04 +00:00
|
|
|
handle->removeInDataHandler(*this);
|
2023-06-07 19:49:07 +00:00
|
|
|
}
|
2023-06-06 14:05:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InDataHandler::~InDataHandler() {
|
|
|
|
|
|
|
|
DEBUGTRACE_ENTER;
|
2023-06-09 08:43:04 +00:00
|
|
|
checkRightThread();
|
2023-06-06 14:05:24 +00:00
|
|
|
#if LASP_DEBUG == 1
|
|
|
|
if (!stopCalled) {
|
|
|
|
std::cerr << "************ BUG: Stop function not called while arriving at "
|
2023-06-07 19:49:07 +00:00
|
|
|
"InDataHandler's destructor. Fix this by calling "
|
2023-06-09 08:43:04 +00:00
|
|
|
"InDataHandler::stop()."
|
2023-06-07 19:49:07 +00:00
|
|
|
<< std::endl;
|
2023-06-06 14:05:24 +00:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2023-06-09 08:43:04 +00:00
|
|
|
#if LASP_DEBUG == 1
|
|
|
|
void InDataHandler::checkRightThread() const {
|
|
|
|
assert(std::this_thread::get_id() == main_thread_id);
|
|
|
|
}
|
|
|
|
#endif
|