/* * @brief 轮询目录和文件 * @return 0表示成功,可继续休眠 -1表示轮询过程中出错 */ int polling_files() { DIR *dir; char dirbuffer[FULL_PATH_LEN]; int flag; while (1) { get_ini(foldername, filename); //memcpy(tmpfolder, foldername, FOLDER_NAME_LEN); sprintf(dirbuffer, "%s/%s", data_store_path, foldername); dir = opendir((const char *)dirbuffer); if (dir == NULL) { write_log("Open dir <%s> failed!\n", dirbuffer); return 0; //return and have a rest may be directory have not been constructed } flag = processdir(dir, foldername, filename); if (-1 == flag) { closedir(dir); return -1; //have a rest } //when completly processed this dir we want to get into next folder //but next folder may be have not constructed yet, but if collect module running, //at most 60 secondes elapsed,next folder must be exist! sleep(60); //update_folder(tmpfolder, REALLY_UPDATE_FOLDER); update_folder(foldername, REALLY_UPDATE_FOLDER); closedir(dir); } return 0; }
T iniGet(const std::string &key, const T &default_value) { static std::map<std::string, std::string>& ini = get_ini(); std::map<std::string, std::string>::const_iterator itr=ini.find(key); if(itr!=ini.end()) { std::stringstream ss; ss<<itr->second; T ret; ss>>ret; return ret; }
/** *@brief 获取配置 *@return success 0 failed -1 */ int get_config() { //读取配置文件内的配置 int fd; char buf[1024]; if( init_ini(CONFIG_FILE_NAME, &fd, buf, 1024) ){ return -1; } if( get_ini(buf, "sql_name", cgv_sql_name) ){ return -1; } if( get_ini(buf, "sql_user", cgv_sql_user) ){ return -1; } if( get_ini(buf, "sql_pass", cgv_sql_pass) ){ return -1; } if( get_ini(buf, "report_addr", cgv_report_addr) ){ return -1; } char temp[32]; if( get_ini(buf, "report_port", temp) ){ return -1; } cgv_report_port = atoi( temp ); if( get_ini(buf, "authenticate_port", temp) ){ return -1; } cgv_authenticate_port = atoi( temp ); destroy_ini( fd ); //打印配置文件中读取的配置 xyprintf(0, "** O(∩ _∩ )O ~~ Get config of config file is success!"); xyprintf(0, "sql_name = %s\n\ sql_user = %s\n\ sql_pass = %s", cgv_sql_name, cgv_sql_user, cgv_sql_pass); xyprintf(0, "report_addr = %s\n\ report_port = %u\n\ authenticate_port = %u\n", cgv_report_addr, cgv_report_port, cgv_authenticate_port); //获取数据库内的配置内容 wt_sql_handle *handle = malloc(sizeof(wt_sql_handle)); memset(handle, 0, sizeof(wt_sql_handle)); if( wt_sql_init(handle, cgv_sql_name, cgv_sql_user, cgv_sql_pass) ){ //数据库初始化 xyprintf(0, "SQL_INIT_ERROR:%s %s %d -- Datebase connect error!", __func__, __FILE__, __LINE__); goto ERR; } if( wt_sql_get_gg(handle) ){ goto STR_ERR; } if( wt_sql_get_gg2(handle) ){ goto STR_ERR; } if( wt_sql_get_other(handle) ){ goto STR_ERR; } if( wt_sql_get_white(handle) ){ goto STR_ERR; } if( wt_sql_get_weixin(handle) ){ goto STR_ERR; } if( wt_sql_get_upurl(handle) ){ goto STR_ERR; } wt_sql_destroy(handle); free(handle); return 0; STR_ERR: wt_sql_destroy(handle); free(handle); ERR: return -1; }