2024-03-13 11:19:24 +00:00
|
|
|
// #define DEBUGTRACE_ENABLED
|
2023-06-06 14:05:24 +00:00
|
|
|
#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,
|
2024-03-04 13:44:00 +00:00
|
|
|
const ResetCallbackType resetfcn)
|
2023-06-09 08:43:04 +00:00
|
|
|
: _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;
|
2024-03-13 11:19:24 +00:00
|
|
|
// checkRightThread();
|
2023-06-06 14:05:24 +00:00
|
|
|
#if LASP_DEBUG == 1
|
|
|
|
stopCalled = true;
|
|
|
|
#endif
|
2024-03-13 11:19:24 +00:00
|
|
|
if (SmgrHandle smgr = _mgr.lock()) {
|
|
|
|
smgr->removeInDataHandler(*this);
|
|
|
|
} else {
|
|
|
|
DEBUGTRACE_PRINT("No stream manager alive anymore!");
|
2023-06-07 19:49:07 +00:00
|
|
|
}
|
2023-06-06 14:05:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InDataHandler::~InDataHandler() {
|
|
|
|
|
|
|
|
DEBUGTRACE_ENTER;
|
|
|
|
#if LASP_DEBUG == 1
|
2024-03-13 11:19:24 +00:00
|
|
|
// checkRightThread();
|
2023-06-06 14:05:24 +00:00
|
|
|
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
|