/* ************************************************************************** * Copyright (C) 2023 INAF * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License * or (at your option) any later version. This program is distributed * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: * * <>Valerio Pastore INAF-OAS Bologna valerio.pastore@inaf.it **************************************************************************** */ #pragma once #include #include #include #include #include #include #include /** * @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. */ namespace inaf::oasbo::DAQ { class BaseDAQ { public: enum Status { INIT = -2, STOP = -1, READY = 0, IDLE = 1, RUN = 2 }; protected: 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 observers; /**< Vector of observers. */ std::vector configurations; /**< Vector of configurations. */ public: /** * @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. */ void setPacket(Packets::BasePacket &packet) { this->packet = &packet; } /** * @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) { observers.push_back(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. */ Packets::BasePacket* getPacketPrt() { return this->packet; } /** * @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. */ virtual void start() = 0; /** * @brief Stops the DAQ system. * * @note This is a pure virtual function and must be implemented by derived classes. */ virtual void stop() = 0; /** * @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. */ virtual int deliverPacket() = 0; /** * @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. */ virtual ~BaseDAQ() { delete receiver; delete provider; delete archiver; delete monitor; delete packet; for (auto ob : observers) { observers.erase(std::remove(observers.begin(), observers.end(), ob), observers.end()); } } }; }