You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#include "rgooseModuleFactory.h"
#include "rgooseModuleZLMedia.h"
#include "rgooseModuleUSBRelay.h"
#include "rgooseModuleKafka.h"
#include "rgooseModuleFlyHunter.h"
#include "rgooseModuleSSDP.h"
#include "rgooseModuleOnvifObserver.h"
#include "rgooseModuleEmbedVideo.h"
#ifdef MEM_DEBUG
#include "../alg/generic/heapDebug.h"
#endif
#define LOG( X ) m_pLog->Log( "MFAC", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "MFAC", this, _LOG_ERROR, X )
argusModuleFactory * argusModuleFactory::_instance = 0;
/**
* Returns the single instance of the object.*/argusModuleFactory* argusModuleFactory::getInstance() { // check if the instance has been created yet
if (0 == _instance) { // if not, then create it
_instance = new argusModuleFactory; } // return the single instance
return _instance;};argusModuleFactory::argusModuleFactory(){ m_pLog = basicLogCollection::getInstance(); m_pDBC = argusDBC::getInstance();};
argusModuleFactory::~argusModuleFactory(){ shutdownServices(); _instance = NULL;};
void argusModuleFactory::shutdownServices( bool force ){#ifdef DEBUG
LOG("shutdownServices");#endif
if( m_vKernelModules.size() > 0 ){ for( vectorKernelModules::iterator index = m_vKernelModules.begin(); index < m_vKernelModules.end(); index++ ){#ifdef DEBUG
LOG("Stop Service of Module");#endif
(*index)->stopService( force );#ifdef DEBUG
LOG("Done");#endif
deleteModule( (*index) );#ifdef DEBUG
LOG("Module is Deleted");#endif
}; m_vKernelModules.clear(); };#ifdef DEBUG
LOG("Done shutdownServices");#endif
};
bool argusModuleFactory::loadModules( uint32_t ServerID ){ DBC_INT_LIST *tList = NULL;
if(m_pDBC == NULL) return false; m_nServerID = ServerID; tList = m_pDBC->listModules( m_nServerID ); if( tList != NULL ) { if( tList->size() ) { for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) createModule( *idx ); tList->clear(); }#ifdef DEBUG
else { LOG("No Modules Defined"); }#endif
delete( tList ); }#ifdef DEBUG
else { LOG("No Modules Defined"); }#endif
return true;};
argusKernelModule *argusModuleFactory::createModule( int id ){ argusKernelModule *tVal = NULL; if( m_pDBC != NULL ){ DBC_MODULE_DATA *tData = NULL;
tData = m_pDBC->getModuleData( id ); if( tData!= NULL ) { switch( tData->type ) { case ARGUS_MODULE_ZLMEDIA:#ifdef DEBUG
LOG("Creating ZLMedia Connector Module");#endif
tVal = new argusModuleZLMedia( tData->module_id ); break; case ARGUS_MODULE_DCBUSB:#ifdef DEBUG
LOG("Creating Dry Contact USB Module");#endif
tVal = new argusModuleUSBRelay( tData->module_id ); break; case ARGUS_MODULE_KAFKA:#ifdef DEBUG
LOG("Creating KAFKA Module");#endif
tVal = new argusModuleKafka( tData->module_id ); break; case ARGUS_MODULE_FLYHUNTER:#ifdef DEBUG
LOG("Creating Fly Hunter Module");#endif
tVal = new argusModuleFlyHunter( tData->module_id ); break; case ARGUS_MODULE_SSDP_ANONCE:#ifdef DEBUG
LOG("Creating SSDP Announcer Module");#endif
tVal = new argusModuleSSDPAnnouncer( tData->module_id ); break; case ARGUS_MODULE_ONVIF_OBSERVER:#ifdef DEBUG
LOG("Creating OnVif Observer Module");#endif
tVal = new argusModuleOnvifObserver( tData->module_id ); break; case ARGUS_MODULE_EMBED_VIDEO:#ifdef DEBUG
LOG("Creating Embed Video Module");#endif
tVal = new argusModuleEmbedVideo( tData->module_id ); break; }; free(tData); } else { LOG_ERROR("No Module Data Fetched!"); }; } else { LOG_ERROR("No Database Object Assigned!"); }; if( tVal != NULL ){ tVal->startService(); m_vKernelModules.push_back( tVal ); }; return tVal;};
void argusModuleFactory::deleteModule( argusKernelModule *M ){ if( M ) { switch( M->getType() ) { case ARGUS_MODULE_ZLMEDIA: delete( (argusModuleZLMedia *) M ); break; case ARGUS_MODULE_DCBUSB: delete( (argusModuleUSBRelay*) M ); break; case ARGUS_MODULE_KAFKA: delete( (argusModuleKafka*) M ); break; case ARGUS_MODULE_FLYHUNTER: delete( (argusModuleFlyHunter*) M ); break; case ARGUS_MODULE_SSDP_ANONCE: delete( (argusModuleSSDPAnnouncer*) M ); break; case ARGUS_MODULE_ONVIF_OBSERVER: delete( (argusModuleOnvifObserver*) M ); break; case ARGUS_MODULE_EMBED_VIDEO: delete( (argusModuleEmbedVideo*) M ); break; }; };};
void argusModuleFactory::deleteModule( int id ){ if( m_vKernelModules.size() > id ) { deleteModule( m_vKernelModules.at( id ) ); m_vKernelModules.erase( m_vKernelModules.begin() + id ); m_vKernelModules.shrink_to_fit(); };};
uint32_t argusModuleFactory::getModulesCount( ARGUS_MODULE_TYPE t ){ uint32_t cnt = 0; if( m_vKernelModules.size() ) { for( int i=0; i < m_vKernelModules.size(); i++ ) { if( m_vKernelModules.at(i)->getType() == t ) cnt++; }; }; return cnt;};
uint32_t argusModuleFactory::fetchModules( ARGUS_MODULE_TYPE t, argusKernelModule**&RA ){ uint32_t cnt = getModulesCount( t ); RA = NULL; if( cnt > 0 ) { RA = ( argusKernelModule** ) calloc( cnt, sizeof( argusKernelModule* ) ); if( RA!= NULL ) { if( m_vKernelModules.size() ) { uint32_t idx = 0; for( int i=0; i < m_vKernelModules.size(); i++ ) { if( m_vKernelModules.at(i)->getType() == t ) { RA[idx] = m_vKernelModules.at(i); idx++; }; }; }; } else cnt = 0; }; return cnt;};
argusKernelModule *argusModuleFactory::getModule( uint32_t id ){ argusKernelModule *RetVal = NULL; if( m_vKernelModules.size() ) { for( vectorKernelModules::iterator idx = m_vKernelModules.begin(); idx < m_vKernelModules.end(); idx++ ){ if( (*idx)->getId() == id ) { RetVal = (*idx); break; }; }; }; return RetVal;};
argusKernelModule *argusModuleFactory::getModule( ARGUS_MODULE_TYPE t, uint32_t id ){ argusKernelModule *RetVal = NULL; if( m_vKernelModules.size() ) { for( vectorKernelModules::iterator idx = m_vKernelModules.begin(); idx < m_vKernelModules.end(); idx++ ){ if( id ){ if( ( (*idx)->getType() == t ) && ( (*idx)->getId() == id ) ){ RetVal = (*idx); break; }; } else { if( (*idx)->getType() == t ){ RetVal = (*idx); break; }; }; }; }; return RetVal;};
void argusModuleFactory::validate( void ){ if(m_pDBC == NULL) return; DBC_INT_LIST *tList = NULL;
#ifdef MEM_DEBUG
size_t memStart, memEnd, memDiff; char MEM_MSG[256]; memStart = getCurrentRSS();#endif
if( m_vKernelModules.size() ) { DBC_INT_LIST tL; for( int cm = 0; cm < m_vKernelModules.size(); cm++ ) tL.push_back( m_vKernelModules.at(cm)->getId() ); tList = m_pDBC->listNewModules( m_nServerID, &tL ); tL.clear(); } else { tList = m_pDBC->listNewModules( m_nServerID, NULL ); }; if( tList != NULL ) {#ifdef DEBUG
LOG("New Modules Exists!");#endif
for( int index=0; index< tList->size(); index++) createModule(tList->at(index)); tList->clear(); delete( tList ); };#ifdef MEM_DEBUG
memEnd = getCurrentRSS(); memDiff = memEnd - memStart; sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff ); LOG( MEM_MSG );#endif
if( m_vKernelModules.size() ) { //Get Full List
//tList = NULL;
tList = m_pDBC->listModules( m_nServerID ); if( tList != NULL ) { int cm = 0; while( cm < m_vKernelModules.size() ) { //check if module removed
bool tRemoved = true; for( int lm = 0; lm < tList->size(); lm++ ) { if( tList->at(lm) == m_vKernelModules.at( cm )->getId() ) { tRemoved = false; break; }; }; if( !tRemoved ) { // validate module
m_vKernelModules.at( cm )->validate(); cm++; } else {#ifdef DEBUG
LOG("Delete Module!");#endif
deleteModule( cm ); }; }; tList->clear(); delete( tList ); } else {#ifdef DEBUG
LOG("All Modules Must be Deleted!");#endif
while( m_vKernelModules.size() ) deleteModule( 0 ); }; } else {#ifdef DEBUG
LOG("No Modules to Validate!");#endif
};#ifdef MEM_DEBUG
memEnd = getCurrentRSS(); memDiff = memEnd - memStart; sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff ); LOG( MEM_MSG );#endif
};
#undef LOG
#undef LOG_ERROR
|