lichao
2021-05-21 1ff714838c03cba1a18884d5b48a20ee6c4275ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * =====================================================================================
 *
 *       Filename:  defs.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年03月26日 19时26分17秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), 
 *   Organization:  
 *
 * =====================================================================================
 */
 
#ifndef DEFS_KP8LKGD0
#define DEFS_KP8LKGD0
 
#include "robust.h"
#include <atomic>
#include <string>
 
class ShmSocket;
typedef uint64_t MQId;
 
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
{
class SharedMemory;
} // namespace bhome_shm
 
using bhome_shm::SharedMemory;
 
std::string BHomeShmName();
SharedMemory &BHomeShm();
CenterInfo *GetCenterInfo(SharedMemory &shm);
ShmSocket &DefaultSender(SharedMemory &shm);
 
MQId NewSession();
bool CenterInit(SharedMemory &shm);
bool GlobalInit(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 &BHTopicCenterAddress(SharedMemory &shm);
const MQInfo &BHTopicBusAddress(SharedMemory &shm);
bool BHNodeInit(SharedMemory &shm, const int64_t request, int64_t &reply);
void BHCenterHandleInit(SharedMemory &shm, 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