Skip to content
Base_Configurator.h 2.22 KiB
Newer Older
astri's avatar
astri committed
#pragma once
Valerio Pastore's avatar
Valerio Pastore committed

#include <map>
#include <string>

astri's avatar
astri committed
namespace inaf::oasbo::Configurators {
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
Valerio Pastore committed
/**
 * @brief The BaseConfigurator class is an abstract base class for configurators in the DAQ system.
 * 
 * It provides common functionality for reading and pushing configurations to a source,
 * as well as inserting new configurations into the existing ones.
 */
Valerio Pastore's avatar
Valerio Pastore committed
class BaseConfigurator{
protected:
astri's avatar
astri committed
	std::map<std::string,std::string> config;
Valerio Pastore's avatar
Valerio Pastore committed

public:
Valerio Pastore's avatar
Valerio Pastore committed
	/**
	 * @brief Read the configuration from the source.
	 * 
	 * @return int Returns 0 on success, or an error code on failure.
	 */
astri's avatar
astri committed
	virtual int readConfigFromSource() = 0;
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @brief Read the configuration for the specified target.
	 * 
	 * @param target The target for which to read the configuration.
	 * @return int Returns 0 on success, or an error code on failure.
	 */
astri's avatar
astri committed
	virtual int readConfigFromSource(std::string target) = 0;
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @brief Push the configuration to the source.
	 * 
	 * @return int Returns 0 on success, or an error code on failure.
	 */
astri's avatar
astri committed
	virtual int pushConfigToSource() = 0;
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @brief Push the configuration for the specified target.
	 * 
	 * @param target The target for which to push the configuration.
	 * @return int Returns 0 on success, or an error code on failure.
	 */
astri's avatar
astri committed
	virtual int pushConfigToSource(std::string target) = 0;
Valerio Pastore's avatar
Valerio Pastore committed

	/**
	 * @brief Insert new configurations into the existing ones.
	 * 
	 * @param newConfig The new configurations to insert.
	 * @param target The target for which to insert the new configurations.
	 * @return int Returns 0 on success, or an error code on failure.
	 */
	virtual int insert(std::map<std::string, std::string> newConfig, std::string target) = 0;

	/**
	 * @brief Get the current configuration.
	 * 
	 * @return std::map<std::string, std::string> The current configuration.
	 */
astri's avatar
astri committed
	virtual std::map<std::string, std::string> getConfig() {return this->config;}
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
Valerio Pastore committed
	/**
	 * @brief Convert the configuration to a string representation.
	 * 
	 * @return std::string The string representation of the configuration.
	 */
Valerio Pastore's avatar
Valerio Pastore committed
	std::string toString(){
		std::string ret = "";
astri's avatar
astri committed
		for( const std::pair<std::string, std::string> n : config) {
Valerio Pastore's avatar
Valerio Pastore committed
			ret += n.first + " : " + n.second + "\n";
		}
		return ret;
	}

	virtual ~BaseConfigurator() = default;

};
astri's avatar
astri committed
}