liuxiaolong
2021-07-20 58d904a328c0d849769b483e901a0be9426b8209
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
/*
 * =====================================================================================
 *
 *       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 "shm_socket.h"
#include <functional>
#include <map>
#include <memory>
class CenterTopicNode;
class TcpServer;
class TcpProxy;
class IoService;
 
class BHCenter
{
    typedef ShmSocket Socket;
 
public:
    typedef Socket::PartialRecvCB MsgHandler;
    typedef Socket::RawRecvCB RawHandler;
    typedef Socket::IdleCB IdleHandler;
    static bool Install(const std::string &name, MsgHandler handler, RawHandler raw_handler, IdleHandler idle, const MQInfo &mq, const int mq_len);
 
    BHCenter(Socket::Shm &shm);
    ~BHCenter();
    bool Start();
    bool Stop();
 
private:
    struct CenterInfo {
        std::string name_;
        MsgHandler handler_;
        RawHandler raw_handler_;
        IdleHandler idle_;
        MQInfo mq_;
        int mq_len_ = 0;
    };
    typedef std::map<std::string, CenterInfo> CenterRecords;
    static CenterRecords &Centers();
 
    std::map<std::string, std::shared_ptr<ShmSocket>> sockets_;
    std::unique_ptr<CenterTopicNode> topic_node_;
 
    std::unique_ptr<IoService> io_service_;
    std::unique_ptr<TcpServer> tcp_server_;
    std::unique_ptr<TcpProxy> tcp_proxy_;
};
 
#endif // end of include guard: CENTER_TM9OUQTG