From 9bf199a4770b08c03d553129757d960b605e598a Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期五, 14 五月 2021 18:05:21 +0800
Subject: [PATCH] add center info at fixed address in shm.

---
 src/defs.h |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/defs.h b/src/defs.h
index f0a0d49..5c770a7 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -19,19 +19,28 @@
 #ifndef DEFS_KP8LKGD0
 #define DEFS_KP8LKGD0
 
+#include <atomic>
 #include <string>
 
 typedef uint64_t MQId;
 
-const MQId kBHDefaultSender = 99;
-const MQId kBHTopicCenter = 100;
-const MQId kBHTopicBus = 101;
-inline const MQId BHGlobalSenderAddress() { return kBHDefaultSender; }
-inline const MQId BHTopicCenterAddress() { return kBHTopicCenter; }
-inline const MQId BHTopicBusAddress() { return kBHTopicBus; }
-
 int64_t CalcAllocIndex(int64_t size);
 int64_t GetAllocSize(int index);
+
+struct CenterInfo {
+	struct MQInfo {
+		int64_t id_ = 0;
+		int64_t offset_ = 0;
+	};
+
+	MQInfo mq_center_;
+	MQInfo mq_bus_;
+	MQInfo mq_init_;
+	MQInfo mq_sender_;
+	std::atomic<MQId> mqid_;
+	CenterInfo() :
+	    mqid_(100000) {}
+};
 
 const int kBHCenterPort = 24287;
 const char kTopicSep = '.';
@@ -42,10 +51,17 @@
 
 std::string BHomeShmName();
 bhome_shm::SharedMemory &BHomeShm();
+CenterInfo *GetCenterInfo(bhome_shm::SharedMemory &shm);
+bool CenterInit(bhome_shm::SharedMemory &shm);
 bool GlobalInit(bhome_shm::SharedMemory &shm);
 typedef std::string Topic;
 void SetLastError(const int ec, const std::string &msg);
 void GetLastError(int &ec, std::string &msg);
 //TODO center can check shm for previous crash.
 
+uint64_t BHGlobalSenderAddress();
+uint64_t BHTopicCenterAddress();
+uint64_t BHTopicBusAddress();
+uint64_t BHCenterReplyAddress();
+
 #endif // end of include guard: DEFS_KP8LKGD0

--
Gitblit v1.8.0