| | |
| | | } |
| | | |
| | | BHCenter::BHCenter(Socket::Shm &shm) : |
| | | socket_(shm, &kBHUniCenter, 1000) {} |
| | | socket_(shm, &BHUniCenter(), 1000) {} |
| | | |
| | | BHCenter::BHCenter() : |
| | | BHCenter(BHomeShm()) {} |
New file |
| | |
| | | /* |
| | | * ===================================================================================== |
| | | * |
| | | * Filename: defs.cpp |
| | | * |
| | | * Description: |
| | | * |
| | | * Version: 1.0 |
| | | * Created: 2021年04月06日 19时23分14秒 |
| | | * Revision: none |
| | | * Compiler: gcc |
| | | * |
| | | * Author: Li Chao (), |
| | | * Organization: |
| | | * |
| | | * ===================================================================================== |
| | | */ |
| | | #include "defs.h" |
| | | namespace |
| | | { |
| | | |
| | | const MQId kBHTopicBus = boost::uuids::string_generator()("01234567-89ab-cdef-8349-1234567890ff"); |
| | | const MQId kBHTopicReqRepCenter = boost::uuids::string_generator()("12345670-89ab-cdef-8349-1234567890ff"); |
| | | const MQId kBHUniCenter = boost::uuids::string_generator()("87654321-89ab-cdef-8349-1234567890ff"); |
| | | |
| | | } // namespace |
| | | |
| | | const MQId &BHTopicBus() { return kBHTopicBus; } |
| | | const MQId &BHTopicReqRepCenter() { return kBHTopicReqRepCenter; } |
| | | const MQId &BHUniCenter() { return kBHUniCenter; } |
| | |
| | | |
| | | typedef boost::uuids::uuid MQId; |
| | | |
| | | const MQId kBHTopicBus = boost::uuids::string_generator()("01234567-89ab-cdef-8349-1234567890ff"); |
| | | const MQId kBHTopicReqRepCenter = boost::uuids::string_generator()("12345670-89ab-cdef-8349-1234567890ff"); |
| | | const MQId kBHUniCenter = boost::uuids::string_generator()("87654321-89ab-cdef-8349-1234567890ff"); |
| | | const MQId &BHTopicBus(); |
| | | const MQId &BHTopicReqRepCenter(); |
| | | const MQId &BHUniCenter(); |
| | | |
| | | const int kBHCenterPort = 24287; |
| | | const char kTopicSep = '.'; |
| | |
| | | return false; |
| | | } |
| | | DEFER1(imsg.Release(shm())); |
| | | return ShmMsgQueue::Send(shm(), kBHTopicBus, imsg, timeout_ms); |
| | | return ShmMsgQueue::Send(shm(), BHTopicBus(), imsg, timeout_ms); |
| | | } catch (...) { |
| | | return false; |
| | | } |
| | |
| | | bool SocketSubscribe::Subscribe(const std::vector<Topic> &topics, const int timeout_ms) |
| | | { |
| | | try { |
| | | return mq().Send(kBHTopicBus, MakeSub(mq().Id(), topics), timeout_ms); |
| | | return mq().Send(BHTopicBus(), MakeSub(mq().Id(), topics), timeout_ms); |
| | | } catch (...) { |
| | | return false; |
| | | } |
| | |
| | | |
| | | public: |
| | | PubSubCenter(ShmSocket::Shm &shm) : |
| | | socket_(shm, &kBHTopicBus, 1000) {} |
| | | socket_(shm, &BHTopicBus(), 1000) {} |
| | | PubSubCenter() : |
| | | PubSubCenter(BHomeShm()) {} |
| | | ~PubSubCenter() { Stop(); } |
| | |
| | | |
| | | public: |
| | | ReqRepCenter(ShmSocket::Shm &shm) : |
| | | socket_(shm, &kBHTopicReqRepCenter, 1000) {} |
| | | socket_(shm, &BHTopicReqRepCenter(), 1000) {} |
| | | ReqRepCenter() : |
| | | ReqRepCenter(BHomeShm()) {} |
| | | ~ReqRepCenter() { Stop(); } |
| | |
| | | bool SocketReply::Register(const ProcInfo &proc_info, const std::vector<std::string> &topics, const int timeout_ms) |
| | | { |
| | | //TODO check reply? |
| | | return SyncSend(&kBHTopicReqRepCenter, MakeRegister(mq().Id(), proc_info, topics), timeout_ms); |
| | | return SyncSend(&BHTopicReqRepCenter(), MakeRegister(mq().Id(), proc_info, topics), timeout_ms); |
| | | } |
| | | bool SocketReply::Heartbeat(const ProcInfo &proc_info, const int timeout_ms) |
| | | { |
| | | return SyncSend(&kBHTopicReqRepCenter, MakeHeartbeat(mq().Id(), proc_info), timeout_ms); |
| | | return SyncSend(&BHTopicReqRepCenter(), MakeHeartbeat(mq().Id(), proc_info), timeout_ms); |
| | | } |
| | | bool SocketReply::StartWorker(const OnRequest &rcb, int nworker) |
| | | { |
| | |
| | | |
| | | BHMsg result; |
| | | const BHMsg &msg = MakeQueryTopic(mq().Id(), topic); |
| | | if (SyncSendAndRecv(&kBHTopicReqRepCenter, &msg, &result, timeout_ms)) { |
| | | if (SyncSendAndRecv(&BHTopicReqRepCenter(), &msg, &result, timeout_ms)) { |
| | | if (result.type() == kMsgTypeQueryTopicReply) { |
| | | MsgQueryTopicReply reply; |
| | | if (reply.ParseFromString(result.body())) { |