lichao
2021-04-06 3e9f5b869dd32441fdd3d77091cb33ef4301f244
src/center.h
@@ -20,6 +20,8 @@
#include "socket.h"
#include <functional>
#include <map>
#include <memory>
class BHCenter
{
@@ -27,15 +29,25 @@
public:
   typedef std::function<bool(ShmSocket &socket, bhome_msg::MsgI &imsg, bhome::msg::BHMsg &msg)> MsgHandler;
   static bool Install(const std::string &name, MsgHandler handler, const std::string &mqid, const int mq_len);
   BHCenter(Socket::Shm &shm);
   BHCenter();
   ~BHCenter() { Stop(); }
   bool Start();
   bool Stop() { return socket_.Stop(); }
   bool Stop();
private:
   ShmSocket socket_;
   struct CenterInfo {
      std::string name_;
      MsgHandler handler_;
      std::string mqid_;
      int mq_len_ = 0;
   };
   typedef std::map<std::string, CenterInfo> CenterRecords;
   static CenterRecords &Centers();
   std::map<std::string, std::shared_ptr<ShmSocket>> sockets_;
};
#endif // end of include guard: CENTER_TM9OUQTG