From 101b5cf85397ef9350aaedd12cfcf9fd3d07a565 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期四, 20 五月 2021 12:41:51 +0800
Subject: [PATCH] refactor node center.
---
src/defs.h | 43 ++++++++++++++++++++++++++++++++++++++-----
1 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/src/defs.h b/src/defs.h
index 10ac73c..51040e6 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -19,12 +19,30 @@
#ifndef DEFS_KP8LKGD0
#define DEFS_KP8LKGD0
-#include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
+#include "robust.h"
+#include <atomic>
+#include <string>
-typedef boost::uuids::uuid MQId;
+typedef uint64_t MQId;
-const MQId kBHBusQueueId = boost::uuids::string_generator()("01234567-89ab-cdef-8349-1234567890ff");
+int64_t CalcAllocIndex(int64_t size);
+int64_t GetAllocSize(int index);
+
+struct MQInfo {
+ MQId id_ = 0;
+ int64_t offset_ = 0;
+};
+
+struct CenterInfo {
+ MQInfo mq_center_;
+ MQInfo mq_bus_;
+ MQInfo mq_sender_;
+ robust::AtomicReqRep init_rr_;
+ std::atomic<MQId> mqid_;
+ CenterInfo() :
+ mqid_(100000) {}
+};
+
const int kBHCenterPort = 24287;
const char kTopicSep = '.';
namespace bhome_shm
@@ -32,8 +50,23 @@
class SharedMemory;
} // namespace bhome_shm
+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.
+const MQInfo &BHGlobalSenderAddress();
+const MQInfo &BHTopicCenterAddress();
+const MQInfo &BHTopicBusAddress();
+bool BHNodeInit(const int64_t request, int64_t &reply);
+void BHCenterHandleInit(std::function<int64_t(const int64_t)> const &onReq);
+
+// node mq is avail with in timeout; after that may get killed.
+int NodeTimeoutSec();
+
#endif // end of include guard: DEFS_KP8LKGD0
--
Gitblit v1.8.0