2023-06-06 14:05:24 +00:00
|
|
|
#pragma once
|
2023-06-09 08:43:04 +00:00
|
|
|
#include "lasp_types.h"
|
2023-06-06 14:05:24 +00:00
|
|
|
#include <atomic>
|
2023-06-09 08:43:04 +00:00
|
|
|
#include <functional>
|
2023-06-07 19:49:07 +00:00
|
|
|
#include <memory>
|
2023-06-06 14:05:24 +00:00
|
|
|
#include <thread>
|
|
|
|
|
2023-06-07 19:49:07 +00:00
|
|
|
class StreamMgr;
|
|
|
|
using SmgrHandle = std::shared_ptr<StreamMgr>;
|
|
|
|
|
2023-06-09 08:43:04 +00:00
|
|
|
class DaqData;
|
|
|
|
class Daq;
|
|
|
|
|
2023-06-06 14:05:24 +00:00
|
|
|
/** \addtogroup device
|
|
|
|
* @{
|
|
|
|
*/
|
2023-06-09 08:43:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The function definition of callbacks with incoming DAQ data
|
|
|
|
*/
|
|
|
|
using InCallbackType = std::function<void(const DaqData &)>;
|
|
|
|
/**
|
|
|
|
* @brief Function definition for the reset callback.
|
|
|
|
*/
|
2024-03-04 13:44:00 +00:00
|
|
|
using ResetCallbackType = std::function<void(const Daq *)>;
|
2023-06-09 08:43:04 +00:00
|
|
|
|
2023-06-06 14:05:24 +00:00
|
|
|
class InDataHandler {
|
|
|
|
|
|
|
|
protected:
|
2023-06-07 19:49:07 +00:00
|
|
|
std::weak_ptr<StreamMgr> _mgr;
|
2023-06-06 14:05:24 +00:00
|
|
|
#if LASP_DEBUG == 1
|
|
|
|
// This is a flag to indicate whether the method stop() is called for the
|
|
|
|
// current handler. It should call the method stop() from the derived class's
|
|
|
|
// destructor.
|
|
|
|
std::atomic<bool> stopCalled{false};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2023-06-09 08:43:04 +00:00
|
|
|
~InDataHandler();
|
|
|
|
const InCallbackType inCallback;
|
2024-03-04 13:44:00 +00:00
|
|
|
const ResetCallbackType reset;
|
2023-06-06 14:05:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief When constructed, the handler is added to the stream manager, which
|
|
|
|
* will call the handlers's inCallback() until stop() is called.
|
|
|
|
*
|
|
|
|
* @param mgr Stream manager.
|
2023-06-09 08:43:04 +00:00
|
|
|
* @param cb The callback that is stored, and called on new DAQ data
|
|
|
|
* @param resetfcn The callback that is stored, and called when the DAQ
|
|
|
|
* changes state.
|
2023-06-06 14:05:24 +00:00
|
|
|
*/
|
2023-06-09 08:43:04 +00:00
|
|
|
InDataHandler(SmgrHandle mgr, InCallbackType cb,
|
2024-03-04 13:44:00 +00:00
|
|
|
ResetCallbackType resetfcn);
|
2023-06-06 14:05:24 +00:00
|
|
|
|
|
|
|
/**
|
2023-06-09 08:43:04 +00:00
|
|
|
* @brief Adds the current InDataHandler to the list of handlers in the
|
|
|
|
* StreamMgr. After this happens, the reset() method stored in this
|
|
|
|
* object is called back. When the stream is running, right after this,
|
|
|
|
* inCallback() is called with DaqData.
|
2023-06-06 14:05:24 +00:00
|
|
|
*/
|
|
|
|
void start();
|
|
|
|
|
|
|
|
/**
|
2023-06-09 08:43:04 +00:00
|
|
|
* @brief Removes the currend InDataHandler from the list of handlers in the
|
|
|
|
* StreamMgr. From that point on, the object can be safely destroyed. Not
|
|
|
|
* calling stop() before destruction of this object is considered a BUG. I.e.
|
|
|
|
* a class which *uses* an InDataHandler should always call stop() in its
|
|
|
|
* destructor.
|
2023-06-06 14:05:24 +00:00
|
|
|
*/
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
#if LASP_DEBUG == 1
|
2023-06-09 08:43:04 +00:00
|
|
|
const std::thread::id main_thread_id;
|
2023-06-06 14:05:24 +00:00
|
|
|
void checkRightThread() const;
|
|
|
|
#else
|
|
|
|
void checkRightThread() const {}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
/** @} */
|