StraStreamPipe.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "StraStreamPipe.h"
  2. #include "Strategy.h"
  3. #include "DBMgr.h"
  4. NAMESPACE_MAS_BEGIN
  5. StraStreamPipe::StraStreamPipe(TZ_INT sceneId,
  6. const std::string & sceneName,
  7. TZ_INT straId, const std::string & straParams,
  8. const ExcepInfo & einfo) :
  9. IStreamPipe(sceneId, straId, EMPT_STRA, einfo),
  10. m_sceneName(sceneName), m_straParams(straParams)
  11. {
  12. }
  13. StraStreamPipe::~StraStreamPipe()
  14. {
  15. this->Dispose();
  16. }
  17. TZ_INT StraStreamPipe::Initialize(SPtr<StrategyLib> & straLib)
  18. {
  19. m_straLib = straLib;
  20. straLib->GetStraLibKey(m_straKey);
  21. m_strategy = straLib->BuildStrategy();
  22. if (!m_strategy)
  23. {
  24. TZLogWarn("build strategy %s nullptr!!!", m_straKey.c_str());
  25. return MEC_NULL_OBJ;
  26. }
  27. auto irst = m_strategy->Initialize();
  28. if (irst)
  29. {
  30. TZLogWarn("stra %s init failed!!!", m_straKey.c_str());
  31. return irst;
  32. }
  33. m_strategy->SetStrategyCfg(m_straParams);
  34. TZLogInfo("stra %s init succeed~~~", m_straKey.c_str());
  35. return MEC_OK;
  36. }
  37. TZ_INT StraStreamPipe::Dispose()
  38. {
  39. m_straLib->DestroyStrategy(m_strategy);
  40. m_strategy = nullptr;
  41. return MEC_OK;
  42. }
  43. std::tuple<TZ_BOOL, TZ_BOOL> StraStreamPipe::streamArrived(
  44. SPtr<StreamInfo> & streamInfo)
  45. {
  46. TZ_BOOL isEvent = FALSE;
  47. // 由策略内部 SetStraRst
  48. m_strategy->DoStrategy(streamInfo);
  49. SPtr<StraProducing> rst = streamInfo->GetStraProducing();
  50. if (rst->Result.RstType)
  51. {
  52. this->addRecord(rst);
  53. }
  54. return std::make_tuple(TRUE, FALSE);
  55. }
  56. TZ_INT StraStreamPipe::SetStrategyCfg(const std::string & param)
  57. {
  58. return m_strategy->SetStrategyCfg(param);
  59. }
  60. void StraStreamPipe::addRecord(SPtr<StraProducing> & producing)
  61. {
  62. producing->Result.SceneName = m_sceneName;
  63. producing->Result.SceneId = this->GetSrcId();
  64. TblEventRecordItem event;
  65. event.Tb_Id = INVALID_PRIMARY_KEY;
  66. event.Tb_Type = (producing->Result.RstType == 1 ? "事件" : "报警");
  67. event.Tb_Name = producing->Result.RstName;
  68. event.Tb_Externs = producing->Result.Externs;
  69. event.Tb_StrategyName = m_straKey;
  70. event.Tb_SceneId = this->GetSrcId();
  71. event.Tb_SceneName = m_sceneName;
  72. event.Tb_BeginTime = producing->Result.BeginTime;
  73. event.Tb_EndTime = event.Tb_BeginTime;
  74. event.Tb_Description = producing->Result.Externs;
  75. auto irst = DBMGR->AddOrUpdateTblEventRecord(event);
  76. TZLogInfo("add event record %s type %d in scene %d %s irst %d~~~",
  77. producing->Result.RstName.c_str(), producing->Result.RstType,
  78. this->GetSrcId(), m_sceneName.c_str(), irst);
  79. }
  80. NAMESPACE_MAS_END