KernelConfigClass.php 6.7 KB
<?php

/**
 * @class KernelConfigClass
 * @brief Class that's contain all specific configuration of the AMDA_Kernel module
 * @details
 */
class KernelConfigClass
{
	private static $xsdRequestDir    = "request/";
	private static $xsdParameterDir  = "parameter/";
	private static $xsdInfoDir       = "info/";
	private static $xsdLocalBaseDir  = "localbase/";

	private static $propFile         = "app.properties";

	private static $amdaPropFile     = "amda.properties";

	private static $cxxCompiler      = "g++";
	private static $cmakeFlags       = "-g -std=c++0x -fPIC -Wall -ggdb -DLINUX -Dlinux -D_REENTRANT -malign-double -pthread";

	private static $logConfigFile    = "log4cxx.config";
	private static $plotConfigFile   = "plotConfig.xml";

	private static $binDir           = "bin/";
	private static $pluginDir        = "plugin/";
	private static $libDir           = "lib/";

	private static $requestParamsDir = "params/";
	private static $userSrcDir       = "src/";
	private static $userLibDir       = "lib/";
	
	private static $datasetInfoDir   = "DataSetInfo/";
	private static $instrumentInfoDir= "InstrumentInfo/";
	private static $missionInfoDir   = "MissionInfo/";
	
	private static $localInclude     = "/opt/local/include/";
	private static $boostInclude     = "/opt/tools/gcc/4.7.2/boost/include/";
	private static $log4cxxInclude   = "/opt/local/include/log4cxx/";

	private static $gccDir           = "/opt/tools/gcc/4.7.2/rtf/";

	private static $defaultGapThreshold = "5";


	private static $userHost = "";

	private static $kernelAbout   = "Created by CDPP/AMDA(c)";
	private static $kernelAcknow  = "CDPP/AMDA Team";

	private static $includeArray     = array(
			"InternLib",
			"Common",
			"Parameters",
			"DD_Client_Lib",
			"helpers",
			"TimeTableCatalog"
	);

	public static $libArray = array(
			"Parameters"
	);


	public static function setUserHost($userHost)
	{
		self::$userHost = $userHost;
	}

	public static function getRequestParamsPath($working_dir)
	{
		$paramsPath = $working_dir.self::$requestParamsDir;

		if (!is_dir($paramsPath))
			mkdir($paramsPath);
			
		return $paramsPath;
	}

	public static function getXSDParameterFilePath()
	{
		return NEWKERNEL_XSD_DIR.self::$xsdParameterDir.'all.xsd';
	}

	public static function getXSDRequestFilePath()
	{
		return NEWKERNEL_XSD_DIR.self::$xsdRequestDir.'all.xsd';
	}
	
	public static function getXSDParamInfoFilePath()
	{
		return NEWKERNEL_XSD_DIR.self::$xsdInfoDir.'paramInfo.xsd';
	}
	
	public static function getXSDDatasetInfoFilePath()
	{
		return NEWKERNEL_XSD_DIR.self::$xsdInfoDir.'dataSetInfo.xsd';
	}
	
	public static function getXSDInstrumentInfoFilePath()
	{
		return NEWKERNEL_XSD_DIR.self::$xsdInfoDir.'instrumentInfo.xsd';
	}
	
	public static function getXSDMissionInfoFilePath()
	{
		return NEWKERNEL_XSD_DIR.self::$xsdInfoDir.'missionInfo.xsd';
	}
	
	public static function getXSDLocalBaseFilePath()
	{
		return NEWKERNEL_XSD_DIR.self::$xsdLocalBaseDir.'base.xsd';
	}
	
	public static function getDatasetInfoPath()
	{
		return NEWKERNEL_INFO_DIR.self::$datasetInfoDir;
	}
	
	public static function getInstrumentInfoPath()
	{
		return NEWKERNEL_INFO_DIR.self::$instrumentInfoDir;
	}
	
	public static function getMissionInfoPath()
	{
		return NEWKERNEL_INFO_DIR.self::$missionInfoDir;
	}
	
