Newer
Older
#include <Base_Monitor.h>
#include <Base_Archiver.h>
#include <Base_Provider.h>
// FORWARD DECLARE
namespace inaf::oasbo::DAQ_observers {
class BaseDAQ_Observer;
}
/**
* @brief The BaseDAQ class represents the base class for a Data Acquisition (DAQ) system.
*
* This class provides a common interface and functionality for a DAQ system. The DAQ system is imagined as a state machine.
* This super class defines the states, sets the receiver, archiver, provider, monitor, and packet objects, and
* manages the observers and configurations. It also provides pure virtual functions for
* starting, stopping, switching states, delivering packets, and getting the state as a string.
*
* @note This class is meant to be inherited from and should not be instantiated directly.
*/
INIT = -2, STOP = -1, READY = 0, IDLE = 1, RUN = 2
Status currentState; /**< The current state of the DAQ system. */
Status nextState; /**< The next state of the DAQ system. */
bool changeStateFlag = false; /**< Flag indicating if the state has changed. */
Receivers::BaseReceiver *receiver = nullptr; /**< Pointer to the receiver object. */
Archivers::BaseArchiver *archiver = nullptr; /**< Pointer to the archiver object. */
Providers::BaseProvider *provider = nullptr; /**< Pointer to the provider object. */
PacketMonitors::BasePacketMonitor *monitor = nullptr; /**< Pointer to the packet monitor object. */
Packets::BasePacket *packet = nullptr; /**< Pointer to the packet object. */
std::vector<inaf::oasbo::DAQ_observers::BaseDAQ_Observer*> observers; /**< Vector of observers. */
std::vector<inaf::oasbo::Configurators::BaseConfigurator*> configurations; /**< Vector of configurations. */
/**
* @brief Sets the receiver object.
*
* @param receiver The receiver object to set.
*/
void setReceiver(Receivers::BaseReceiver &receiver) {
this->receiver = &receiver;
/**
* @brief Sets the archiver object.
*
* @param archiver The archiver object to set.
*/
void setArchiver(Archivers::BaseArchiver &archiver) {
this->archiver = &archiver;
}
/**
* @brief Sets the provider object.
*
* @param provider The provider object to set.
*/
void setProvider(Providers::BaseProvider &provider) {
this->provider = &provider;
}
/**
* @brief Sets the packet monitor object.
*
* @param monitor The packet monitor object to set.
*/
void setMonitor(PacketMonitors::BasePacketMonitor &monitor) {
this->monitor = &monitor;
}
/**
* @brief Sets the packet object.
*
* @param packet The packet object to set.
*/
/**
* @brief Sets the current state of the DAQ system.
*
* @param currentState The current state to set.
*/
void setCurrentState(Status currentState) {
this->currentState = currentState;
}
/**
* @brief Sets the next state of the DAQ system.
*
* @param nextState The next state to set.
*/
void setNextState(Status nextState) {
this->nextState = nextState;
}
/**
* @brief Sets the flag indicating if the state has changed.
*
* @param flag The flag value to set.
*/
void setChangeStateFlag(bool flag) {
this->changeStateFlag = flag;
}
/**
* @brief Registers an observer to the DAQ system.
*
* @param observer The observer to register.
*/
void registerObserver(
inaf::oasbo::DAQ_observers::BaseDAQ_Observer *observer) {
/**
* @brief Removes an observer from the DAQ system.
*
* @param observer The observer to remove.
*/
void removeObserver(
inaf::oasbo::DAQ_observers::BaseDAQ_Observer *observer) {
observers.erase(
std::remove(observers.begin(), observers.end(), observer),
observers.end());
}
/**
* @brief Gets a pointer to the receiver object.
*
* @return Pointer to the receiver object.
*/
Receivers::BaseReceiver* getReceiverPtr() {
return this->receiver;
/**
* @brief Gets a pointer to the archiver object.
*
* @return Pointer to the archiver object.
*/
Archivers::BaseArchiver* getArchiverPtr() {
return this->archiver;
}
/**
* @brief Gets a pointer to the provider object.
*
* @return Pointer to the provider object.
*/
Providers::BaseProvider* getProviderPtr() {
return this->provider;
}
/**
* @brief Gets a pointer to the packet monitor object.
*
* @return Pointer to the packet monitor object.
*/
PacketMonitors::BasePacketMonitor* getMonitorPtr() {
return this->monitor;
}
/**
* @brief Gets a pointer to the packet object.
*
* @return Pointer to the packet object.
*/
/**
* @brief Gets the current state of the DAQ system.
*
* @return The current state of the DAQ system.
*/
Status getCurrentState() {
return this->currentState;
}
/**
* @brief Gets the next state of the DAQ system.
*
* @return The next state of the DAQ system.
*/
Status getNextState() {
return this->nextState;
}
/**
* @brief Gets the flag indicating if the state has changed.
*
* @return The flag indicating if the state has changed.
*/
int getChangeStateFlag() {
return this->changeStateFlag;
}
/**
* @brief Starts the DAQ system.
*
* @note This is a pure virtual function and must be implemented by derived classes.
*/
/**
* @brief Stops the DAQ system.
*
* @note This is a pure virtual function and must be implemented by derived classes.
*/
/**
* @brief Switches the state of the DAQ system.
*
* @param state The state to switch to.
*
* @note This is a pure virtual function and must be implemented by derived classes.
*/
virtual void switchState(const Status state) = 0;
/**
* @brief Delivers a packet after received. It should probably call the provider to deliver the packet.
*
* @return The result of the packet delivery.
*
* @note This is a pure virtual function and must be implemented by derived classes.
*/
/**
* @brief Gets the string representation of a state.
*
* @param state The state to get the string representation of.
* @return The string representation of the state.
*
* @note This is a pure virtual function and must be implemented by derived classes.
*/
virtual std::string getStateStr(const Status state) = 0;
/**
* @brief Destructor for the BaseDAQ class.
*
* Deletes the receiver, provider, archiver, monitor, packet, and observers.
*/
delete provider;
delete archiver;
delete monitor;
for (auto ob : observers) {
observers.erase(std::remove(observers.begin(), observers.end(), ob),
observers.end());
}