/home/fwph/code/wurde/rde/core/WURDEConfiguration.cpp

Go to the documentation of this file.
00001 
00028 #include <WURDEConfiguration.H>
00029 #include <syslog.h>
00030 #include <stdlib.h>
00031 #include <Logger.H>
00032 
00033 using namespace WURDE;
00034 using namespace std;
00035 
00036 namespace WURDE {
00037 
00038        WURDEConfiguration g_globalConfiguration;
00039 
00040        WURDEConfiguration::WURDEConfiguration(){
00041               // set up defaults for the robot
00042               m_dataDir="/usr/local/share/wurde/data";
00043               m_binDir="/usr/local/bin";
00044               m_configDir="/usr/local/share/wurde/config";
00045               m_mcpConfigFile="mcp-config.xml";
00046               m_logDirectory="/usr/local/share/wurde/log";
00047               m_moduleName="null";
00048               m_logLevel=LOG_DEBUG;
00049        }
00050 
00051        bool WURDEConfiguration::haveOption(std::string name){
00052               std::multimap<std::string,std::string>::iterator iter;
00053               g_logdebug << "looking for option #"<<name<<"# in conf object " << this <<endl;
00054               iter=m_options.find(name);
00055               if(iter!=m_options.end()){
00056                      return true;
00057               }
00058               g_logdebug << "Don't have it." <<endl;
00059               return false;
00060        }
00061        
00062        std::string WURDEConfiguration::getOption(std::string name){
00063               std::multimap<std::string,std::string>::iterator iter;
00064 
00065               iter=m_options.find(name);
00066               if(iter!=m_options.end()){
00067                      return iter->second;
00068               }
00069 
00070               return "empty";
00071        }
00072 
00073        void WURDEConfiguration::setOption(std::string name, std::string value){
00074               m_options.insert(pair<string,string>(name,value));
00075               g_logdebug << "Setting option #"<<name<<"#"<<endl;
00076               if(m_options.find(name)==m_options.end()){
00077                       g_logdebug << "SOMETHING IS VERY WRONG IN SETOPTIONS" << endl;
00078               }else if(!haveOption(name)){
00079                       g_logdebug << "SOMETHING IS BROKEN IN HAVEOPTIONS" << endl;
00080                     
00081               }else{
00082                       g_logdebug << "Everything is peachy. " << endl;
00083               }
00084        }
00085 
00086        bool WURDEConfiguration::haveModuleOption(std::string module, std::string name){
00087               std::multimap<std::string, std::multimap<std::string, std::string> >::iterator iter;
00088               iter=m_moduleOptions.find(module);
00089               if(iter!=m_moduleOptions.end()){
00090                      std::multimap<std::string,std::string>::iterator iter2;
00091                      iter2=iter->second.find(name);
00092                      if(iter2!=iter->second.end()){
00093                             return true;
00094                      }
00095 
00096                      return false;
00097               }
00098 
00099               return false;
00100        }
00101        
00102        std::string WURDEConfiguration::getModuleOption(std::string module, std::string name){
00103               std::multimap<std::string, std::multimap<std::string, std::string> >::iterator iter;
00104 
00105               iter=m_moduleOptions.find(module);
00106               if(iter!=m_moduleOptions.end()){
00107                      std::multimap<std::string,std::string>::iterator iter2;
00108                      iter2=iter->second.find(name);
00109                      if(iter2!=iter->second.end()){
00110                             return iter2->second;;
00111                      }
00112 
00113                      return "empty";
00114               }
00115 
00116               return "empty";
00117 
00118        }
00119 
00120        void WURDEConfiguration::setModuleOption(std::string module, std::string name, std::string value){
00121               std::multimap<std::string, std::multimap<std::string, std::string> >::iterator iter;
00122 
00123               iter=m_moduleOptions.find(module);
00124               if(iter!=m_moduleOptions.end()){
00125                      iter->second.insert(pair<string,string>(name,value));
00126               }else{
00127                      std::multimap<string,string> temp;
00128                      temp.insert(pair<string,string>(name,value));
00129                      m_moduleOptions.insert(pair<string,multimap<string,string> >(module,temp));
00130               }
00131               
00132        }
00133 
00134 
00135        void WURDEConfiguration::readEnvironment(){
00136               char *temp;
00137 
00138               temp=getenv("WURDE_DATA_DIR");
00139               if(temp){
00140                      setDataDirectory(temp);
00141               }
00142 
00143               temp=getenv("WURDE_CONFIG_DIR");
00144               if(temp){
00145                      setConfigDirectory(temp);
00146               }
00147 
00148               temp=getenv("WURDE_BIN_DIR");
00149               if(temp){
00150                      setBinDirectory(temp);
00151               }
00152 
00153               temp=getenv("WURDE_MCP_CONFIG");
00154               if(temp){
00155                      setMCPConfigFile(temp);
00156               }
00157 
00158               temp=getenv("WURDE_LOG_LEVEL");
00159               if(temp){
00160                      string tmplog=temp;
00161                      std::transform (tmplog.begin(),tmplog.end(), tmplog.begin(), (int (*) (int)) tolower);
00162                      if(tmplog=="debug"){
00163                             setLogLevel(LOG_DEBUG);
00164                      }else if(tmplog=="info"){
00165                             setLogLevel(LOG_INFO);
00166                      }else if(tmplog=="notice"){
00167                             setLogLevel(LOG_NOTICE);
00168                      }else if(tmplog=="warn"){
00169                             setLogLevel(LOG_WARNING);
00170                      }else if(tmplog=="error"){
00171                             setLogLevel(LOG_ERR);
00172                      }else if(tmplog=="fatal"){
00173                             setLogLevel(LOG_CRIT);
00174                      }else{
00175                             cout << "Invalid loging level requested. Using LOG_DEBUG\n";
00176                             setLogLevel(LOG_DEBUG);
00177                      }
00178               }
00179 
00180               temp=getenv("WURDE_LOG_DIRECTORY");
00181               if(temp){
00182                      setLogDirectory(temp);
00183               }
00184 
00185        }
00186 
00187 
00188 }

Generated on Thu Feb 1 15:31:54 2007 for WURDE by  doxygen 1.5.1