1
This commit is contained in:
parent
d2bb14deae
commit
fc87c6c040
@ -26,6 +26,20 @@ struct GSNode
|
||||
bool servicing = false;
|
||||
int version = 0;
|
||||
f8::TimerWp timer_wp;
|
||||
|
||||
std::string ToJson()
|
||||
{
|
||||
auto node = a8::MutableXObject::CreateObject();
|
||||
node->SetVal("node_id", node_id);
|
||||
node->SetVal("instance_id", instance_id);
|
||||
node->SetVal("room_num", room_num);
|
||||
node->SetVal("online_num", online_num);
|
||||
node->SetVal("ip", ip);
|
||||
node->SetVal("port", port);
|
||||
node->SetVal("servicing", servicing);
|
||||
node->SetVal("version", version);
|
||||
return node->ToJsonStr();
|
||||
}
|
||||
};
|
||||
|
||||
void GSMgr::Init()
|
||||
@ -154,6 +168,7 @@ void GSMgr::___GSReport(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
}
|
||||
node_key_hash_.erase(gs->key);
|
||||
RearrangeNode();
|
||||
f8::Timer::Instance()->DeleteCurrentTimer();
|
||||
}
|
||||
});
|
||||
node_key_hash_[key] = gs;
|
||||
@ -307,6 +322,9 @@ void GSMgr::RearrangeNode()
|
||||
|
||||
void GSMgr::AddNodeToSortedNodes(std::shared_ptr<GSNode> node)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("AddNodeToSortedNodes %s\n" , {node->ToJson()});
|
||||
#endif
|
||||
auto itr = sorted_node_hash_.find(node->version);
|
||||
if (itr != sorted_node_hash_.end()) {
|
||||
itr->second.push_back(node);
|
||||
@ -317,11 +335,17 @@ void GSMgr::AddNodeToSortedNodes(std::shared_ptr<GSNode> node)
|
||||
|
||||
void GSMgr::RemoveNodeFromSortedNodes(std::shared_ptr<GSNode> node)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("RemoveNodeFromSortedNodes %s\n" , {node->ToJson()});
|
||||
#endif
|
||||
for (auto& pair : sorted_node_hash_) {
|
||||
std::vector<std::shared_ptr<GSNode>>& node_list = pair.second;
|
||||
for (size_t i = 0; i < node_list.size(); ++i) {
|
||||
if (node_list[i] == node) {
|
||||
node_list.erase(node_list.begin() + i);
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("RemoveNodeFromSortedNodes ok %s\n" , {node->ToJson()});
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user