00001 /* 00002 * File: TreqsConfig.h 00003 * 00004 * Copyright Jonathan Schaeffer 2009-2010, 00005 * CC-IN2P3, CNRS <jonathan.schaeffer@cc.in2p3.fr> 00006 * Contributors : Andres Gomez, 00007 * CC-IN2P3, CNRS <andres.gomez@cc.in2p3.fr> 00008 * 00009 * This software is a computer program whose purpose is to schedule, sort 00010 * and submit file requests to the hierarchical storage system HPSS. 00011 * 00012 * This software is governed by the CeCILL license under French law and 00013 * abiding by the rules of distribution of free software. You can use, 00014 * modify and/or redistribute the software under the terms of the CeCILL 00015 * license as circulated by CEA, CNRS and INRIA at the following URL 00016 * "http://www.cecill.info". 00017 * 00018 * As a counterpart to the access to the source code and rights to copy, 00019 * modify and redistribute granted by the license, users are provided only 00020 * with a limited warranty and the software's author, the holder of the 00021 * economic rights, and the successive licensors have only limited 00022 * liability. 00023 * 00024 * In this respect, the user's attention is drawn to the risks associated 00025 * with loading, using, modifying and/or developing or reproducing the 00026 * software by the user in light of its specific status of free software, 00027 * that may mean that it is complicated to manipulate, and that also 00028 * therefore means that it is reserved for developers and experienced 00029 * professionals having in-depth computer knowledge. Users are therefore 00030 * encouraged to load and test the software's suitability as regards their 00031 * requirements in conditions enabling the security of their systems and/or 00032 * data to be ensured and, more generally, to use and operate it in the 00033 * same conditions as regards security. 00034 * 00035 * The fact that you are presently reading this means that you have had 00036 * knowledge of the CeCILL license and that you accept its terms. 00037 * 00038 */ 00039 00040 #ifndef _CONFIG_H_ 00041 #define _CONFIG_H_ 00042 00043 #include <string> 00044 #include <fstream> 00045 #include <stdlib.h> 00046 #include <map> 00047 #include <vector> 00048 00049 #include "logger.h" 00050 #include "Exceptions.h" 00051 #include "Destroyer.h" 00052 00053 #ifndef CONFIGFILE_H_ 00054 #define CONFIGFILE_H 00055 #endif 00056 00057 namespace treqs { 00058 00059 enum ConfSections { 00060 MAIN, TREQSDB, FILECOPY 00061 }; 00062 /* 00063 * ============================================================================= 00064 * Class: Config 00065 * Description: Contains all config parameters. 00066 * Singleton 00067 * ============================================================================= 00068 */ 00069 00071 typedef std::pair<std::string, std::string> ConfigKey_t; 00072 00074 00075 class TreqsConfig { 00076 public: 00078 static TreqsConfig *getInstance(); 00079 00081 std::string getConfigpath(); 00083 void setConfigpath(std::string) throw (FileNotFoundError); 00091 std::string getValue(std::string sec, std::string key) throw (ConfigNotFoundError); 00095 void dumpConfig(); 00099 void reloadConfig(); 00100 00101 protected: 00103 TreqsConfig(); /* constructor */ 00104 00105 private: 00107 00115 void findConfigpath() throw (FileNotFoundError); 00117 static TreqsConfig *_singleton; 00119 static Destroyer<TreqsConfig> _destroyer; 00120 00122 void parse_config(); 00123 00125 std::string Configpath; 00126 00127 // static std::map<std::string,ConfMap> cfg_sections; 00129 static std::map<ConfigKey_t, std::string> Configuration; 00131 static log4cxx::LoggerPtr logger; 00132 }; /* ----- end of class Config ----- */ 00133 00134 } 00135 #endif