Main.cc 2.51 KB
/**
 * Main.cc
 *  Created on: 18 mar. 2016
 *      Author: AKKA IS
 */

#include <iostream>

#include <boost/program_options.hpp>

#include "AMDA-Kernel_Config.hh"
#include <Application.hh>

// Parameters module include
#include "ParameterManager.hh"
#include "Parameter.hh"
#include "Process.hh"
#include "ParameterInfo.hh"
#include "ServicesServer.hh"

using namespace std;
namespace po = boost::program_options;
using namespace log4cxx;
using namespace log4cxx::helpers;
using namespace AMDA::Parameters;

#define YEAR_3000_TIMESTAMP 32503680000

/**
 * Main function
 */
int main(int argc, char *argv[]) {
	int result = AMDA_EXIT_OK;

	/// Parse command line parameters
	po::options_description desc("Allowed options");

	desc.add_options()
		("help,h", "Produce help message")
		("version,v", "Program version")
		("parameter,p", po::value< vector<string> >(), "Parameter(s) name")
	;

	po::positional_options_description p;
	p.add("parameter", -1);

	po::variables_map vm;
	po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
	po::notify(vm);

	if (vm.count("help")) {
		cout << desc << "\n";
		return result;
	}
	if (vm.count("version")) {
		cout << "Version: " << AMDA_Kernel_VERSION << "\n";
		return result;
	}

	if (!vm.count("parameter")) {
		return result;
	}

	AMDA::Common::Application lMain;

	return lMain.main(argc,argv,[&](int , char **, AMDA::helpers::Properties& lProperties) -> int {

			vector<string> lParameterList = vm["parameter"].as< vector<string> >();

			///Create ParameterManager and configuration
			ParameterManager parameterManager;
			std::string emptyStr;
                        parameterManager.addInputInterval(0,YEAR_3000_TIMESTAMP, 0, emptyStr, emptyStr, 0);

			if (!lProperties["app.param.gapthreshold"].empty())
			{
				double defaultGapThreshold = 0.;
				defaultGapThreshold = atof(lProperties["app.param.gapthreshold"].c_str());
				if (defaultGapThreshold > 0.)
					parameterManager.setDefaultGapThreshold(defaultGapThreshold);
			}

			for (auto lParamName : lParameterList) {
				try {
					///Create Parameter
					parameterManager.createParameter(lParamName);

					///Generate Output
					AMDA::Parameters::ParameterInfo* lParameterInfo =
							new AMDA::Parameters::ParameterInfo(parameterManager);
					ParamOutputSPtr lParamOutput(lParameterInfo);
					lParameterInfo->setParamName(lParamName);
					parameterManager.getParamOutputList().push_back( lParamOutput);
				} catch (...) {
				}
			}
			/// launch request
			parameterManager.execute("");

			return result;
});

}