| | |
| | | bool StartWorker(const RequestResultCB &rrcb, int nworker = 2); |
| | | bool StartWorker(int nworker = 2) { return StartWorker(RequestResultCB(), nworker); } |
| | | bool Stop() { return Socket::Stop(); } |
| | | bool AsyncRequest(const std::string &topic, const void *data, const size_t size, const int timeout_ms, const RequestResultCB &rrcb); |
| | | bool AsyncRequest(const std::string &topic, const std::string &data, const int timeout_ms, const RequestResultCB &rrcb) |
| | | bool AsyncRequest(const Topic &topic, const void *data, const size_t size, const int timeout_ms, const RequestResultCB &rrcb); |
| | | bool AsyncRequest(const Topic &topic, const std::string &data, const int timeout_ms, const RequestResultCB &rrcb) |
| | | { |
| | | return AsyncRequest(topic, data.data(), data.size(), timeout_ms, rrcb); |
| | | } |
| | | bool SyncRequest(const std::string &topic, const void *data, const size_t size, std::string &out, const int timeout_ms); |
| | | bool SyncRequest(const std::string &topic, const std::string &data, std::string &out, const int timeout_ms) |
| | | bool SyncRequest(const Topic &topic, const void *data, const size_t size, std::string &out, const int timeout_ms); |
| | | bool SyncRequest(const Topic &topic, const std::string &data, std::string &out, const int timeout_ms) |
| | | { |
| | | return SyncRequest(topic, data.data(), data.size(), out, timeout_ms); |
| | | } |
| | |
| | | private: |
| | | bool AsyncSend(const void *remote, const void *msg, const int timeout_ms, const RecvCB &cb); |
| | | bool SyncSendAndRecv(const void *remote, const void *msg, void *result, const int timeout_ms); |
| | | bool QueryRPCTopic(const std::string &topic, bhome::msg::BHAddress &addr, const int timeout_ms); |
| | | bool QueryRPCTopic(const Topic &topic, bhome::msg::BHAddress &addr, const int timeout_ms); |
| | | std::unordered_map<std::string, RecvCB> async_cbs_; |
| | | |
| | | typedef bhome_msg::BHAddress Address; |
| | |
| | | { |
| | | class Impl |
| | | { |
| | | typedef std::unordered_map<std::string, Address> Store; |
| | | typedef std::unordered_map<Topic, Address> Store; |
| | | Store store_; |
| | | |
| | | public: |
| | | bool Find(const std::string &topic, Address &addr) |
| | | bool Find(const Topic &topic, Address &addr) |
| | | { |
| | | auto pos = store_.find(topic); |
| | | if (pos != store_.end()) { |
| | |
| | | return false; |
| | | } |
| | | } |
| | | bool Update(const std::string &topic, const Address &addr) |
| | | bool Update(const Topic &topic, const Address &addr) |
| | | { |
| | | store_[topic] = addr; |
| | | return true; |
| | |
| | | // } |
| | | |
| | | public: |
| | | bool Find(const std::string &topic, Address &addr) { return impl_->Find(topic, addr); } |
| | | bool Update(const std::string &topic, const Address &addr) { return impl_->Update(topic, addr); } |
| | | bool Find(const Topic &topic, Address &addr) { return impl_->Find(topic, addr); } |
| | | bool Update(const Topic &topic, const Address &addr) { return impl_->Update(topic, addr); } |
| | | }; |
| | | TopicCache topic_cache_; |
| | | }; |