rafactor, remove old todo, add some err msg.
| | |
| | | namespace |
| | | { |
| | | |
| | | //TODO check proc_id |
| | | |
| | | template <class Body, class OnMsg, class Replyer> |
| | | inline void Dispatch(MsgI &msg, BHMsgHead &head, OnMsg const &onmsg, Replyer const &replyer) |
| | | { |
| | |
| | | GlobalInit(shm); |
| | | |
| | | if (args.Has("daemon") || args.Has("d")) { |
| | | int r = daemon(0, 0); // TODO center control msg to close itself. |
| | | int r = daemon(0, 0); // maybe add center control msg to close itself. |
| | | } |
| | | |
| | | BHCenter center(shm); |
| | |
| | | return op(node); |
| | | } |
| | | } |
| | | } catch (...) { |
| | | //TODO error log |
| | | } catch (std::exception &e) { |
| | | LOG_ERROR() << "handle msg exception: " << e.what(); |
| | | return MakeReply<Reply>(eError, "internal error."); |
| | | } |
| | | } |
| | |
| | | typedef std::string Topic; |
| | | void SetLastError(const int ec, const std::string &msg); |
| | | void GetLastError(int &ec, std::string &msg); |
| | | //TODO center can check shm for previous crash. |
| | | |
| | | const MQInfo &BHTopicCenterAddress(SharedMemory &shm); |
| | | const MQInfo &BHTopicBusAddress(SharedMemory &shm); |
| | |
| | | default: break; |
| | | } |
| | | if (!IsOk()) { |
| | | throw("Error: shm can not create/open \"" + name_ + "\""); |
| | | throw std::runtime_error("Error: shm can not create/open \"" + name_ + "\""); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | } |
| | | ShmMsgQueue::ShmMsgQueue(const int64_t abs_addr, ShmType &segment, const MQId id) : |
| | | id_(id), queue_(abs_addr, segment, MsgQIdToName(id_)) |
| | | { |
| | | //TODO check some tag. |
| | | } |
| | | id_(id), queue_(abs_addr, segment, MsgQIdToName(id_)) {} |
| | | |
| | | ShmMsgQueue::~ShmMsgQueue() {} |
| | | |
| | |
| | | bool ShmMsgQueue::TrySend(SharedMemory &shm, const MQInfo &remote, const RawData val) |
| | | { |
| | | try { |
| | | //TODO find from center, or use offset. |
| | | ShmMsgQueue dest(remote.offset_, shm, remote.id_); |
| | | return dest.queue().TryWrite(val); |
| | | } catch (...) { |
| | |
| | | reply_head.mutable_proc_id()->swap(out_proc_id); |
| | | return true; |
| | | } |
| | | } catch (...) { |
| | | } catch (std::exception &e) { |
| | | LOG_ERROR() << __func__ << " exception: " << e.what(); |
| | | SetLastError(eError, __func__ + std::string(" internal errer.")); |
| | | } |
| | | return false; |
| | |
| | | reply.ParseBody(reply_body) && |
| | | IsSuccess(reply_body.errmsg().errcode()); |
| | | } |
| | | // TODO wait for result? |
| | | } catch (...) { |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | } |
| | | //TODO error msg. |
| | | if (head.type() == kMsgTypePublish) { |
| | | if (pub.ParseFromString(body)) { |
| | | head.mutable_proc_id()->swap(proc_id); |
| | | return true; |
| | | } |
| | | } |
| | | SetLastError(eError, "invalid subcribe msg received."); |
| | | return false; |
| | | } |