/*
|
* =====================================================================================
|
*
|
* 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"
|
#include "msg.h"
|
#include "shm_msg_queue.h"
|
|
namespace
|
{
|
|
struct LastError {
|
int ec_ = 0;
|
std::string msg_;
|
};
|
|
LastError &LastErrorStore()
|
{
|
thread_local LastError le;
|
return le;
|
}
|
|
} // namespace
|
|
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_;
|
}
|