123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #include "StraStreamPipe.h"
- #include "Strategy.h"
- #include "DBMgr.h"
- NAMESPACE_MAS_BEGIN
- StraStreamPipe::StraStreamPipe(TZ_INT sceneId,
- const std::string & sceneName,
- TZ_INT straId, const std::string & straParams,
- const ExcepInfo & einfo) :
- IStreamPipe(sceneId, straId, EMPT_STRA, einfo),
- m_sceneName(sceneName), m_straParams(straParams)
- {
- }
- StraStreamPipe::~StraStreamPipe()
- {
- this->Dispose();
- }
- TZ_INT StraStreamPipe::Initialize(SPtr<StrategyLib> & straLib)
- {
- m_straLib = straLib;
- straLib->GetStraLibKey(m_straKey);
- m_strategy = straLib->BuildStrategy();
- if (!m_strategy)
- {
- TZLogWarn("build strategy %s nullptr!!!", m_straKey.c_str());
- return MEC_NULL_OBJ;
- }
- auto irst = m_strategy->Initialize();
- if (irst)
- {
- TZLogWarn("stra %s init failed!!!", m_straKey.c_str());
- return irst;
- }
- m_strategy->SetStrategyCfg(m_straParams);
- TZLogInfo("stra %s init succeed~~~", m_straKey.c_str());
- return MEC_OK;
- }
- TZ_INT StraStreamPipe::Dispose()
- {
- m_straLib->DestroyStrategy(m_strategy);
- m_strategy = nullptr;
- return MEC_OK;
- }
- std::tuple<TZ_BOOL, TZ_BOOL> StraStreamPipe::streamArrived(
- SPtr<StreamInfo> & streamInfo)
- {
- TZ_BOOL isEvent = FALSE;
- // 由策略内部 SetStraRst
- m_strategy->DoStrategy(streamInfo);
- SPtr<StraProducing> rst = streamInfo->GetStraProducing();
- if (rst->Result.RstType)
- {
- this->addRecord(rst);
- }
- return std::make_tuple(TRUE, FALSE);
- }
- TZ_INT StraStreamPipe::SetStrategyCfg(const std::string & param)
- {
- return m_strategy->SetStrategyCfg(param);
- }
- void StraStreamPipe::addRecord(SPtr<StraProducing> & producing)
- {
- producing->Result.SceneName = m_sceneName;
- producing->Result.SceneId = this->GetSrcId();
- TblEventRecordItem event;
- event.Tb_Id = INVALID_PRIMARY_KEY;
- event.Tb_Type = (producing->Result.RstType == 1 ? "事件" : "报警");
- event.Tb_Name = producing->Result.RstName;
- event.Tb_Externs = producing->Result.Externs;
- event.Tb_StrategyName = m_straKey;
- event.Tb_SceneId = this->GetSrcId();
- event.Tb_SceneName = m_sceneName;
- event.Tb_BeginTime = producing->Result.BeginTime;
- event.Tb_EndTime = event.Tb_BeginTime;
- event.Tb_Description = producing->Result.Externs;
- auto irst = DBMGR->AddOrUpdateTblEventRecord(event);
- TZLogInfo("add event record %s type %d in scene %d %s irst %d~~~",
- producing->Result.RstName.c_str(), producing->Result.RstType,
- this->GetSrcId(), m_sceneName.c_str(), irst);
- }
- NAMESPACE_MAS_END
|