2025-03-12 14:17:01 +08:00

97 lines
2.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "ChgWorkThread.h"
#include "pub_logger_api/logger.h"
#include "common/Common.h"
#include "boost/make_shared.hpp"
using namespace iot_service;
CChgWorkThreadPtr g_ptrChgWorkThread = NULL;
/* @brief 获取FBD订阅接口单例 */
CChgWorkThreadPtr iot_service::getChgWorkThreadSingleTon(const iot_public::SRunAppInfo &stRunAppInfo)
{
if (g_ptrChgWorkThread == NULL)
{
g_ptrChgWorkThread = boost::make_shared<ChgWorkThread>(stRunAppInfo);
if (g_ptrChgWorkThread != NULL)
{
if (true != g_ptrChgWorkThread->initialize())
{
/* @brief 注册失败后清理资源 */
g_ptrChgWorkThread.reset();
}
}
}
return g_ptrChgWorkThread;
}
/* @brief 销毁单例,注意:由于使用了智能指针,一定要保证外部的引用全部释放掉,这样才能保证真正释放 */
void iot_service::releaseChgWorkThreadSingleTon()
{
g_ptrChgWorkThread.reset();
{
LOGERROR("单例释放失败,可能由于外部还有对象使用了此智能指针没有释放");
}
}
bool iot_service::ChgWorkThread::initialize()
{
//初始化变化数据发送接口库
//================================================================================================
m_ptrChgDataApi = boost::make_shared<CDpcdaForDp>(m_stRunAppInfo.nDomainId,m_stRunAppInfo.nAppId,
m_stRunAppInfo.strAppName.c_str());
if (m_ptrChgDataApi == NULL)
{
LOGERROR("COperateServerClass ::init(), make_shared<CDpcdaForDp> fail!\n");
return false;
}
if (m_ptrChgDataApi->suspendThread() == false) //初始化挂起
{
LOGERROR("COperateServerClass ::init(), resumeThread <CDpcdaForDp> fail!\n");
return false;
}
return true;
}
ChgWorkThread::ChgWorkThread(iot_public::SRunAppInfo stRunAppInfo):
m_stRunAppInfo(stRunAppInfo),
m_ptrChgDataApi(NULL)
{
}
iot_service::ChgWorkThread::~ChgWorkThread()
{
//释放变化数据接口
if (m_ptrChgDataApi)
{
m_ptrChgDataApi->suspendThread();
m_ptrChgDataApi.reset();
m_ptrChgDataApi = NULL;
LOGINFO("CSrvDataPublish::release()success \n");
}
}
bool iot_service::ChgWorkThread::resumeThread()
{
return m_ptrChgDataApi->resumeThread();
}
bool iot_service::ChgWorkThread::suspendThread()
{
return m_ptrChgDataApi->suspendThread();
}
bool iot_service::ChgWorkThread::addChgData(iot_idl::SRealTimeDataPkg &objChgData)
{
return m_ptrChgDataApi->addChgData(objChgData) ;
}