ProcessStandard.hh 2.65 KB
/**
 * ProcessStandard.hh
 *
 *  Created on: Dec 11, 2012
 *      Author: AKKA IS
 */

#ifndef PROCESSSTANDARD_HH_
#define PROCESSSTANDARD_HH_

#include <string>
#include <list>
#include <map>

#include <boost/shared_ptr.hpp>
#include <log4cxx/logger.h>


#include "AMDA_exception.hh"
#include "DataWriter.hh"
#include "DataClient.hh"
#include "Parameter.hh"
#include "Properties.hh"

#include "MultiParamProcess.hh"
#include "Parser.hh"

#define PROCESS_STANDARD_COMPIL_VERSION 4

namespace AMDA {
namespace Parameters {

class ServicesServer;
typedef ServicesServer *ServicesServerPtr;

class ParamData;
typedef ParamData *ParamDataPtr;

class ProcessStandard: public MultiParamProcess_CRTP<ProcessStandard> {
public:

	typedef std::vector<std::string> SoList;
	/**
	 * map: first element: path of plugin, second, list of .so
	 */
	typedef std::map<std::string,  SoList> PluginList;
	/**
	 *
	 * Default constructor.
	 */
	ProcessStandard(Parameter &parameter);
	/**
	 *
	 * Default constructor.
	 */
	ProcessStandard(const ProcessStandard &process, Parameter &parameter);

	/**
	 * Default destructor.
	 */
	virtual ~ProcessStandard();

	/**
	 * initialization of get method
	 * create real ParamData
	 */
	virtual TimeStamp init();

	/*
	 * @overload MultiParamProcess_CRTP::getMinSampling
	 */
	virtual double getMinSampling();

	virtual void establishConnection();

protected:
	/**
	 * get paramName and fctName of expression
	 */
	virtual void parse();

	/**
	 * @brief return true if generated .so is necessary
	 */
	bool mustGenerated(TimeStamp time) ;
	/**
	 * get paramName and fctName of expression
	 */
	void generateCppfile();

	/**
	 * generate dynamic library
	 */
	TimeStamp  generateSoFile();

	/**
	 * Load dynamic library to process
	 */
	void loadDynamicLib();

	/**
	 * Load dynamic library to process
	 */
	void closeDynamicLib();

	/**
	 * find include
	 */
	bool findInclude(std::string name, std::string &path, std::vector<std::string> &listSo) ;

	std::string _fct;
	std::string _symboleName;
	ServicesServerPtr _servicesServer;
	std::string _fileNameRoot;
	std::string _fileNameC;
	std::string _fileNameSO;
	void *_handle;
	 AMDA::Parameters::ParamData *(*_processInit)(Process *pProcess);
	int (*_compilVersion)();
	 bool _accesDirect;

	 bool _alreadyParsed;

	AMDA::helpers::Properties _propertiesList;
	Parser _parser;
	PluginList _PluginList;
	std::stringstream _streamIncludeFile;
	TimeStamp _timeOfSoFile;

	/**
	 * @brief  temporary working directory to create temporary file
	 * @details give by mkdtemp(_propertiesList["app.process.src"]/XXXXXX);
	 */
	std::string _workingDiretory ;
};

} /* namespace Parameters */
} /* namespace AMDA */
#endif /* PROCESSSTANDARD_HH_ */