83 lines
2.0 KiB
C++
83 lines
2.0 KiB
C++
|
|
|
|||
|
|
/******************************************************************************//**
|
|||
|
|
* @file CTsdbSaveRedunSw.cpp
|
|||
|
|
* @brief 时序库存库服务,冗余切换类
|
|||
|
|
* @author yikenan
|
|||
|
|
* @version 1.0
|
|||
|
|
* @date
|
|||
|
|
**********************************************************************************/
|
|||
|
|
|
|||
|
|
#include "CTsdbSaveSrv.h"
|
|||
|
|
#include "CNodeMng.h"
|
|||
|
|
#include "CTsdbSaveRedunSw.h"
|
|||
|
|
#include "SampleThread.h"
|
|||
|
|
|
|||
|
|
namespace iot_dbms
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
CTsdbSaveRedunSw::CTsdbSaveRedunSw( CTsdbSaveSrv *pParent, const iot_public::SRunAppInfo &stRunAppInfo)
|
|||
|
|
: m_pParent( pParent ),
|
|||
|
|
m_stRunAppInfo(stRunAppInfo),
|
|||
|
|
m_ptrSampleThread(NULL)
|
|||
|
|
{
|
|||
|
|
assert(m_pParent);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
CTsdbSaveRedunSw::~CTsdbSaveRedunSw()
|
|||
|
|
{
|
|||
|
|
//< m_objFrontThread析构时会 quit()
|
|||
|
|
m_ptrSampleThread.reset();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int CTsdbSaveRedunSw::redundantSwitch(bool bMaster, bool bSlave)
|
|||
|
|
{
|
|||
|
|
//< 当前逻辑 bSlave 无需使用
|
|||
|
|
|
|||
|
|
if (bMaster)
|
|||
|
|
{
|
|||
|
|
m_objFrontThread.resumeThread();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
m_objFrontThread.suspendThread();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(m_ptrSampleThread != NULL)
|
|||
|
|
{
|
|||
|
|
m_ptrSampleThread->redundantSwitch(bMaster);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_pParent->updateProcInfo(true, m_objFrontThread.isThreadRunning(), bSlave);
|
|||
|
|
|
|||
|
|
return iotSuccess;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int CTsdbSaveRedunSw::initialize()
|
|||
|
|
{
|
|||
|
|
//PUBLIC应用不加载定时存盘功能
|
|||
|
|
if(m_stRunAppInfo.nAppId == CN_AppId_PUBLIC)
|
|||
|
|
{
|
|||
|
|
return iotSuccess;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//初始化历史采样接口
|
|||
|
|
//================================================================================================
|
|||
|
|
m_ptrSampleThread = boost::make_shared<CSampleThread>(m_stRunAppInfo);
|
|||
|
|
if (m_ptrSampleThread == NULL)
|
|||
|
|
{
|
|||
|
|
LOGERROR("CTsdbSaveRedunSw::initialize(), create SampleInstance fail!");
|
|||
|
|
return iotFailed;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(!m_ptrSampleThread->initialize())
|
|||
|
|
{
|
|||
|
|
LOGERROR("CTsdbSaveRedunSw::initialize(), init SampleInstance fail!");
|
|||
|
|
return iotFailed;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return iotSuccess;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} //< namespace iot_dbms
|
|||
|
|
|