	public static function getKernelBinPath()
	{
		return NEWKERNEL_INSTALL_DIR.self::$binDir;
	}

	public static function getExecEnvVarArray()
	{
		return array (
				"DDPATH" => DDRES_DIR,
				"MY_GXX_HOME" => self::$gccDir,
				"PATH" => self::getKernelBinPath().":".self::$gccDir."bin/:".getenv("PATH"),
				"LD_LIBRARY_PATH" => self::$gccDir."lib64:".self::$gccDir."lib:".getenv("LD_LIBRARY_PATH")
		);
	}

	public static function getTimeToBatchMode()
	{
		return 10;
	}

	public static function write($working_dir, $compilation_path, $localbase_path)
	{
		//create app.properties file
		$appProperties = array();

		$appProperties["app.log4cxx.configfile"]      = NEWKERNEL_CONFIG_DIR.self::$logConfigFile;
		$appProperties["app.param.path"]              = self::getRequestParamsPath($working_dir);
		$appProperties["app.parameter.xsd"]           = self::getXSDParameterFilePath();
		$appProperties["app.request.xsd"]             = self::getXSDRequestFilePath();
		
		$appProperties["app.paramInfo.xsd"]           = self::getXSDParamInfoFilePath();
		$appProperties["app.dataSetInfo.path"]        = self::getDatasetInfoPath();
		$appProperties["app.dataSetInfo.xsd"]         = self::getXSDDatasetInfoFilePath();
		$appProperties["app.instrumentInfo.path"]     = self::getInstrumentInfoPath();
		$appProperties["app.instrumentInfo.xsd"]      = self::getXSDInstrumentInfoFilePath();
		$appProperties["app.missionInfo.path"]        = self::getMissionInfoPath();
		$appProperties["app.missionInfo.xsd"]         = self::getXSDMissionInfoFilePath();
		
		$appProperties["app.localbase.path"]          = $localbase_path;
		$appProperties["app.localbase.xsd"]           = self::getXSDLocalBaseFilePath();
		
		$appProperties["app.plugin"]                  = NEWKERNEL_INSTALL_DIR.self::$pluginDir;
		$appProperties["app.process.src"]             = $compilation_path.self::$userSrcDir;
		$appProperties["app.process.lib"]             = $compilation_path.self::$userLibDir;
		$appProperties["app.process.CXX_COMPILER"]    = self::$cxxCompiler;
		$appProperties["app.process.CMAKE_CXX_FLAGS"] = self::$cmakeFlags;

		$appProperties["app.process.INCLUDE"]         = "";
		foreach (self::$includeArray as $inc)
			$appProperties["app.process.INCLUDE"] .= ("-I".NEWKERNEL_SRC_DIR.$inc." ");
		$appProperties["app.process.INCLUDE"]         .= "-I".self::$localInclude." -I".self::$boostInclude." -I".self::$log4cxxInclude;

		$appProperties["app.process.LIB"]             = "-L".NEWKERNEL_INSTALL_DIR.self::$libDir." ";
		foreach (self::$libArray as $lib)
			$appProperties["app.process.LIB"] .= ("-l".$lib." ");

		$appProperties["app.plot.configfile"]         = INTEGRATION_SRC_DIR.'../config/'.self::$plotConfigFile;

		$appProperties["app.param.gapthreshold"] = self::$defaultGapThreshold;

		if (self::$userHost != "")
			$appProperties["app.user.host"] = self::$userHost;


		$fp = fopen($working_dir.self::$propFile, 'w');
		foreach ($appProperties as $key => $value)
			fwrite($fp, $key."=".$value.PHP_EOL);
		fclose($fp);

		//create amda.properties file
		$amdaPropertiesArray = array();

		$amdaPropertiesArray["createdby"] = self::$kernelAbout;
		$amdaPropertiesArray["acknowledgement"] = self::$kernelAcknow;

		$fp = fopen($working_dir.self::$amdaPropFile, 'w');
		foreach ($amdaPropertiesArray as $key => $value)
			fwrite($fp, $key."=".$value.PHP_EOL);
		fclose($fp);
	}
}

?>