Merge "Fix indentation and style issues in fm-common/fmConfig.cpp"
This commit is contained in:
commit
06afa39e78
@ -17,13 +17,12 @@
|
|||||||
#include "fmSnmpConstants.h"
|
#include "fmSnmpConstants.h"
|
||||||
#include "fmSnmpUtils.h"
|
#include "fmSnmpUtils.h"
|
||||||
|
|
||||||
typedef std::map<std::string,std::string> configParams;
|
typedef std::map<std::string, std::string> configParams;
|
||||||
|
|
||||||
static const char *conf = NULL;
|
static const char *conf = NULL;
|
||||||
static int config_loaded = false;
|
static int config_loaded = false;
|
||||||
|
|
||||||
std::string trim(std::string str)
|
std::string trim(std::string str) {
|
||||||
{
|
|
||||||
if (str.length() == 0) {
|
if (str.length() == 0) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@ -33,37 +32,37 @@ std::string trim(std::string str)
|
|||||||
return str.substr(first, (last-first+1));
|
return str.substr(first, (last-first+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
CFmMutex & getConfMutex(){
|
CFmMutex & getConfMutex() {
|
||||||
static CFmMutex *m = new CFmMutex;
|
static CFmMutex *m = new CFmMutex;
|
||||||
return *m;
|
return *m;
|
||||||
}
|
}
|
||||||
|
|
||||||
configParams &getConfigMap(){
|
configParams &getConfigMap() {
|
||||||
static configParams conf;
|
static configParams conf;
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fm_conf_set_file(const char *fn){
|
void fm_conf_set_file(const char *fn) {
|
||||||
conf = fn;
|
conf = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fm_get_config_paramters(){
|
void fm_get_config_paramters() {
|
||||||
CfmFile f;
|
CfmFile f;
|
||||||
std::string delimiter = "=";
|
std::string delimiter = "=";
|
||||||
std::string line, key, value;
|
std::string line, key, value;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
|
|
||||||
if (conf == NULL){
|
if (conf == NULL) {
|
||||||
FM_ERROR_LOG("The config file is not set\n");
|
FM_ERROR_LOG("The config file is not set\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!f.open(conf, CfmFile::READ, false)){
|
if (!f.open(conf, CfmFile::READ, false)) {
|
||||||
FM_ERROR_LOG("Failed to open config file: %s\n", conf);
|
FM_ERROR_LOG("Failed to open config file: %s\n", conf);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true){
|
while (true) {
|
||||||
if (!f.read_line(line)) break;
|
if (!f.read_line(line)) break;
|
||||||
|
|
||||||
if (line.size() == 0) continue;
|
if (line.size() == 0) continue;
|
||||||
@ -74,10 +73,10 @@ void fm_get_config_paramters(){
|
|||||||
key = trim(line.substr(0, pos));
|
key = trim(line.substr(0, pos));
|
||||||
value = trim(line.erase(0, pos + delimiter.length()));
|
value = trim(line.erase(0, pos + delimiter.length()));
|
||||||
getConfigMap()[key] = value;
|
getConfigMap()[key] = value;
|
||||||
if (key.compare(FM_SNMP_TRAPDEST) == 0){
|
if (key.compare(FM_SNMP_TRAPDEST) == 0) {
|
||||||
set_trap_dest_list(value);
|
set_trap_dest_list(value);
|
||||||
}
|
}
|
||||||
if (key.compare(FM_SQL_CONNECTION) != 0){
|
if (key.compare(FM_SQL_CONNECTION) != 0) {
|
||||||
// Don't log sql_connection, as it has a password
|
// Don't log sql_connection, as it has a password
|
||||||
FM_INFO_LOG("Config key (%s), value (%s)",
|
FM_INFO_LOG("Config key (%s), value (%s)",
|
||||||
key.c_str(), value.c_str());
|
key.c_str(), value.c_str());
|
||||||
@ -85,17 +84,17 @@ void fm_get_config_paramters(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fm_get_config_key(std::string &key, std::string &val){
|
bool fm_get_config_key(std::string &key, std::string &val) {
|
||||||
configParams::iterator it;
|
configParams::iterator it;
|
||||||
CFmMutexGuard m(getConfMutex());
|
CFmMutexGuard m(getConfMutex());
|
||||||
|
|
||||||
if (!config_loaded){
|
if (!config_loaded) {
|
||||||
fm_get_config_paramters();
|
fm_get_config_paramters();
|
||||||
config_loaded = true;
|
config_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
it = getConfigMap().find(key);
|
it = getConfigMap().find(key);
|
||||||
if (it != getConfigMap().end()){
|
if (it != getConfigMap().end()) {
|
||||||
val = it->second;
|
val = it->second;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user