lichao
2021-03-29 5657dca25451cfb63a90a3908db0c464fe3f343d
src/pubsub.h
@@ -18,12 +18,31 @@
#ifndef PUBSUB_4KGRA997
#define PUBSUB_4KGRA997
#include "shm.h"
#include "shm_queue.h"
#include <thread>
#include <atomic>
#include <mutex>
#include <vector>
namespace bhome_shm {
bool Subscribe(const std::string &topic);
// publish/subcribe manager.
class BusManager
{
    ShmMsgQueue busq_;
    std::atomic<bool> run_;
    std::vector<std::thread> workers_;
    std::mutex mutex_;
    bool StopNoLock();
public:
    BusManager(SharedMemory &shm);
    ~BusManager();
    bool Start(const int nworker = 2);
    bool Stop();
};
} // namespace bhome_shm
#endif // end of include guard: PUBSUB_4KGRA997