route.cpp
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <set>
#include <lib_log.h>
#include "route.h"
route_t g_rotue_t;
namespace {
const char* ROUTE_XML_PATH = "./route.xml";
int parser_ser(xmlNodePtr cur, el::lib_xmlparser_t& xml, service_mgr_t* service_mgr){
cur = cur->xmlChildrenNode;
while(NULL != cur){
if(!xmlStrcmp(cur->name, (const xmlChar*)"date")){
service_t service;
xml.get_xml_prop(cur, service.ip, "ip");
xml.get_xml_prop(cur, service.port, "port");
service_mgr->service_vec.push_back(service);
}
cur = cur->next;
}
return 0;
}
}
int route_t::parser()
{
int ret = this->xml.open(ROUTE_XML_PATH);
if (0 != ret){
return ret;
}
this->xml.move2children_node();
while(NULL != this->xml.node_ptr){
//ȡڵе
if (!xmlStrcmp(this->xml.node_ptr->name, (const xmlChar*)"ser")){
service_mgr_t service_mgr;
xmlNodePtr cur = this->xml.node_ptr;
std::string str_start;
std::string str_end;
xml.get_xml_prop(cur, str_start, "start");
service_mgr.start = ::strtoul(str_start.c_str(), 0, 16);
xml.get_xml_prop(cur, str_end, "end");
service_mgr.end = ::strtoul(str_end.c_str(), 0, 16);
if (service_mgr.start > service_mgr.end){
assert(0);
return -1;
}
parser_ser(cur, this->xml, &service_mgr);
g_rotue_t.service_mgr_vec.push_back(service_mgr);
}
this->xml.move2next_node();
}
return 0;
}