void CXmlConfig::GetServerInfo(std::string &ip, short &port) { CMarkupSTL MarkupXml; MarkupXml.Load(configfile.c_str()); bool bRet = MarkupXml.FindChildElem("port"); assert(bRet); MarkupXml.IntoElem(); port = atoi(MarkupXml.GetData().c_str()); }
void c_server::loadStorage(wisdom_IOStream& os) { CMarkupSTL config; if (!config.Load(TS_CONFIG)) return; c_wlock lock(&m_lock); m_storage.clear(); //根节点 config.FindElem(); while (config.FindChildElem("storage")) { config.IntoElem(); wisdom_storage og = new _storage; og->cb = new _storage_cb; string interval; if (config.FindChildElem("interval", true)) interval = config.GetChildData().c_str(); sscanf(interval.c_str(), "%x#%x", &og->ibegin, &og->iend); if (config.FindChildElem("constr", true)) og->cb->m_constr = config.GetChildData().c_str(); LOG4_INFO("storage begin:" << og->ibegin << "|end:" << og->iend << "|constr:" << og->cb->constr()); os->push(__tos("storage begin:" << og->ibegin << "|end:" << og->iend << "|constr:" << og->cb->constr())); config.OutOfElem(); m_storage.insert(make_pair(c_interval(og->ibegin, og->iend), og)); } return; }
bool c_server::LoadConfig() { CMarkupSTL config; if (!config.Load(TS_CONFIG)) return false; //根节点 config.FindElem(); if (config.FindChildElem("server", true)) { config.IntoElem(); if (config.FindChildElem("port", true)) c_config::get_instance()->m_port = atoi(config.GetChildData().c_str()); if (config.FindChildElem("threads", true)) m_threads = atoi(config.GetChildData().c_str()); if (config.FindChildElem("delay", true)) m_delay = atoi(config.GetChildData().c_str()); config.OutOfElem(); } wisdom_IOStream os = new c_ostream_array; loadStorage(os); return true; }
bool CFileOperate::_Load() { UPLOAD_LOG_TYPE upload_load_type = _GetUpLoadLogType(); if (upload_load_type == NAME_SERVER_LOG) { char szPath[255]; sprintf(szPath,"../share_config/share_log_config.xml"); CMarkupSTL oxml; if (!oxml.Load(szPath) ){ USER_LOG_ERROR("cannot load "<<szPath); assert(false); return false; } if (!oxml.FindElem("root") ){ USER_LOG_ERROR("can not find root node "<<szPath); assert(false); return false; } if (!oxml.IntoElem()){ USER_LOG_ERROR("can not into root node "<<szPath); assert(false); return false; } if (!oxml.FindElem("logtype") ){ USER_LOG_ERROR("can not find logtype node "<<szPath); assert(false); return false; } if (!oxml.IntoElem()){ USER_LOG_ERROR("can not into logtype node "<<szPath); assert(false); return false; } log_directory_map log_directory_map_tmp; while (oxml.FindElem("type")) { LogStruct log_struct_tmp; log_struct_tmp.folder_name = oxml.GetAttrib("name"); log_struct_tmp.log_file_head = oxml.GetAttrib("log_file_head"); log_struct_tmp.log_file_trail = oxml.GetAttrib("log_file_trail"); if (!log_struct_tmp.folder_name.empty()) { std::map<std::string,std::string> remote_local_directory; std::string remote_direcotry = "ftp://"; remote_direcotry += CCurlFtpMgr::Instance().GetFtpHost(); remote_direcotry += ":"; remote_direcotry += CCurlFtpMgr::Instance().GetFtpPort(); remote_direcotry += "/"; remote_direcotry += "name_server/"; remote_direcotry += log_struct_tmp.folder_name; remote_direcotry += "/"; std::string local_directory = "..\\"; local_directory += log_struct_tmp.folder_name; local_directory += "\\"; remote_local_directory.insert(std::pair<std::string,std::string>(remote_direcotry,local_directory)); log_directory_map_tmp.insert(std::pair<LogStruct,std::map<std::string,std::string>>(log_struct_tmp,remote_local_directory)); } } m_log_directory.insert(std::pair<UPLOAD_LOG_TYPE,log_directory_map>(upload_load_type,log_directory_map_tmp)); oxml.OutOfElem(); oxml.OutOfElem(); } else if (upload_load_type == LG_SERVER_LOG) { std::string lg_id = ""; { char szPath[255]; sprintf(szPath,"../config/lg_config.xml"); CMarkupSTL oxml; if (!oxml.Load(szPath) ){ USER_LOG_ERROR("cannot load "<<szPath); assert(false); return false; } if (!oxml.FindElem("root") ){ USER_LOG_ERROR("can not find root node "<<szPath); assert(false); return false; } if (!oxml.IntoElem()){ USER_LOG_ERROR("can not into root node "<<szPath); assert(false); return false; } if (!oxml.FindElem("loginserver") ){ USER_LOG_ERROR("can not find loginserver node "<<szPath); assert(false); return false; } if (!oxml.IntoElem()){ USER_LOG_ERROR("can not into loginserver node "<<szPath); assert(false); return false; } if (!oxml.FindElem("id") ){ USER_LOG_ERROR("can not find id node "<<szPath); assert(false); return false; } lg_id = oxml.GetAttrib("value"); } { char szPath[255]; sprintf(szPath,"../share_config/share_log_config.xml"); CMarkupSTL oxml; if (!oxml.Load(szPath) ){ USER_LOG_ERROR("cannot load "<<szPath); assert(false); return false; } if (!oxml.FindElem("root") ){ USER_LOG_ERROR("can not find root node "<<szPath); assert(false); return false; } if (!oxml.IntoElem()){ USER_LOG_ERROR("can not into root node "<<szPath); assert(false); return false; } if (!oxml.FindElem("logtype") ){ USER_LOG_ERROR("can not find logtype node "<<szPath); assert(false); return false; } if (!oxml.IntoElem()){ USER_LOG_ERROR("can not into logtype node "<<szPath); assert(false); return false; } log_directory_map log_directory_map_tmp; while (oxml.FindElem("type")) { LogStruct log_struct_tmp; log_struct_tmp.folder_name = oxml.GetAttrib("name"); log_struct_tmp.log_file_head = oxml.GetAttrib("log_file_head"); log_struct_tmp.log_file_trail = oxml.GetAttrib("log_file_trail"); if (!log_struct_tmp.folder_name.empty()) { std::map<std::string,std::string> remote_local_directory; std::string remote_direcotry = "ftp://"; remote_direcotry += CCurlFtpMgr::Instance().GetFtpHost(); remote_direcotry += ":"; remote_direcotry += CCurlFtpMgr::Instance().GetFtpPort(); remote_direcotry += "/"; remote_direcotry += "area_"; remote_direcotry += lg_id.substr(0,1); remote_direcotry += "/"; remote_direcotry += "lg_"; remote_direcotry += lg_id; remote_direcotry += "/"; remote_direcotry += log_struct_tmp.folder_name; remote_direcotry += "/"; std::string local_directory = "..\\"; local_directory += log_struct_tmp.folder_name; local_directory += "\\"; remote_local_directory.insert(std::pair<std::string,std::string>(remote_direcotry,local_directory)); log_directory_map_tmp.insert(std::pair<LogStruct,std::map<std::string,std::string>>(log_struct_tmp,remote_local_directory)); } } m_log_directory.insert(std::pair<UPLOAD_LOG_TYPE,log_directory_map>(upload_load_type,log_directory_map_tmp)); oxml.OutOfElem(); oxml.OutOfElem(); } } else if (upload_load_type == GS_SERVER_LOG) { std::string gs_id = ""; { char szPath[255]; sprintf(szPath,"../config/gs_config.xml"); CMarkupSTL oxml; if (!oxml.Load(szPath) ){ USER_LOG_ERROR("cannot load "<<szPath); assert(false); return false; } if (!oxml.FindElem("root") ){ USER_LOG_ERROR("can not find root node "<<szPath); assert(false); return false; } if (!oxml.IntoElem()){ USER_LOG_ERROR("can not into root node "<<szPath); assert(false); return false; } if (!oxml.FindElem("gameserver") ){ USER_LOG_ERROR("can not find gameserver node "<<szPath); assert(false); return false; } if (!oxml.IntoElem()){ USER_LOG_ERROR("can not into gameserver node "<<szPath); assert(false); return false; } if (!oxml.FindElem("id") ){ USER_LOG_ERROR("can not find id node "<<szPath); assert(false); return false; } gs_id = oxml.GetAttrib("value"); } { char szPath[255]; sprintf(szPath,"../share_config/share_log_config.xml"); CMarkupSTL oxml; if (!oxml.Load(szPath) ){ USER_LOG_ERROR("cannot load "<<szPath); assert(false); return false; } if (!oxml.FindElem("root") ){ USER_LOG_ERROR("can not find root node "<<szPath); assert(false); return false; } if (!oxml.IntoElem()){ USER_LOG_ERROR("can not into root node "<<szPath); assert(false); return false; } if (!oxml.FindElem("logtype") ){ USER_LOG_ERROR("can not find logtype node "<<szPath); assert(false); return false; } if (!oxml.IntoElem()){ USER_LOG_ERROR("can not into logtype node "<<szPath); assert(false); return false; } log_directory_map log_directory_map_tmp; while (oxml.FindElem("type")) { LogStruct log_struct_tmp; log_struct_tmp.folder_name = oxml.GetAttrib("name"); log_struct_tmp.log_file_head = oxml.GetAttrib("log_file_head"); log_struct_tmp.log_file_trail = oxml.GetAttrib("log_file_trail"); if (!log_struct_tmp.folder_name.empty()) { std::map<std::string,std::string> remote_local_directory; std::string remote_direcotry = "ftp://"; remote_direcotry += CCurlFtpMgr::Instance().GetFtpHost(); remote_direcotry += ":"; remote_direcotry += CCurlFtpMgr::Instance().GetFtpPort(); remote_direcotry += "/"; remote_direcotry += "area_"; remote_direcotry += gs_id.substr(0,1); remote_direcotry += "/"; remote_direcotry += "gs_"; remote_direcotry += gs_id; remote_direcotry += "/"; remote_direcotry += log_struct_tmp.folder_name; remote_direcotry += "/"; std::string local_directory = "..\\"; local_directory += log_struct_tmp.folder_name; local_directory += "\\"; remote_local_directory.insert(std::pair<std::string,std::string>(remote_direcotry,local_directory)); log_directory_map_tmp.insert(std::pair<LogStruct,std::map<std::string,std::string>>(log_struct_tmp,remote_local_directory)); } } m_log_directory.insert(std::pair<UPLOAD_LOG_TYPE,log_directory_map>(upload_load_type,log_directory_map_tmp)); oxml.OutOfElem(); oxml.OutOfElem(); } } return true; }
int CDefaultCtrl::InitProcMon(CMarkupSTL & conf, bool reload /*= false*/) { #ifdef OPEN_PRINT printf("set common config file,path_name=%s\n",ix_->argv_[1]); #endif monsrv_.SetCommFilePath(ix_->argv_[1]);//设置公共配置文件路径 std::vector<TGroupInfo> GroupInfoList; int group_num = atoi( conf.GetAttrib("groupnum").c_str() ); //spp_ctrl.xml int check_group_interval = atoi(conf.GetAttrib("check_group_interval").c_str() ); if(check_group_interval != 0 ) monsrv_.SetCheckGroupInterval(check_group_interval); assert(group_num > 0 && group_num < MAX_PROC_GROUP_NUM ); ix_->group_num_ = group_num; ix_->cur_group_id_ = group_num; TGroupInfo groupinfo; int start_grp = 0,end_grp = 0,cur_grp = 0; while(conf.FindChildElem("group")) // 加载进程组信息 { memset(&groupinfo, 0x0, sizeof(TGroupInfo)); start_grp = atoi(conf.GetChildAttrib("start_group").c_str()); end_grp = atoi(conf.GetChildAttrib("end_group").c_str()); groupinfo.adjust_proc_time= 0; strncpy(groupinfo.basepath_, conf.GetChildAttrib("basepath").c_str(), MAX_FILEPATH_LEN); strncpy(groupinfo.exefile_, conf.GetChildAttrib("exe").c_str(), MAX_FILEPATH_LEN); strncpy(groupinfo.etcfile_, conf.GetChildAttrib("etc").c_str(), MAX_FILEPATH_LEN); strncpy(groupinfo.server_flag_,conf.GetChildAttrib("flag").c_str(),MAX_SERVER_FLAG_LEN); groupinfo.exitsignal_ = atoi(conf.GetChildAttrib("exitsignal").c_str()); if(*conf.GetChildAttrib("maxprocnum").c_str()) { groupinfo.maxprocnum_ = atoi(conf.GetChildAttrib("maxprocnum").c_str()); } else { groupinfo.maxprocnum_ = 100; } if(*conf.GetChildAttrib("minprocnum").c_str()) { groupinfo.minprocnum_ = atoi(conf.GetChildAttrib("minprocnum").c_str()); } else { groupinfo.minprocnum_ = 1; } if(*conf.GetChildAttrib("heartbeat").c_str()) { groupinfo.heartbeat_ = atoi(conf.GetChildAttrib("heartbeat").c_str()); } else { groupinfo.heartbeat_ = 60; } groupinfo.maxwatermark_ = atoi(conf.GetChildAttrib("watermark").c_str()); groupinfo.minsrate_ = atoi(conf.GetChildAttrib("minsrate").c_str()); groupinfo.maxdelay_ = atoi(conf.GetChildAttrib("maxdelay").c_str()); groupinfo.maxmemused_ = atoi(conf.GetChildAttrib("maxmemused").c_str()); assert(groupinfo.minprocnum_ >= 0 && groupinfo.minprocnum_ <= groupinfo.maxprocnum_ && groupinfo.exitsignal_ > 0 && groupinfo.groupid_ >= 0); assert(start_grp == cur_grp); if(end_grp < start_grp ) end_grp = start_grp; if(end_grp >= group_num ) end_grp = group_num -1; assert(start_grp <= end_grp ); for(int idx = start_grp; idx <= end_grp;++idx) { groupinfo.groupid_ = idx; GroupInfoList.push_back(groupinfo); } cur_grp = end_grp + 1; if(cur_grp == group_num ) break; } monsrv_.SetGroupNum(group_num); for(int idx = 0;idx < group_num;++idx ) //添加进程组的信息到procmon { memset(&groupinfo, 0x0, sizeof(TGroupInfo)); groupinfo = GroupInfoList[idx]; if(!reload) { monsrv_.add_group(&groupinfo); } else { monsrv_.mod_group(groupinfo.groupid_, &groupinfo); } } monsrv_.set_notify(notify, this); return 0; }
bool c_server::LoadConfig() { CMarkupSTL config; if (!config.Load(TS_CONFIG)) return false; //¸ù½Úµã config.FindElem(); if (config.FindChildElem("server", true)) { config.IntoElem(); if (config.FindChildElem("ip", true)) m_ip = config.GetChildData(); if (config.FindChildElem("port", true)) c_config::get_instance()->m_port = atoi(config.GetChildData().c_str()); if (config.FindChildElem("threads", true)) m_threads = atoi(config.GetChildData().c_str()); if (config.FindChildElem("leavedb", true)) m_leavedb = config.GetChildData(); if (config.FindChildElem("cache", true)) m_cache_size = atoi(config.GetChildData().c_str()); if (config.FindChildElem("list_max_count", true)) m_list_max_count = atoi(config.GetChildData().c_str()); if (config.FindChildElem("mlist_max_count", true)) m_mlist_max_count = atoi(config.GetChildData().c_str()); if (config.FindChildElem("seq_valid_time", true)) m_seq_valid_time = atoi(config.GetChildData().c_str()); if (config.FindChildElem("write_buffer_size", true)) m_write_buffer_size = atoi(config.GetChildData().c_str()); if (config.FindChildElem("object_effective", true)) m_object_effective = atoi(config.GetChildData().c_str()); if (config.FindChildElem("seq_clear_time", true)) m_seq_clear_time = atoi(config.GetChildData().c_str()); config.OutOfElem(); } return true; }