From 993c556000a414011626770540678948f16eaa9e Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期三, 02 六月 2021 17:40:50 +0800
Subject: [PATCH] center restart with new shm; set center node ssn.

---
 box/center_topic_node.cpp |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/box/center_topic_node.cpp b/box/center_topic_node.cpp
index 82b38ca..8228992 100644
--- a/box/center_topic_node.cpp
+++ b/box/center_topic_node.cpp
@@ -29,7 +29,7 @@
 
 namespace
 {
-const std::string &kTopicQueryProc = "@center_query_procs";
+const std::string &kTopicQueryProc = "#center_query_procs";
 
 std::string ToJson(const MsgQueryProcReply &qpr)
 {
@@ -56,7 +56,7 @@
 } // namespace
 
 CenterTopicNode::CenterTopicNode(CenterPtr center, SharedMemory &shm) :
-    pscenter_(center), pnode_(new TopicNode(shm)), run_(false) {}
+    pscenter_(center), pnode_(new TopicNode(shm, 200)), run_(false) {}
 
 CenterTopicNode::~CenterTopicNode() { Stop(); }
 
@@ -77,26 +77,36 @@
 	MsgCommonReply reply;
 
 	ProcInfo info;
-	info.set_proc_id("#center.node");
+	info.set_proc_id("@center.node");
 	info.set_name("center node");
-	if (!pnode_->Register(info, reply, timeout)) {
+	Json jinfo;
+	jinfo.put("description", "some center services. Other nodes may use topics to use them.");
+	info.set_public_info(jinfo.dump());
+	if (!pnode_->DoRegister(true, info, reply, timeout)) {
 		throw std::runtime_error("center node register failed.");
 	}
 
 	MsgTopicList topics;
 	topics.add_topic_list(kTopicQueryProc);
-	if (!pnode_->ServerRegisterRPC(topics, reply, timeout)) {
+	if (!pnode_->DoServerRegisterRPC(true, topics, reply, timeout)) {
 		throw std::runtime_error("center node register topics failed.");
 	}
 
 	auto onRequest = [this](void *src_info, std::string &client_proc_id, MsgRequestTopic &request) {
 		auto reply = MakeReply<MsgRequestTopicReply>(eSuccess);
 		if (request.topic() == kTopicQueryProc) {
-			auto data = (*pscenter_)->QueryProc(request.data());
+			std::string id;
+			if (!request.data().empty()) {
+				Json json;
+				if (json.parse(request.data())) {
+					id = json.get("proc_id", "");
+				}
+			}
+			auto data = (*pscenter_)->QueryProc(id);
 			*reply.mutable_errmsg() = data.errmsg();
 			reply.set_data(ToJson(data));
 		} else {
-			SetError(*reply.mutable_errmsg(), eInvalidInput, "not supported topic" + request.topic());
+			SetError(*reply.mutable_errmsg(), eInvalidInput, "invalid topic: " + request.topic());
 		}
 		pnode_->ServerSendReply(src_info, reply);
 	};

--
Gitblit v1.8.0