From 77a6c3512a44dfe6540dde71946e6484fe4f173f Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期一, 10 五月 2021 16:05:28 +0800 Subject: [PATCH] test lock code. --- src/defs.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/defs.cpp b/src/defs.cpp index 4051196..6d688b2 100644 --- a/src/defs.cpp +++ b/src/defs.cpp @@ -16,15 +16,51 @@ * ===================================================================================== */ #include "defs.h" +#include "msg.h" +#include "shm_msg_queue.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"); +struct LastError { + int ec_ = 0; + std::string msg_; +}; + +LastError &LastErrorStore() +{ + thread_local LastError le; + return le; +} } // namespace -const MQId &BHTopicBus() { return kBHTopicBus; } -const MQId &BHTopicReqRepCenter() { return kBHTopicReqRepCenter; } -const MQId &BHUniCenter() { return kBHUniCenter; } +std::string BHomeShmName() +{ + return "bhome_default_shm_v0"; +} +bhome_shm::SharedMemory &BHomeShm() +{ + static bhome_shm::SharedMemory shm(BHomeShmName(), 1024 * 1024 * 512); + return shm; +} + +bool GlobalInit(bhome_shm::SharedMemory &shm) +{ + MsgI::BindShm(shm); + typedef std::atomic<MQId> IdSrc; + IdSrc *psrc = shm.FindOrCreate<IdSrc>("shmqIdSrc0", 100000); + return psrc && ShmMsgQueue::SetData(*psrc); +} + +void SetLastError(const int ec, const std::string &msg) +{ + LastErrorStore().ec_ = ec; + LastErrorStore().msg_ = msg; +} + +void GetLastError(int &ec, std::string &msg) +{ + ec = LastErrorStore().ec_; + msg = LastErrorStore().msg_; +} \ No newline at end of file -- Gitblit v1.8.0