lichao
2021-05-14 9bf199a4770b08c03d553129757d960b605e598a
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