/* * ===================================================================================== * * 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 "defs.h" #include "socket.h" #include #include #include // publish/subcribe manager. class PubSubCenter { class SocketBus : public ShmSocket { public: SocketBus(ShmSocket::Shm &shm) : ShmSocket(shm, &kBHTopicBus, 1000) {} using ShmSocket::shm; }; SocketBus socket_; ShmSocket::Shm &shm() { return socket_.shm(); } std::mutex mutex_; typedef std::set Clients; std::unordered_map records_; public: PubSubCenter(ShmSocket::Shm &shm) : socket_(shm) {} PubSubCenter() : PubSubCenter(BHomeShm()) {} ~PubSubCenter() { Stop(); } bool Start(const int nworker = 2); bool Stop() { return socket_.Stop(); } }; #endif // end of include guard: PUBSUB_CENTER_MFSUZJU7