00001 00025 #include "llindraconfigfile.h" 00026 00027 #include "llfile.h" 00028 #include "llsd.h" 00029 #include "llsdserialize.h" 00030 #include "llframetimer.h" 00031 00032 static std::string sConfigDir = ""; 00033 static const char indraConfigFileName[] = "indra.xml"; 00034 00035 00036 LLIndraConfigFile::LLIndraConfigFile() 00037 : LLLiveFile(filename(), configFileRefreshRate), 00038 mConfig(LLSD()) 00039 { 00040 } 00041 00042 //static 00043 void LLIndraConfigFile::initClass(const std::string& config_dir) 00044 { 00045 sConfigDir = config_dir; 00046 llinfos << "LLIndraConfigFile::initClass config dir " 00047 << config_dir << "/" << indraConfigFileName << llendl; 00048 } 00049 00050 LLSD LLIndraConfigFile::getConfig(const std::string& config_name) 00051 { 00052 if (sConfigDir.empty()) 00053 { 00054 llerrs << "LLIndraConfigFile::initClass() not called" << llendl; 00055 } 00056 00057 LLFrameTimer::updateFrameTime(); 00058 00059 static LLIndraConfigFile the_file; 00060 the_file.checkAndReload(); 00061 00062 return the_file.mConfig[config_name]; 00063 } 00064 00065 std::string LLIndraConfigFile::filename() 00066 { 00067 std::ostringstream ostr; 00068 00069 ostr << sConfigDir 00070 << "/" << indraConfigFileName; 00071 00072 return ostr.str(); 00073 } 00074 00075 /* virtual */ 00076 void LLIndraConfigFile::loadFile() 00077 { 00078 llinfos << "LLIndraConfigFile::loadFile: reading from " 00079 << filename() << llendl; 00080 00081 LLSD config; 00082 00083 { 00084 llifstream file(filename().c_str()); 00085 if (file.is_open()) 00086 { 00087 LLSDSerialize::fromXML(config, file); 00088 } 00089 00090 if (config.isUndefined()) 00091 { 00092 llinfos << "LLIndraConfigFile::loadFile: file missing, ill-formed," 00093 " or simply undefined; not changing the blacklist" << llendl; 00094 return; 00095 } 00096 } 00097 00098 if (config.isMap()) 00099 { 00100 mConfig = config; 00101 } 00102 else 00103 { 00104 llwarns << "LLIndraConfigFile: " << indraConfigFileName << " expects a map; wrong format" << llendl; 00105 return; 00106 } 00107 }