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 "rgooseNodeFactory.h"
#include "rgooseIPCamera.h"
#include "rgooseNode3D.h"
#ifdef MEM_DEBUG
#include "../alg/generic/heapDebug.h"
#endif
#define LOG( X ) m_pLog->Log( "NFAC", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "NFAC", this, _LOG_ERROR, X )
argusNodeFactory * argusNodeFactory::_instance = 0;
/**
* Returns the single instance of the object.*/argusNodeFactory* argusNodeFactory::getInstance() { // check if the instance has been created yet
if (0 == _instance) { // if not, then create it
_instance = new argusNodeFactory; } // return the single instance
return _instance;};argusNodeFactory::argusNodeFactory(){ m_pLog = basicLogCollection::getInstance(); m_pDBC = argusDBC::getInstance();};
argusNodeFactory::~argusNodeFactory(){ if( m_vNetNodes.size() > 0 ){ for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ){ switch( (*index)->getType() ){ //case ARGUS_ANALOG_STATIC_CAMERA: delete( (chucha*) (*index) ); break;
case ARGUS_IP_STATIC_CAMERA: delete( (ARGUS_Camera*) (*index) ); break; }; }; m_vNetNodes.clear(); m_mNetNodesIDS.clear(); };};
bool argusNodeFactory::loadNodes( uint32_t SiteID ){ if(m_pDBC == NULL) return false; m_nSiteID = SiteID; DBC_INT_LIST *tList = NULL; tList = m_pDBC->listNodes( SiteID ); if( tList != NULL ) { for( int index=0; index< tList->size(); index++ ) { createNode( tList->at(index) ); }; tList->clear(); delete( tList ); return true; }; return false;};
argusNetNode *argusNodeFactory::createNode( uint32_t id ){ argusNetNode *tVal = NULL; if( m_pDBC != NULL ){ DBC_NODE_DATA *tData = NULL; tData = m_pDBC->getNodeData( id ); if( tData!= NULL ) { switch( tData->type ) { case ARGUS_ANALOG_STATIC_CAMERA:#ifdef DEBUG
LOG("Creating Analog Static Camera");#endif
break; case ARGUS_ANALOG_PTZ_CAMERA:#ifdef DEBUG
LOG("Creating Analog PTZ Camera");#endif
break; case ARGUS_IP_STATIC_CAMERA:{#ifdef DEBUG
LOG("Creating Network Static Camera");#endif
ARGUS_IPCAM *tCamera; tCamera = new ARGUS_IPCAM( id ); if( tCamera ) { LOG("Success"); tVal = ( argusNetNode *) tCamera; }; }; break; case ARGUS_IP_PTZ_CAMERA:#ifdef DEBUG
LOG("Creating Network PTZ Camera");#endif
break; case ARGUS_IP_UART_GATEWAY:#ifdef DEBUG
LOG("Creating Ethernet to UART Gateway");#endif
break; case ARGUS_IP_VIDEO_SERVER:#ifdef DEBUG
LOG("Creating Network Video Encoder");#endif
break; case ARGUS_LFS_SENSOR:#ifdef DEBUG
LOG("Creating LFS Sensor");#endif
break; case ARGUS_ALS_SENSOR:{#ifdef DEBUG
LOG("Creating ALS Sensor");#endif
break; }; case ARGUS_PLS_200_SENSOR:#ifdef DEBUG
LOG("Creating PLS200 Sensor");#endif
break; case ARGUS_PLS_360_SENSOR:#ifdef DEBUG
LOG("Creating PLS360 Sensor");#endif
break; case ARGUS_3D_SENSOR:{#ifdef DEBUG
LOG("Creating 3D Sensor");#endif
argus3DLIDAR *t3DRadar; t3DRadar = new argus3DLIDAR( id ); if( t3DRadar ) { LOG("Success"); t3DRadar->startService(); tVal = ( argusNetNode *) t3DRadar; }; break; }; case ARGUS_JAMER:#ifdef DEBUG
LOG("Creating RF Jamer");#endif
break; case ARGUS_NET_PLS_200:#ifdef DEBUG
LOG("Creating Network-PLS200 Sensor");#endif
break; case ARGUS_DRONE_CONTROL:#ifdef DEBUG
LOG("Creating Drone Controll");#endif
break; }; free(tData); }; }; if( tVal != NULL ){ m_vNetNodes.push_back( tVal ); m_mNetNodesIDS[id] = tVal; }; return tVal;};
void argusNodeFactory::deleteNode( argusNetNode *ptr ){ if( ptr == NULL ) return; // if some troubles move this to an end of the function!
for( vectorNetNodes::iterator index = m_vNetNodes.begin() ; index < m_vNetNodes.end(); index++ ){ if( (*index) == ptr ) { m_mNetNodesIDS.erase( ptr->getDbId() ); m_vNetNodes.erase( index ); break; }; }; switch( ptr->getType() ) { case ARGUS_ANALOG_STATIC_CAMERA:#ifdef DEBUG
LOG("Destroying Analog Static Camera");#endif
break; case ARGUS_ANALOG_PTZ_CAMERA:#ifdef DEBUG
LOG("Destroying Analog PTZ Camera");#endif
break; case ARGUS_IP_STATIC_CAMERA:#ifdef DEBUG
LOG("Destroying Network Static Camera");#endif
delete((ARGUS_Camera *) ptr ); break; case ARGUS_IP_PTZ_CAMERA:#ifdef DEBUG
LOG("Destroying Network PTZ Camera");#endif
delete((ARGUS_Camera *) ptr ); break; case ARGUS_IP_UART_GATEWAY:#ifdef DEBUG
LOG("Destroying Ethernet to UART Gateway");#endif
break; case ARGUS_IP_VIDEO_SERVER:#ifdef DEBUG
LOG("Destroying Network Video Encoder");#endif
break; case ARGUS_LFS_SENSOR:#ifdef DEBUG
LOG("Destroying LFS Sensor");#endif
break; case ARGUS_ALS_SENSOR:#ifdef DEBUG
LOG("Destroying ALS Sensor");#endif
break; case ARGUS_PLS_200_SENSOR:#ifdef DEBUG
LOG("Destroying PLS200 Sensor");#endif
break; case ARGUS_PLS_360_SENSOR:#ifdef DEBUG
LOG("Destroying PLS360 Sensor");#endif
break; case ARGUS_3D_SENSOR:#ifdef DEBUG
LOG("Destroying 3D Sensor");#endif
break; case ARGUS_JAMER:#ifdef DEBUG
LOG("Destroying RF Jamer");#endif
break; case ARGUS_NET_PLS_200:#ifdef DEBUG
LOG("Destroying Network-PLS200 Sensor");#endif
break; case ARGUS_DRONE_CONTROL:#ifdef DEBUG
LOG("Destroying Drone Controll");#endif
break; };};
/*
@id Database ID of Node to be deleted*/argusNetNode *argusNodeFactory::getNode( uint32_t id ){ mapNode2Id::iterator it; it = m_mNetNodesIDS.find( id ); if( it != m_mNetNodesIDS.end() ) { return m_mNetNodesIDS[id]; }; return NULL;};
/*
@id Database ID of Node to be deleted*/void argusNodeFactory::deleteNode( uint32_t id ){ argusNetNode *tNode = getNode( id ); deleteNode( tNode );};
void argusNodeFactory::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_vNetNodes.size() ) { DBC_INT_LIST tL; for( int cm = 0; cm < m_vNetNodes.size(); cm++ ) tL.push_back( m_vNetNodes.at(cm)->getDbId() ); tList = m_pDBC->listNewNodes( m_nSiteID, &tL ); tL.clear(); } else { tList = m_pDBC->listNewNodes( m_nSiteID, NULL ); }; if( tList != NULL ) { LOG("New Nodes Added!"); for( int index=0; index< tList->size(); index++) createNode(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_vNetNodes.size() ) { //Get Full List
tList = m_pDBC->listNodes( m_nSiteID ); if( tList != NULL ) { int cm = 0; while( cm < m_vNetNodes.size() ) { //check if module removed
bool tRemoved = true; for( int lm = 0; lm < tList->size(); lm++ ) { if( tList->at(lm) == m_vNetNodes.at(cm)->getDbId() ) { tRemoved = false; break; }; }; if( !tRemoved ) { // validate module
m_vNetNodes.at(cm)->validate(); cm++; } else { deleteNode( cm ); }; }; tList->clear(); delete( tList ); } else { LOG("All Modules Must be Deleted!"); while( m_vNetNodes.size() ) deleteNode( (uint32_t) 0 ); }; };#ifdef MEM_DEBUG
memEnd = getCurrentRSS(); memDiff = memEnd - memStart; sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff ); LOG( MEM_MSG );#endif
};
uint32_t argusNodeFactory::getNodeCount( ARGUS_NODE_TYPE type ){ uint32_t RetVal = 0; if( m_vNetNodes.size() ) for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ) if( (*index)->getType() == type ) RetVal++; return RetVal;};
uint32_t argusNodeFactory::fetchNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){ uint32_t RetVal = 0; if( RA == NULL ) { RetVal = getNodeCount( type ); if( RetVal > 0 ) { RA = (argusNetNode **) calloc( RetVal, sizeof(argusNetNode *)); if( RA == NULL ) return 0; uint32_t cnt = 0; for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ) { if( (*index)->getType() == type ) { RA[cnt] = (*index); cnt++; }; }; }; } else { if( m_vNetNodes.size() ) { for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ) { if( (*index)->getType() == type ) { RA[RetVal] = (*index); RetVal++; }; }; }; }; return RetVal;};
#undef LOG
#undef LOG_ERROR
|