Skip to content
Base_DAQ.h 2.77 KiB
Newer Older
Valerio Pastore's avatar
Valerio Pastore committed
#ifndef BASEDAQ_H_
#define BASEDAQ_H_

#include <Base_Monitor.h>
#include <Base_Protocol.h>
#include <Base_Archiver.h>
#include <Base_Provider.h>
Valerio Pastore's avatar
Valerio Pastore committed
#include <Base_Packet.h>
Valerio Pastore's avatar
Valerio Pastore committed
#include <Base_Configurator.h>
Valerio Pastore's avatar
Valerio Pastore committed

// FORWARD DECLARE
namespace inaf::oasbo::DAQ_observers {
class BaseDAQ_Observer;
}

Valerio Pastore's avatar
Valerio Pastore committed
namespace inaf::oasbo::DAQ {
class BaseDAQ {
Valerio Pastore's avatar
Valerio Pastore committed
public:
	enum Status {
Valerio Pastore's avatar
Valerio Pastore committed
		STOP = -1, READY = 0, IDLE = 1, RUN = 2
Valerio Pastore's avatar
Valerio Pastore committed

protected:
	Status currentState;
	Status nextState;
Valerio Pastore's avatar
Valerio Pastore committed
	bool changeStateFlag = false;
astri's avatar
astri committed
	ConnectionProtocols::BaseProtocol *protocol = nullptr;
astri's avatar
astri committed
	Archivers::BaseArchiver *archiver = nullptr;
	Providers::BaseProvider *provider = nullptr;
	PacketMonitors::BasePacketMonitor *monitor = nullptr;
	PacketLib::BasePacket *packet = nullptr;
Valerio Pastore's avatar
Valerio Pastore committed
	std::vector<inaf::oasbo::DAQ_observers::BaseDAQ_Observer*> observers;
Valerio Pastore's avatar
Valerio Pastore committed
	std::vector<inaf::oasbo::Configurators::BaseConfigurator*> configurations;
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
Valerio Pastore committed
public:
Valerio Pastore's avatar
Valerio Pastore committed
	void setProtocol(ConnectionProtocols::BaseProtocol &socket) {
astri's avatar
astri committed
		this->protocol = &socket;
Valerio Pastore's avatar
Valerio Pastore committed
	}
	void setArchiver(Archivers::BaseArchiver &archiver) {
		this->archiver = &archiver;
	}
	void setProvider(Providers::BaseProvider &provider) {
		this->provider = &provider;
	}
	void setMonitor(PacketMonitors::BasePacketMonitor &monitor) {
		this->monitor = &monitor;
	}
	void setPacket(PacketLib::BasePacket &packet) {
		this->packet = &packet;
	}
	void setCurrentState(Status currentState) {
		this->currentState = currentState;
	}
	void setNextState(Status nextState) {
		this->nextState = nextState;
	}
	void setChangeStateFlag(bool flag) {
		this->changeStateFlag = flag;
	}
Valerio Pastore's avatar
Valerio Pastore committed
	void registerObserver(
			inaf::oasbo::DAQ_observers::BaseDAQ_Observer *observer) {
Valerio Pastore's avatar
Valerio Pastore committed
		observers.push_back(observer);
	}

Valerio Pastore's avatar
Valerio Pastore committed
	void removeObserver(
			inaf::oasbo::DAQ_observers::BaseDAQ_Observer *observer) {
Valerio Pastore's avatar
Valerio Pastore committed
		observers.erase(
				std::remove(observers.begin(), observers.end(), observer),
				observers.end());
	}
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
Valerio Pastore committed
	ConnectionProtocols::BaseProtocol* getSocketPtr() {
astri's avatar
astri committed
		return this->protocol;
Valerio Pastore's avatar
Valerio Pastore committed
	}
	Archivers::BaseArchiver* getArchiverPtr() {
		return this->archiver;
	}
	Providers::BaseProvider* getProviderPtr() {
		return this->provider;
	}
	PacketMonitors::BasePacketMonitor* getMonitorPtr() {
		return this->monitor;
	}
	PacketLib::BasePacket* getPacketPrt() {
		return this->packet;
	}
	Status getCurrentState() {
		return this->currentState;
	}
	Status getNextState() {
		return this->nextState;
	}
	int getChangeStateFlag() {
		return this->changeStateFlag;
	}
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
Valerio Pastore committed
	virtual void start() = 0;
Valerio Pastore's avatar
Valerio Pastore committed
	virtual void stop() = 0;
	virtual void switchState(const Status) = 0;
Valerio Pastore's avatar
Valerio Pastore committed
	virtual int deliverPacket() = 0;
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
Valerio Pastore committed
	virtual ~BaseDAQ() {
astri's avatar
astri committed
		delete protocol;
Valerio Pastore's avatar
Valerio Pastore committed
		delete provider;
		delete archiver;
		delete monitor;
Valerio Pastore's avatar
Valerio Pastore committed
		delete packet;
Valerio Pastore's avatar
Valerio Pastore committed
		for (auto ob : observers) {
			observers.erase(std::remove(observers.begin(), observers.end(), ob),
					observers.end());
		}
Valerio Pastore's avatar
Valerio Pastore committed
	}
};
Valerio Pastore's avatar
Valerio Pastore committed
#endif /* BASEDAQ_H_ */