bool ConfigFile::load_config() { std::ifstream file; file.open(get_config_file()); if (!file) { LOGE("Config file %s not found", get_config_file().c_str()); return false; } Json::Reader reader; bool success = reader.parse(file, m_root, false); file.close(); if (!success) { LOGE("Failed to parse configuration file"); return false; } const Json::Value jsonversion = m_root[CONF_VERSION]; if (jsonversion.isInt()) { m_version = jsonversion.asInt(); } else { return false; } return true; }
int RakNet_core_server::load_config() { pre_log("start to load test server config file\n"); // 打开配置文件 Inifile inifile; if (inifile.open(get_config_file()) == false) { printf("load %s inifile failed\n", get_config_file()); return 1; } m_network_module = new Network_module; //读取global配置信息 char buffer[100]; inifile.get_value("global", "log_dir", buffer, sizeof(buffer)); pre_log("read global config, log_dir %s\n", buffer); m_network_module->init_log("network_module", buffer, "debug"); inifile.get_value("network_module", "max_connection", buffer, sizeof(buffer)); m_network_module->set_max_connection(buffer); inifile.get_value("network_module", "max_income_connection", buffer, sizeof(buffer)); m_network_module->set_max_income_connection(buffer); inifile.get_value("network_module", "local_port", buffer, sizeof(buffer)); m_network_module->set_local_port(buffer); return 0; }
int Test_server::load_config() { pre_log("start to load test server config file\n"); // 打开配置文件 Inifile inifile; if (inifile.open(get_config_file()) == false) { printf("load %s inifile failed\n", get_config_file()); return 1; } m_module1 = new Module1; // m_module2 = new Module2; m_module1->set_name("module1"); // m_module2->set_name("module2"); //读取global配置信息 char buffer[100]; inifile.get_value("global", "log_dir", buffer, sizeof(buffer)); pre_log("read global config, log_dir %s\n", buffer); m_module1->init_log("module1", buffer, "debug"); // m_module2->init_log("module2", buffer, "debug"); return 0; }
void CAutoPopup::init() { __uint i; popupEntry_t * ent; nEntries = (__uint)GetPrivateProfileInt( "AutoPopup", "count", 0, get_config_file() ); if(nEntries >= maxPopups){ nEntries = maxPopups; } ent = entries; char lineBuf[1024]; char key[4]; memset(&entries, 0, sizeof(entries)); for(i=0; i<nEntries; i++){ sprintf(key, "%d", i); GetPrivateProfileString( "AutoPopup", key, "", lineBuf, sizeof(lineBuf), get_config_file() ); CArgs a; parse_arg_ex(lineBuf, &a, ","); if(a.argc != 5){ continue; } if(!tagname_by_text(&ent->tn, a.argv[0])){ continue; } if(atoi(a.argv[1])){ ent->flags |= popupWhenVariableIsOn; } if(atoi(a.argv[2])){ ent->flags |= popupOverlay; } if(atoi(a.argv[3])){ ent->flags |= popupAutoHide; } strncpy(ent->associatedPicture, a.argv[4], MAX_PATH); ent->associatedPicture[MAX_PATH - 1] = 0; ent++; } nEntries = ent - entries; }
int load_paths() { char filename[256]; int ret = 0; if ( get_config_file( filename ) ) { GetIniString( "PathNames", "roompath", ROOMPATH, ROOMPATH, 255, filename); GetIniString( "PathNames", "monpath", MONPATH, MONPATH, 255, filename); GetIniString( "PathNames", "objpath", OBJPATH, OBJPATH, 255, filename); GetIniString( "PathNames", "playerpath", PLAYERPATH, PLAYERPATH, 255, filename); GetIniString( "PathNames", "docpath", DOCPATH, DOCPATH, 255, filename); GetIniString( "PathNames", "postpath", POSTPATH, POSTPATH, 255, filename); GetIniString( "PathNames", "binpath", BINPATH, BINPATH, 255, filename); GetIniString( "PathNames", "logpath", LOGPATH, LOGPATH, 255, filename); /* make sure we only do this once */ loaded_paths_yet = TRUE; } else ret = -1; return(ret); }
static VOID print_infos(int force) { CHAR16 *config_file; CHAR16 dpath[FILENAME_MAXLEN]; CHAR16 *boot_dev_name; UINT8 is_abs; boot_dev_name = fops_bootdev_name(); config_file = get_config_file(); fops_getdefault_path(dpath, FILENAME_MAXLEN); if (force || elilo_opt.verbose > 0) Print(L"default file path: %s:%s\n", boot_dev_name, dpath); is_abs = config_file && (config_file[0] == CHAR_BACKSLASH || config_file[0] == CHAR_SLASH) ? 1 : 0; if (force || elilo_opt.verbose > 0) Print(L"config file : %s%s\n", config_file && is_abs == 0 ? dpath : L"", config_file ? config_file : L"none used"); if (alt_argv) { CHAR16 **p = alt_argv; Print(L"found alternate default choice :"); while (*p) Print(L" %s", *p++); Print(L"\n"); } }
std::string processHost() { Json::Value root; Json::Value config; Json::Reader reader; std::ostringstream osshelper; std::string config_file = get_config_file(); std::string input = readInputTextFile(config_file.c_str()); bool parsingSuccessful = reader.parse(input, config); if (!parsingSuccessful) { syslog(LOG_ERR, "Failed to parse %s file: \n%s\n", config_file.c_str(), reader.getFormattedErrorMessages().c_str()); return std::string(""); } std::string url_root = getElasticUrl(config, 0); std::string url_state = getElasticUrl(config, 1); std::string url_health = getElasticUrl(config, 2); std::string url_nodes = getElasticUrl(config, 3); processURLEx(url_root, std::string("root"), root, config); processURLEx(url_state, std::string("state"), root, config); processURLEx(url_health, std::string("health"), root, config); processURLEx(url_nodes, std::string("nodes"), root, config); osshelper << root; return osshelper.str(); }
int main(int argc, char *argv[]) { int i; if (argc <= 0 || !argv[0]) { fprintf(stderr, "invalid program name\n"); return 1; } program_name = os_GetLastname(argv[0]); get_program_dir(argv[0]); for (i = 1; i < argc; ++i) { if (!strcmp(argv[i], "--version")) { print_version(); } else if (!strcmp(argv[i], "--help")) { print_help(); } else { die("invalid option: %s", argv[i]); } } get_config_file(); parse_config(); create_dir(); do_loop(); return 0; }
/* determine which tags should be saved to history database. */ void CInMemoryBuffer::buildStreamList() { RTK_CURSOR hNode; RTK_CURSOR hGroup; RTK_CURSOR hTag; PCRTK_TAG pTag; TAG_NAME tn; char nodeName[rtkm_node_key_length + 1]; GetPrivateProfileString( "PMC", "ServerName", "LocalServer", nodeName, sizeof(nodeName), get_config_file() ); CNodeName nodeKey(nodeName); //utils_debug("wlock 3\n"); WriteLock(); if(!lock_rtdb(__false, 100)){ //utils_debug("release 6\n"); Release(); return; } // clear list clearStreamList(); hNode = open_node(nodeKey); if(hNode){ hGroup = cursor_open_first_subitem(hNode); while(!cursor_is_end(hGroup)){ hTag = cursor_open_first_subitem(hGroup); while(!cursor_is_end(hTag)){ pTag = (PCRTK_TAG)cursor_get_item(hTag); if(pTag->s.Flags & TF_SaveToHistory){ tn.node = pTag->node; tn.sname.group = pTag->group; tn.sname.tag = pTag->key; addTag(&tn); } cursor_move_next(hTag); } close_handle(hTag); cursor_move_next(hGroup); } close_handle(hGroup); } unlock_rtdb(); //utils_debug("release 7\n"); Release(); }
Config* config_get(int argc, char** argv) { Config* config = (Config*) malloc(sizeof(Config)); FILE* file = get_config_file(argc, argv); load(file, config); fclose(file); return config; }
void CDCSItem::Save() { m_sCaption = framDCSView->edtName->Text; WritePrivateProfileString( "pmc", "name", m_sCaption.c_str(), get_config_file() ); m_ViewItem->Text = m_sCaption; }
/* 功能:读取配置文件[PMC]下的MaxChangeRate和TagLife 参数:无 返回:无 */ static void _load_settings() { char buf[32]; *buf = 0; GetPrivateProfileString( "PMC", "MaxChangeRate", "0.01", buf, sizeof(buf), get_config_file() ); g_fltMaxChangeRate = (__r4)atof(buf); if(g_fltMaxChangeRate < 0.0001 || g_fltMaxChangeRate > 5){ utils_error( "MaxChangeRate=%.3f%% is not valid.\n", g_fltMaxChangeRate ); g_fltMaxChangeRate = (__r4)rtkm_default_change_rate; } utils_trace("MaxChangeRate is set to %.3f%% \n", g_fltMaxChangeRate); *buf = 0; GetPrivateProfileString( "PMC", "TagLife", "60", buf, sizeof(buf), get_config_file() ); g_fltTagLife = (__r4)atof(buf); if(g_fltTagLife < 5){ utils_error( "TagLife=%.1fs is not valid, reset to 5s.\n", g_fltTagLife ); } utils_trace("TagLife is set to %.1fs\n", g_fltTagLife); }
int main(int argc, char *argv[]) { char *dir = "."; char *pdb = NULL; int ec; printf("agi2pdb v" VERSION " - Converting Sierra AGI files to PalmOS Database\n" "(C) Copyright 2001-2002 Stuart George & Thomas Akesson\n" "\n" "This program is free software; you can redistribute it and/or modify it\n" "under the terms of the GNU General Public License, version 2 or later,\n" "as published by the the Free Software Foundation.\n" "\n"); if(argc>3 || (argc==2 && argv[1][1]=='?')) { printf("syntax:\n" " agi2pdb {directory} {game.pdb}\n"); return 0; } else if (argc>1){ dir = argv[1]; if (argc>2) pdb = argv[2]; } ec = agi_detect_game (dir); if (ec == err_OK) { if (loader == &agi_v2) printf("AGI version 2 game detected.\n"); else printf("AGI version 3 game detected.\n"); if (pdb == NULL) { pdb = (char*) malloc(32); match_crc_name (game.crc, get_config_file(), pdb); } if (game.ver) { agi_init(); convert2pdb (loader, pdb); } else { printf("Game version could not be determined.\n" "Make sure Sarien configuration file is available!\n"); } } else { printf("No AGI game detected.\n"); return 1; } return 0; }
void config_handler::print() { // // Display internal settings set from reading steering // string mn = "print:"; string def = "<default>"; int w1=30; //arbitrary spacing size that makes formatting look pretty for data names int w2=30; //arbitrary spacing size that makes formatting look pretty for data options cout<<cn<<mn<<" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" <<"\n"<<setw(w1)<<"DEBUG: " <<setw(w2)<<(debug? "ON":"OFF") <<"\n"<<setw(w1)<<"RUN IN BACKGROUND: " <<setw(w2)<<(get_background()? "ON":"OFF") <<"\n"<<setw(w1)<<"SIMULATION: " <<setw(w2)<<(get_simulate()? "ON":"OFF") <<"\n"<<setw(w1)<<"FILTER FIRST: " <<setw(w2)<<(get_filter()? "ON":"OFF") <<"\n"<<setw(w1)<<"SAVE RECORDINGS: " <<setw(w2)<<(get_save_rec()? "ON":"OFF") <<"\n"<<setw(w1)<<"HUMAN READABLE OUTPUT: " <<setw(w2)<<(get_output_formatted()? "ON":"OFF") <<"\n"<<setw(w1)<<"Output Type ID: " <<setw(w2)<<"\""<<get_output_type_id()<<"\"" <<"\n"<<setw(w1)<<"RPi Latitude: " <<setw(w2)<<"\""<<get_latitude()<<"\"" <<"\n"<<setw(w1)<<"RPi Longitude: " <<setw(w2)<<"\""<<get_longitude()<<"\"" <<"\n"<<setw(w1)<<"RPi ID: " <<setw(w2)<<"\""<<get_rpid()<<"\"" <<"\n"<<setw(w1)<<"Simulation Data Dir: " <<setw(w2)<<"\""<<get_simulate_dir()<<"\"" <<"\n"<<setw(w1)<<"Config Path: " <<setw(w2)<<"\""<<get_config_file_path()<<"\"" <<"\n"<<setw(w1)<<"Config Name: " <<setw(w2)<<"\""<<get_config_file_name()<<"\"" <<"\n"<<setw(w1)<<"Config File: " <<setw(w2)<<"\""<<get_config_file()<<"\"" <<"\n"<<setw(w1)<<"Final Feature Format: " <<setw(w2)<<"\""<<get_final_feature_format()<<"\"" <<"\n"<<setw(w1)<<"Filter Vector Path: " <<setw(w2)<<"\""<<get_fv_filter_path()<<"\"" <<"\n"<<setw(w1)<<"Filter Vector Name: " <<setw(w2)<<"\""<<get_fv_filter_name()<<"\"" <<"\n"<<setw(w1)<<"Filter Vector File: " <<setw(w2)<<"\""<<get_fv_filter()<<"\"" <<"\n"<<setw(w1)<<"Feature Vector Path: " <<setw(w2)<<"\""<<get_fv_file_path()<<"\"" <<"\n"<<setw(w1)<<"Feature Vector Name: " <<setw(w2)<<"\""<<get_fv_file_name()<<"\"" <<"\n"<<setw(w1)<<"Feature Vector File: " <<setw(w2)<<"\""<<get_fv_file()<<"\"" <<"\n"<<setw(w1)<<"Analysis File(s) Path: " <<setw(w2)<<"\""<<get_analysis_location()<<"\"" <<"\n"<<setw(w1)<<"Data File(s) Path: " <<setw(w2)<<"\""<<get_data_location()<<"\"" <<"\n"<<setw(w1)<<"Media Location File Path: " <<setw(w2)<<"\""<<get_media_location()<<"\"" <<"\n"<<setw(w1)<<"Recording Extention: " <<setw(w2)<<"\""<<get_rec_extention()<<"\"" <<"\n"<<setw(w1)<<"Recording File Name Prefix: " <<setw(w2)<<"\""<<get_rec_file_name_prefix()<<"\"" <<"\n"<<setw(w1)<<"Recording Rate: " <<setw(w2)<<"\""<<get_samp_rate()<<"\"" <<"\n"<<setw(w1)<<"Recording Duration: " <<setw(w2)<<"\""<<get_rec_duration()<<"\"" <<"\n"<<setw(w1)<<"Recording Number: " <<setw(w2)<<"\""<<get_rec_number()<<"\""<<endl; cout<<cn<<mn<<" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl; return; }
/* _on_system() */ void PMC_API _on_system(PCRTK_PACKET packet, HVBUS bus) { #if 0 if(get_power_state() != PWR_RUNNING){ return; } #endif { static __bool priorityBoosted = __false; if(!priorityBoosted){ DWORD boost; boost = GetPrivateProfileInt( "vbus", "SystemBoost", THREAD_PRIORITY_ABOVE_NORMAL, get_config_file() ); SetThreadPriority(GetCurrentThread(), boost); priorityBoosted = __true; } } if(packet->packet_type != PT_ServerClaim){ return; } if(!lock_rtdb(__false, 1000)){ return; } RTK_CURSOR hNode; PRTK_NODE pNode; TAG_NAME tn; host_to_node(&packet->src.host, &tn.node); hNode = open_node(&tn.node); pNode = (PRTK_NODE)cursor_get_item(hNode); if(pNode){ pNode->dogcount = g_NodeLife; } close_handle(hNode); unlock_rtdb(); if(!pNode && g_Worker){ memset(&tn.sname, 0, sizeof(tn.sname)); g_Worker->inform_load(&tn, 1); } }
/* Read port setting from config file */ __bool CSerialPort::get_config_string() { char port[16]; sprintf(port,"port%d",m_iPortNo); if( !GetPrivateProfileString( "ports", port, SPAC_DEFAULT_SETTING, m_Setting, sizeof(m_Setting), get_config_file() ) ){ strncpy(m_Setting, SPAC_DEFAULT_SETTING, sizeof(m_Setting)); m_Setting[sizeof(m_Setting) - 1] = 0; } return __true; }
void PythonCompletionFramework::load_preferences() { JediCompletePluginPref* pref = JediCompletePluginPref::instance(); std::string config_file = get_config_file(); // Initialising options from config file GKeyFile* keyfile = g_key_file_new(); if (g_key_file_load_from_file(keyfile, config_file.c_str(), G_KEY_FILE_NONE, NULL)) { const char* group = get_plugin_name(); pref->row_text_max = g_key_file_get_integer(keyfile, group, "maximum_char_in_row", NULL); pref->suggestion_window_height_max = g_key_file_get_integer(keyfile, group, "maximum_sug_window_height", NULL); pref->page_up_down_skip_amount = g_key_file_get_integer(keyfile, group, "page_up_down_skip_amount", NULL); pref->start_completion_with_dot = g_key_file_get_boolean(keyfile, group, "start_completion_with_dot", NULL); pref->jedi_server_port = g_key_file_get_integer(keyfile, group, "server_port", NULL); gchar* temp; temp = g_key_file_get_string(keyfile, group, "python_path", NULL); pref->python_path = temp; g_free(temp); } else { pref->row_text_max = 120; pref->suggestion_window_height_max = 300; pref->page_up_down_skip_amount = 4; pref->start_completion_with_dot = true; pref->jedi_server_port = 8080; pref->python_path = "/usr/bin/python"; } // hidden preference "server_script_dir" gchar* dirname = g_path_get_dirname(config_file.c_str()); pref->server_script_dir = dirname; g_free(dirname); g_key_file_free(keyfile); this->updated_preferences(); }
CDCSItem::CDCSItem() { char buf[256]; GetPrivateProfileString( "pmc", "name", "NicBuilder 工业监控系统", buf, sizeof(buf), get_config_file() ); m_iIcon = 25; m_sCaption = buf; if(!framDCSView){ framDCSView = new TframDCSView(0); framDCSView->Tag = (int)this; } m_PropertyPage = framDCSView; m_SearchKey = "DCS"; m_ClassName = "NicBuilder 工业监控系统"; }
void PythonCompletionFramework::save_preferences() { std::string config_file = get_config_file(); GKeyFile* keyfile = g_key_file_new(); const char* group = get_plugin_name(); JediCompletePluginPref* pref = JediCompletePluginPref::instance(); g_key_file_set_integer(keyfile, group, "maximum_char_in_row", pref->row_text_max); g_key_file_set_integer(keyfile, group, "maximum_sug_window_height", pref->suggestion_window_height_max); g_key_file_set_integer(keyfile, group, "page_up_down_skip_amount", pref->page_up_down_skip_amount); g_key_file_set_boolean(keyfile, group, "start_completion_with_dot", pref->start_completion_with_dot); g_key_file_set_integer(keyfile, group, "server_port", pref->jedi_server_port); g_key_file_set_string(keyfile, group, "python_path", pref->python_path.c_str()); geanycc::util::save_keyfile(keyfile, config_file.c_str()); g_key_file_free(keyfile); }
config_handler::config_handler( string fpath, string fname = "" ) { string mn = "config_handler:"; cout<<mn<<" Constructor started for file \""<<fname<<"\"."<<endl; debug = true; init(); if( fpath == "" ) fpath = utils::get_home_dir(); if( fname == "" ) utils::get_base( fpath ); if( fname == "" ) fname = "cirainbow.conf"; // make sure default or custom config file is found // User coice, home directory "cirainbow.conf", local directory "sound_settings.conf" if( utils::is_file_readable( utils::pathify(fpath) + fname ) == false ) { cout<<cn<<mn<<" Initial config file not accesable at: \""<<utils::pathify(fpath)+fname<<"\"."<<endl; fpath = utils::get_base_dir(); fname = "sound_settings.conf"; } //cout<<cn<<mn<<" Config file here: \""<<utils::pathify(fpath)+fname<<"\"."<<endl; //TEST //exit( 0 ); //TEST set_config_file_path( fpath ); set_config_file_name( fname ); string configFile = get_config_file_path() + get_config_file_name(); set_config_file( configFile ); cout<<cn<<mn<<" Config file here: \""<<get_config_file()<<"\"."<<endl; read_config( configFile ); cout<<cn<<mn<<" Constructor finished for file \""<<fname<<"\"."<<endl; }
void _load_settings(__bool bSilent) { char buf[32]; if(!bSilent){ utils_trace("Loading proxy settings...\n"); } g_NodeLife = GetPrivateProfileInt( "PMC", "NodeLife", rtkm_default_node_life, get_config_file() ); if(g_NodeLife < 200 || g_NodeLife > 60000){ g_NodeLife = rtkm_default_node_life; } if(!bSilent){ utils_trace( "Node will be kicked after idle for %d ms.\n", g_NodeLife ); } *buf = 0; GetPrivateProfileString( "PMC", "TagLife", "120", buf, sizeof(buf), get_config_file() ); g_fltTagLife = (__r4)atof(buf); if(g_fltTagLife < 5){ utils_error( "TagLife=%.1fs is not valid, reset to %.1fs.\n", g_fltTagLife, rtkm_default_tag_life ); g_fltTagLife = rtkm_default_tag_life; }else{ if(!bSilent){ utils_trace("TagLife is set to %.1fs\n", g_fltTagLife); } } CProxyWorker::m_MaxBgLoads = GetPrivateProfileInt( "PMC", "MaxBgLoad", 256, get_config_file() ); if(!bSilent){ utils_trace("BGLoader's queue length is %d entries.\n", CProxyWorker::m_MaxBgLoads); } g_QueryInterval = GetPrivateProfileInt( "PMC", "QueryInterval", 1000, get_config_file() ); if(g_QueryInterval < 1000 || g_QueryInterval > 30000){ if(!bSilent){ utils_error("QueryInterval=%d is invalid, setting to default."); } g_QueryInterval = 1000; } if(!bSilent){ utils_trace("Query interval set to %d.\n", g_QueryInterval); } }
/* * Returns false on error * true on OK, with full_path set to where config file should be */ bool CONFIG::find_config_path(POOL_MEM &full_path) { bool found = false; POOL_MEM config_dir; POOL_MEM config_path_file; if (!m_cf) { /* * No path is given, so use the defaults. */ found = get_config_file(full_path, get_default_configdir(), m_config_default_filename); if (!found) { config_path_file.strcpy(full_path); found = get_config_include_path(full_path, get_default_configdir()); } if (!found) { Jmsg2(NULL, M_ERROR, 0, _("Failed to read config file at the default locations " "\"%s\" (config file path) and \"%s\" (config include directory).\n"), config_path_file.c_str(), full_path.c_str()); } } else if (path_exists(m_cf)) { /* * Path is given and exists. */ if (path_is_directory(m_cf)) { found = get_config_file(full_path, m_cf, m_config_default_filename); if (!found) { config_path_file.strcpy(full_path); found = get_config_include_path(full_path, m_cf); } if (!found) { Jmsg3(NULL, M_ERROR, 0, _("Failed to find configuration files under directory \"%s\". " "Did look for \"%s\" (config file path) and \"%s\" (config include directory).\n"), m_cf, config_path_file.c_str(), full_path.c_str()); } } else { full_path.strcpy(m_cf); path_get_directory(config_dir, full_path); m_config_dir = bstrdup(config_dir.c_str()); found = true; } } else if (!m_config_default_filename) { /* * Compatibility with older versions. * If m_config_default_filename is not set, * m_cf may contain what is expected in m_config_default_filename. */ found = get_config_file(full_path, get_default_configdir(), m_cf); if (!found) { Jmsg2(NULL, M_ERROR, 0, _("Failed to find configuration files at \"%s\" and \"%s\".\n"), m_cf, full_path.c_str()); } } else { Jmsg1(NULL, M_ERROR, 0, _("Failed to read config file \"%s\"\n"), m_cf); } if (found) { set_env("BAREOS_CFGDIR", m_config_dir); } return found; }
BOOL CMcEvtQueryApp::InitInstance() { //get app path char lpFilename[_MAX_PATH]; memset(lpFilename,0,_MAX_PATH); GetModuleFileName( NULL,lpFilename,_MAX_PATH); char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _splitpath( lpFilename, drive, dir, fname, ext ); CString sAppDrive=drive; CString sAppPath=dir; m_path=sAppDrive+sAppPath; GetPrivateProfileString("evtlq", "folder", (LPCSTR)m_path, lpFilename, _MAX_PATH, get_config_file()); m_folder=lpFilename; AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. //SetRegistryKey(_T("Local AppWizard-Generated Applications")); // To create the main window, this code creates a new frame window // object and then sets it as the application's main window object. CMainFrame* pFrame = new CMainFrame; m_pMainWnd = pFrame; // create and load the frame with its resources //pFrame->LoadFrame(IDR_MAINFRAME, // WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, // NULL); pFrame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW,NULL,NULL); // The one and only window has been initialized, so show and update it. pFrame->ShowWindow(SW_SHOW); pFrame->UpdateWindow(); CMCCommand cmdInfo; ParseCommandLine(cmdInfo); if(cmdInfo.bShowAtTop){ pFrame->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); } return TRUE; }
bool CRtkService::_init() { char serverName[rtkm_node_key_length + 1]; m_bPending = __true; PrimaryCheckInterval = GetPrivateProfileInt( "PMC", "PrimaryCheckInterval", 500, get_config_file() ); if(PrimaryCheckInterval < 50 || PrimaryCheckInterval > 5000){ utils_error( "Warning : PrimaryCheckInterval=%d is invalid, reset to 500.\n", PrimaryCheckInterval ); PrimaryCheckInterval = 500; } MaxPrimaryWatchDogCounter = GetPrivateProfileInt( "PMC", "PrimaryWatchDogCounter", 8, get_config_file() ); if(MaxPrimaryWatchDogCounter < 3 || MaxPrimaryWatchDogCounter > 50){ utils_error( "Warning : PrimaryWatchDogCounter=%d is invalid, reset to 20.\n", PrimaryWatchDogCounter ); MaxPrimaryWatchDogCounter = 8; } PrimaryWatchDogCounter = MaxPrimaryWatchDogCounter; m_bPending = __false; init_powermgr(); #ifdef _WIN32 init_spac();//初始化得到security descriptor、mutex对象句柄数组mutics[]和event对象句柄数组events[] #endif init_server_shell();//创建g_shell init_config();//空函数。。。 GetPrivateProfileString( "PMC", "ServerName", "", serverName, sizeof(serverName), get_config_file() ); //若pmc.ini中没有给出节点名,取本机名为节点名 if(!serverName[0]){ DWORD len; len = sizeof(serverName); GetComputerName(serverName, &len); } //初始化网络,即设定一些值,创建链表g_buses,<bus_id, CRtkVBus*>,并开启5个VBUS线程 if(!init_network(RTK_INIT_AS_SERVER, serverName)){ return false; } //给g_buses中的4个元素的CRtkVBus的成员赋值 connect_vbus( BUSID_RTDB, VBUS_CONNECT_AS_SERVER, on_rtdb, rtdb_filter ); connect_vbus( BUSID_SYSTEM, VBUS_CONNECT_AS_SERVER, on_system, server_filter ); connect_vbus( BUSID_OPERATION, VBUS_CONNECT_AS_SERVER, on_operation, server_filter ); connect_vbus( BUSID_CONFIG, VBUS_CONNECT_AS_SERVER, on_config, server_filter ); utils_trace("Networking Subsystem initialized.\n"); register_power_callback(power_state_changed, 0);//创建一个CALLBACK_ITEM,用形参给其成员赋值,并链接上RTK_LIST_ENTRY // checking primary site if(!setup_running_state()){ return false; } setup_rtdb();//在pmc.ini中寻找组名,加载组名对应的*.csv文件中的标签到内存,并开启一个线程。 utils_trace("Realtime Database Subsystem initialized.\n"); init_ioss(); utils_trace("IO Susbsystem initialized.\n"); utils_trace("%s started...\n", versionString.c_str()); if(get_power_state() == PWR_RUNNING){ online_broadcast();//发送一个报警数据包,RTK_ALARM_PACKET型 } return true; }
void ConfigFile::write_config() { std::ofstream file; file.open(get_config_file()); file << m_root; file.close(); }
int main(int argc, char** argv) { return parse_options(argc, argv) || list_commands(get_config_file()) || show_gui(&argc, &argv); }
static char *get_config_file (const char *filename) { const char *try[] = {"XDG_CONFIG_HOME", "APPDATA", "HOME", NULL}; char *conf_file, *conf_dir; int i = 0; do { conf_dir = getenv (try[i++]); } while (conf_dir == NULL && try[i] != NULL); if (conf_dir == NULL) { conf_file = g_strdup (filename); } else { conf_dir = g_build_filename (conf_dir, "s4", NULL); if (g_mkdir_with_parents (conf_dir, 0700) == -1) { conf_file = g_strdup (filename); fprintf (stderr, "Could not create %s - %s\n", conf_dir, strerror (errno)); } else { conf_file = g_build_filename (conf_dir, filename, NULL); } g_free (conf_dir); } return conf_file; } #define HEX_TO_CHAR(h) ((h)<10?(h) + '0':(h) + 'a' - 9) #define CHAR_TO_HEX(c) (((c) & 0xf) + (((c) & 0x40) >> 6) * 9) static void encode_string (const char *val, char *buf) { for (; *val; val++) { if (isalnum (*val)) { *buf++ = *val; } else { *buf++ = '%'; *buf++ = HEX_TO_CHAR ((*val >> 4) & 0xf); *buf++ = HEX_TO_CHAR (*val & 0xf); } } *buf = '\0'; } static void decode_string (char *buf) { char *w, *r; for (w = r = buf; *r; w++, r++) { if (*r == '%') { *w = CHAR_TO_HEX (*(r+1)) << 4 | CHAR_TO_HEX (*(r+2)); r += 2; } else { *w = *r; } } *w = '\0'; } void config_init (void) { FILE *file; char key[1024], value[4096]; int i; for (i = 0; user_vars[i].key != NULL; i++) { user_vars[i].value = strdup (user_vars[i].default_value); } config_file = get_config_file (CONFIG_FILENAME); file = fopen (config_file, "r"); if (file == NULL) { fprintf (stderr, "Could not open %s - %s\n", config_file, strerror (errno)); return; } while (fscanf (file, " %s = %s ", key, value) != EOF) { decode_string (value); set_var (key, strdup (value)); } fclose (file); } void config_cleanup (void) { FILE *file; char value[4096]; int i; file = fopen (config_file, "w"); if (file == NULL) { fprintf (stderr, "Could not open %s - %s\n", config_file, strerror (errno)); return; } for (i = 0; user_vars[i].key != NULL; i++) { encode_string (user_vars[i].value, value); fprintf (file, "%s = %s\n", user_vars[i].key, value); } fclose (file); g_free (config_file); } /* Sets the configuration variable key to val. */ void set_var (const char *key, char *val) { int i, j; for (i = 0; user_vars[i].key != NULL; i++) { if (strcmp (key, user_vars[i].key) == 0) { if (user_vars[i].possible_values[0] != NULL) { for (j = 0; user_vars[i].possible_values[j] != NULL; j++) { if (strcmp (user_vars[i].possible_values[j], val) == 0) { break; } } if (user_vars[i].possible_values[j] == NULL) { fprintf (stderr, "%s is not a valid value for %s\n", val, key); free (val); return; } } free (user_vars[i].value); user_vars[i].value = val; return; } } fprintf (stderr, "%s is not a configuration variable\n", key); free (val); }
void config_handler::read_config( string fname="" ) { // // read steering from file fname // string mn = "read_config:"; //Method name, for printing bool sound_section = false; //flag for only parsing the sound related sections string confFileName = fname; if( fname == "" ) confFileName = get_config_file(); cout<<cn<<mn<<" Searching for config file \""<<confFileName<<"\"..."<<endl; //ensure config provided is found and readable ifstream infile( confFileName.c_str(), ios::in ); if( !infile ){ // Check open cerr<<cn<<mn<<" ERROR: Can't open \""<<confFileName<<"\""<<endl; infile.close(); exit(1); } else { if( confFileName != get_config_file() ) { this->set_config_file( confFileName ); } if (debug) cout<<cn<<mn<<" Reading config file \""<<confFileName<<"\""<<endl; } // prepare to read string curLine; string optionName; string optionValue; int w = 20; //arbitrary width units that make formatting nice // read all options from text file while (infile.good()) { // get one whole line at a time getline(infile, curLine); curLine = trim(curLine); //remove leading and trailing white space // check for correct config file section as we go through all of the config file if( curLine.front() == '[' && curLine.back() == ']' ) { string section_name = curLine.substr( curLine.find_last_of("[")+1, curLine.find_last_of("]")-1 ); if( section_name == "NODE_INFO" || section_name == "SOUND" ) { sound_section = true; } else { sound_section = false; } cout<<cn<<mn<<" Section name: \""<<section_name<<"\". This is a sound section? "<<(sound_section? "YES":"NO")<<endl; } // Only parse the relevnt sound sections if( sound_section == true ) { // retrieve the option name and it's value seperatly for further parsing int optionSep = curLine.find('='); //optioname and value are seperated by aan equals sign optionName = trim(curLine.substr(0, optionSep)); optionValue = trim(curLine.substr(optionSep+1, curLine.size())); //'optionValue' could be broken up further if needed if (debug) { cout<<cn<<mn<<" Read in:>>>>>>>>>>>" <<"\n"<<setw(w)<<"currentLine: \""<<curLine<<"\"" <<"\n"<<setw(w)<<" optionName: \""<<optionName<<"\"" <<"\n"<<setw(w)<<"optionValue: \""<<optionValue<<"\"" <<"\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl; } if(curLine[0] != '#' && !curLine.empty() ) { //ignore lines beginning with comments - could be done better if( optionName == optionValue && optionName != "debug" ) { cerr<<cn<<mn<<" ERROR: config option \""<<optionName<<"\" found but no value set!"<<endl; } else if ( optionName == "debug" ) { debug=true; cout<<cn<<mn<<" Debug turned on!"<<endl; } else if ( optionName == "recordingduration" ) { set_rec_duration( utils::string_to_number<int>( optionValue ) ); } else if ( optionName == "recordingnumber" ) { set_rec_number( utils::string_to_number<int>( optionValue ) ); } else if ( optionName == "recordingprefix" ) { set_rec_file_name_prefix( optionValue ); } else if ( optionName == "samplerate" ) { set_samp_rate( utils::string_to_number<int>( optionValue ) ); } else if ( optionName == "featureplanpath" ) { set_fv_file_path( optionValue ); } else if ( optionName == "featureplanname" ) { set_fv_file_name( optionValue ); } else if ( optionName == "filterplanpath" ) { set_fv_filter_path( optionValue ); } else if ( optionName == "filterplanname" ) { set_fv_filter_name( optionValue ); } else if ( optionName == "recordingextention" ) { set_rec_extention( optionValue ); } else if ( optionName == "medialocation" ) { set_media_location( optionValue ); } else if ( optionName == "datalocation" ) { set_data_location( optionValue ); } else if ( optionName == "analysislocation" ) { set_analysis_location( optionValue ); } else if ( optionName == "latitude" ) { set_latitude( optionValue ); } else if ( optionName == "longitude" ) { set_longitude( optionValue ); } else if ( optionName == "rasberrypiid" ) { set_rpid( optionValue ); } else if ( optionName == "simulationdirectory" ) { set_simulate_dir( optionValue ); } else if ( optionName == "outputform" ) { set_final_feature_format( optionValue ); } else if ( optionName == "outputtypeid" ) { set_output_type_id( utils::string_to_number<int>( optionValue ) ); } else if ( optionName == "outputhumanreadable" ) { if( optionValue == "on" ) set_output_formatted( true ); else set_output_formatted( false ); } else if ( optionName == "simulate" ) { if( optionValue == "on" ) set_simulate( true ); else set_simulate( false ); } else if ( optionName == "background" ) { if( optionValue == "on" ) set_background( true ); else set_background( false ); } else if ( optionName == "filter" ) { if( optionValue == "on" ) set_filter( true ); else set_filter( false ); } else if ( optionName == "analysis" ) { if( optionValue == "on" ) set_analysis( true ); else set_analysis( false ); } else if ( optionName == "saverecording" ) { if( optionValue == "on" ) set_save_rec( true ); else set_save_rec( false ); } else { cerr<<cn<<mn<<" WARN: Invalid config option found '"<<curLine<<"'"<<endl; //exit(0); //stop if an invalid option found, it's probably an error! } } } } // feature plans can be listed a few different ways, ensure they are appropratly formatted string file = ""; if( fv_filter_path != "" ) file = get_fv_filter_path(); else file = utils::get_base_dir(); if( fv_filter_name != "" ) file += get_fv_filter_name(); else file += "featureplan_filter"; set_fv_filter( file ); if( fv_file_path != "" ) file = get_fv_file_path(); else file = utils::get_base_dir(); if( fv_file_name != "" ) file += get_fv_file_name(); else file += "featureplan"; set_fv_file( file ); // set default directoryies for simulations, if none were provided string simDataDir = utils::pathify( utils::get_base_dir() + "test/" ); if( get_simulate() == true ) { if( get_simulate_dir() == "" ) { if( get_final_feature_format() == "WRAPPED" ) simDataDir += "data_fv/"; else if( get_final_feature_format() == "FILES" ) simDataDir += "data_yaafe/"; set_simulate_dir( simDataDir ); } } if(debug) { cout<<cn<<mn<<" Finished reading config. REPORT:"<<endl; this->print(); } infile.close(); //cleanup return; }