#include "DetectorLib.h" #include "SysUtils.h" #if defined(LINUX) #include #endif #define DET_LIB_INFO_LEN 1000 NAMESPACE_MAS_BEGIN DetectorLib::DetectorLib(const std::string & path) : m_path(path), m_detKey(""), m_sohd(INVALID_DLLHD), m_initialize(nullptr), m_dispose(nullptr), m_buildDetector(nullptr), m_destroyDetector(nullptr), m_getInformation(nullptr) {} DetectorLib::~DetectorLib() { if (m_sohd != INVALID_DLLHD) { if (m_dispose) { m_dispose(); } tzc::SysUtils::FreeLibrary(m_sohd); m_sohd = INVALID_DLLHD; } } TZ_INT DetectorLib::Initialize(DetectorInfo & jinfo) { m_sohd = tzc::SysUtils::LoadLibrary(m_path); if (m_sohd == INVALID_DLLHD) { TZLogError("Load DLL %s failed, dlerror: %s!!", m_path.c_str(), dlerror()); return MEC_FAILED; } m_initialize = (DET_Initialize)tzc::SysUtils::GetSymbol(m_sohd, INITIALIZE_DETECTOR_SYMBOL); if (!m_initialize) { TZLogError("Get INITIALIZE_DETECTOR_SYMBOL failed, invalid DLL %s!!", m_path.c_str()); return MEC_FAILED; } m_dispose = (DET_Dispose)tzc::SysUtils::GetSymbol(m_sohd, DISPOSE_DETECTOR_SYMBOL); if (!m_dispose) { TZLogError("Get DISPOSE_DETECTOR_SYMBOL failed, invalid DLL %s!!", m_path.c_str()); return MEC_FAILED; } m_buildDetector = (DET_BuildDetector)tzc::SysUtils::GetSymbol(m_sohd, BUILD_DETECTOR_SYMBOL); if (!m_buildDetector) { TZLogError("Get BUILD_DETECTOR_SYMBOL failed, invalid DLL %s!!", m_path.c_str()); return MEC_FAILED; } m_destroyDetector = (DET_DestroyDetector)tzc::SysUtils::GetSymbol(m_sohd, DESTROY_DETECTOR_SYMBOL); if (!m_destroyDetector) { TZLogError("Get DESTROY_DETECTOR_SYMBOL failed, invalid DLL %s!!", m_path.c_str()); return MEC_FAILED; } m_getInformation = (DET_GetInformation)tzc::SysUtils::GetSymbol(m_sohd, INFO_DETECTOR_SYMBOL); if (!m_getInformation) { TZLogError("Get INFO_DETECTOR_SYMBOL failed, invalid DLL %s!!", m_path.c_str()); return MEC_FAILED; } TZLogInfo("Initialize SONode of DLL %s succeed~~~", m_path.c_str()); std::string sinfo; this->GetInformation(sinfo); DetectorInfo::fromJson(sinfo, jinfo); m_detKey = jinfo.Key; return m_initialize(); } Detector DetectorLib::BuildDetector() { if (!m_buildDetector) { TZLogWarn("m_buildDetector is NULL, maybe it has not been initialized!!!"); return nullptr; } return m_buildDetector(); } TZ_INT DetectorLib::DestroyDetector(Detector * pdet) { if (!m_destroyDetector) { TZLogWarn("m_destroyDetector is NULL, maybe it has not been initialized!!!"); return MEC_NULL_OBJ; } return m_destroyDetector(pdet); } TZ_INT DetectorLib::GetInformation(std::string & info) { if (!m_getInformation) { TZLogWarn("m_getInformation is NULL, maybe it has not been initialized!!!"); return MEC_NULL_OBJ; } TZ_CHAR cinfo[DET_LIB_INFO_LEN + 10]; TZ_INT irst = m_getInformation(cinfo); if (irst) { TZLogWarn("%s m_getInformation failed!!", m_path.c_str()); return irst; } info = cinfo; return MEC_OK; } void DetectorLib::GetDetLibKey(std::string & detKey) { detKey = m_detKey; } NAMESPACE_MAS_END