Skip to content
Base_Receiver.h 1.76 KiB
Newer Older
#pragma once
Valerio Pastore's avatar
Valerio Pastore committed

#include <netinet/in.h>
Valerio Pastore's avatar
Valerio Pastore committed
#include <Base_Packet.h>
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
.  
Valerio Pastore committed
namespace inaf::oasbo::Receivers {
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
Valerio Pastore committed
/**
 * @brief The BaseReceiver class is an abstract base class for receivers in the DAQ system.
 * 
 * This class provides a common interface for receiving data from clients. It defines pure virtual
 * functions for getting and setting the host, connecting to and closing the connection with the client,
 * checking if the receiver is connected to the client, and receiving data from the client.
 * 
 * Derived classes must implement these functions according to their specific requirements.
 */
Valerio Pastore's avatar
.  
Valerio Pastore committed
class BaseReceiver {
Valerio Pastore's avatar
Valerio Pastore committed
protected:
	std::string host;
public:

Valerio Pastore's avatar
Valerio Pastore committed
	/**
	 * @brief Get the host address.
	 * 
	 * @return The host address as a string.
	 */
	virtual std::string getHost() = 0;
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @brief Set the host address.
	 * 
	 * @param host The host address to set.
	 */
	virtual void setHost(std::string host) = 0;
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
Valerio Pastore committed
	/**
	 * @brief Connect to the client.
	 * 
	 * @return An integer indicating the success or failure of the operation.
	 */
Valerio Pastore's avatar
Valerio Pastore committed
	virtual int connectToClient()=0;
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @brief Close the connection with the client.
	 * 
	 * @return An integer indicating the success or failure of the operation.
	 */
Valerio Pastore's avatar
Valerio Pastore committed
	virtual int closeConnectionToClient()=0;
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @brief Check if the receiver is connected to the client.
	 * 
	 * @return true if the receiver is connected to the client, false otherwise.
	 */
Valerio Pastore's avatar
Valerio Pastore committed
	virtual bool isConnectedToClient() const =0;
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @brief Receive data from the client.
	 * 
	 * @param packet The received packet will be stored in this parameter.
	 * @return An integer indicating the success or failure of the operation.
	 */
Valerio Pastore's avatar
.  
Valerio Pastore committed
	virtual int receiveFromClient(Packets::BasePacket&) = 0;
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @brief Virtual destructor.
	 */
	virtual ~BaseReceiver() = default;
Valerio Pastore's avatar
Valerio Pastore committed
};