lichao
2021-04-09 4e5cb7960ce4e7e66d5190be67426aeca8b55c3d
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
/*
 * =====================================================================================
 *
 *       Filename:  center.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年03月30日 16时22分24秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef CENTER_TM9OUQTG
#define CENTER_TM9OUQTG
 
#include "socket.h"
#include <functional>
#include <map>
#include <memory>
 
class BHCenter
{
    typedef ShmSocket Socket;
 
public:
    typedef Socket::PartialRecvCB MsgHandler;
    typedef Socket::IdleCB IdleHandler;
    static bool Install(const std::string &name, MsgHandler handler, IdleHandler idle, const std::string &mqid, const int mq_len);
    static bool Install(const std::string &name, MsgHandler handler, IdleHandler idle, const MQId &mqid, const int mq_len);
 
    BHCenter(Socket::Shm &shm);
    BHCenter();
    ~BHCenter() { Stop(); }
    bool Start();
    bool Stop();
 
private:
    struct CenterInfo {
        std::string name_;
        MsgHandler handler_;
        IdleHandler idle_;
        std::string mqid_;
        int mq_len_ = 0;
    };
    typedef std::map<std::string, CenterInfo> CenterRecords;
    static CenterRecords &Centers();
 
    std::map<std::string, std::shared_ptr<ShmSocket>> sockets_;
};
 
#endif // end of include guard: CENTER_TM9OUQTG