lichao
2021-04-02 83085f2ce99cca05d40a19482151873a55e6393a
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
/*
 * =====================================================================================
 *
 *       Filename:  pubsub_center.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年04月01日 09时29分39秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef PUBSUB_CENTER_MFSUZJU7
#define PUBSUB_CENTER_MFSUZJU7
 
#include "center.h"
#include "defs.h"
#include "socket.h"
#include <mutex>
#include <set>
#include <unordered_map>
 
BHCenter::MsgHandler MakeBusCenter();
 
// publish/subcribe manager.
class PubSubCenter
{
    ShmSocket socket_;
 
public:
    PubSubCenter(ShmSocket::Shm &shm) :
        socket_(shm, &kBHTopicBus, 1000) {}
    PubSubCenter() :
        PubSubCenter(BHomeShm()) {}
    ~PubSubCenter() { Stop(); }
    bool Start(const int nworker = 2);
    bool Stop() { return socket_.Stop(); }
};
 
#endif // end of include guard: PUBSUB_CENTER_MFSUZJU7