/* * ===================================================================================== * * Filename: socket.h * * Description: * * Version: 1.0 * Created: 2021年03月30日 15时49分19秒 * Revision: none * Compiler: gcc * * Author: Li Chao (), * Organization: * * ===================================================================================== */ #ifndef SOCKET_GWTJHBPO #define SOCKET_GWTJHBPO #include "shm_queue.h" #include #include #include #include #include #include #include class ShmSocket : private boost::noncopyable { typedef bhome_shm::ShmMsgQueue Queue; public: enum Type { eSockRequest, eSockReply, eSockSubscribe, eSockPublish, eSockBus, }; typedef std::function RecvCB; typedef std::function RecvRawCB; ShmSocket(Type type, bhome_shm::SharedMemory &shm); ShmSocket(Type type); ~ShmSocket(); // bool Request(const std::string &topic, const void *data, const size_t size, onReply); bool RequestAndWait() { return false; } // call Request, and wait onReply notify cv // bool HandleRequest(onData); bool ReadRequest(); // exclude with HandleRequest bool SendReply(); // exclude with HandleRequest bool Publish(const std::string &topic, const void *data, const size_t size, const int timeout_ms); bool Subscribe(const std::vector &topics, const int timeout_ms); bool RecvSub(std::string &topic, std::string &data, const int timeout_ms); // start recv. bool Start(const RecvCB &onData, int nworker = 1); bool StartRaw(const RecvRawCB &onData, int nworker = 1); bool Stop(); private: bool StopNoLock(); bhome_shm::SharedMemory &shm_; const Type type_; std::vector workers_; std::mutex mutex_; std::atomic run_; std::unique_ptr mq_; }; #endif // end of include guard: SOCKET_GWTJHBPO