lichao
2021-03-31 2e99e5311d1b9a53cca17008452cbe49e2af7234
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
/*
 * =====================================================================================
 *
 *       Filename:  pubsub.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年03月24日 18时44分36秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef PUBSUB_4KGRA997
#define PUBSUB_4KGRA997
 
#include "socket.h"
#include <mutex>
#include <set>
#include <unordered_map>
 
namespace bhome_shm
{
 
// publish/subcribe manager.
class BusManager
{
    SharedMemory &shm_;
    ShmSocket socket_;
    std::mutex mutex_;
    typedef std::set<MQId> Clients;
    std::unordered_map<std::string, Clients> records_;
 
public:
    BusManager(SharedMemory &shm);
    BusManager();
    ~BusManager() { Stop(); }
    bool Start(const int nworker = 2);
    bool Stop() { return socket_.Stop(); }
};
 
} // namespace bhome_shm
 
#endif // end of include guard: PUBSUB_4KGRA997