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"
#include "rgooseNode2D.h"
#include "rgooseNodePTZCamControl.h"
#include "rgooseNodeStaticCamControl.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(); LOG("CONSTRUCTION");};
argusNodeFactory::~argusNodeFactory(){ unloadNodes(); _instance = NULL;};
bool argusNodeFactory::unloadNodes( void ){ if( m_pDBC != NULL ){ if( m_vNetNodes.size() > 0 ){ for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ){ LOG(" Unload Node... BEGIN"); switch( (*index)->getType() ){ case ARGUS_ANALOG_STATIC_CAMERA: LOG(" Static Analog Cam"); delete( (ARGUS_CAM*) (*index) ); break; case ARGUS_ANALOG_PTZ_CAMERA: LOG(" PTZ Analog Cam"); delete( (ARGUS_PTZCAM*) (*index) ); break; case ARGUS_IP_PTZ_CAMERA:{ LOG(" PTZ IP Cam"); delete( (ARGUS_PTZCAM*) (*index) ); break; }; case ARGUS_IP_STATIC_CAMERA:{ LOG(" Static IP Cam"); delete( (ARGUS_CAM*) (*index) ); break; }; case ARGUS_IP_UART_GATEWAY:{ LOG(" UART Gateway"); delete( (argusNetNode*) (*index) ); break; }; case ARGUS_ALS_SENSOR: case ARGUS_PLS_200_SENSOR: case ARGUS_PLS_360_SENSOR: case ARGUS_LFS_SENSOR:{ LOG(" 2D LRF"); delete( (ARGUS_2DSensor*) (*index) ); LOG(" 2D LRF done"); break; }; case ARGUS_3D_SENSOR:{ LOG(" 3D LRF"); delete( (argus3DLIDAR*) (*index) ); break; }; }; LOG(" Unload Node... DONE!"); }; m_vNetNodes.clear(); m_mNetNodesIDS.clear(); }; }; return true;};/*
bool argusNodeFactory::loadNodes( uint32_t SiteID ){ LOG("Node Loader"); if(m_pDBC == NULL) return false; m_nSiteID = SiteID; DBC_INT_LIST *tList = m_pDBC->listNodes( SiteID ); if( tList != NULL ) { for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ){ uint32_t id = *idx; char msg[64]; sprintf( msg, "Creating Node[%d]", id ); createNode( id ); }; tList->clear(); delete( tList ); return true; }; return false;}; */bool argusNodeFactory::loadNodes( uint32_t SiteID ){ if( m_pDBC == NULL ) return false; m_nSiteID = SiteID; DBC_INT_LIST *tList = m_pDBC->listNodes( SiteID ); if( tList != NULL ) { for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) createNode((*idx)); tList->clear(); delete( tList ); } #ifdef DEBUG
else { LOG("No Nodes Defined"); }#endif
return true;};
bool argusNodeFactory::reloadNodes( uint32_t SiteID ){ if(!unloadNodes()) return false; return loadNodes( SiteID ); };
bool argusNodeFactory::reloadNode( uint32_t NodeID ){ deleteNode( NodeID ); argusNetNode *tNode = createNode( NodeID ); if( tNode ) { return true; }; return false;};
argusNetNode *argusNodeFactory::createNode( uint32_t id ){ argusNetNode *tVal = NULL; LOG("Create Node!"); 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
ARGUS_CAM *tCamera; tCamera = new ARGUS_CAM( id ); if( tCamera ) { LOG("Starting Service"); tCamera->startService(); tVal = ( argusNetNode *) tCamera; LOG("Success"); }; break; }; case ARGUS_ANALOG_PTZ_CAMERA:{#ifdef DEBUG
LOG("Creating Analog PTZ Camera");#endif
ARGUS_PTZCAM *tCamera; tCamera = new ARGUS_PTZCAM( id ); if( tCamera ) { LOG("Starting Service"); tCamera->startService(); tVal = ( argusNetNode *) tCamera; LOG("Success"); }; break; }; case ARGUS_IP_STATIC_CAMERA:{#ifdef DEBUG
LOG("Creating IP Static Camera");#endif
ARGUS_CAM *tCamera; tCamera = new ARGUS_CAM( id ); if( tCamera ) {#ifdef DEBUG
LOG("Starting Service");#endif
if( tCamera->startService() ){ tVal = ( argusNetNode *) tCamera;#ifdef DEBUG
LOG("Success");#endif
} else {#ifdef DEBUG
LOG_ERROR("Error Sterting Service");#endif
delete( tCamera ); }; }; break; }; case ARGUS_IP_PTZ_CAMERA:{
#ifdef DEBUG
LOG("Creating IP PTZ Camera");#endif
ARGUS_PTZCAM *tCamera; tCamera = new ARGUS_PTZCAM( id ); if( tCamera ) {#ifdef DEBUG
LOG("Starting Service");#endif
if( tCamera->startService() ){ tVal = ( argusNetNode *) tCamera;#ifdef DEBUG
LOG("Success");#endif
} else {#ifdef DEBUG
LOG_ERROR("Error Starting Service!");#endif
delete( tCamera ); }; }; break; }; case ARGUS_IP_UART_GATEWAY:{#ifdef DEBUG
LOG("Creating Ethernet to UART Gateway");#endif
tVal = new argusNetNode( id ); 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
ARGUS_2DSensor *tSensor; tSensor = new ARGUS_2DSensor( id ); if( tSensor ) { LOG("Success"); tSensor->startService(); tVal = ( argusNetNode *) tSensor; }; break; }; case ARGUS_ALS_SENSOR:{#ifdef DEBUG
LOG("Creating ALS Sensor");#endif
ARGUS_2DSensor *tSensor; tSensor = new ARGUS_2DSensor( id ); if( tSensor ) { LOG("Success"); tSensor->startService(); tVal = ( argusNetNode *) tSensor; }; break; }; case ARGUS_PLS_200_SENSOR:{#ifdef DEBUG
LOG("Creating PLS200 Sensor");#endif
ARGUS_2DSensor *tSensor; tSensor = new ARGUS_2DSensor( id ); if( tSensor ) { LOG("Success"); tSensor->startService(); tVal = ( argusNetNode *) tSensor; }; break; }; case ARGUS_PLS_360_SENSOR:{#ifdef DEBUG
LOG("Creating PLS360 Sensor");#endif
ARGUS_2DSensor *tSensor; tSensor = new ARGUS_2DSensor( id ); if( tSensor ) { LOG("Success"); tSensor->startService(); tVal = ( argusNetNode *) tSensor; }; 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
SLEEP(2000); LOG("Actual Destroying Network Static Camera"); delete((ARGUS_PTZCAM *) ptr ); break; case ARGUS_IP_PTZ_CAMERA:#ifdef DEBUG
LOG("Destroying Network PTZ Camera");#endif
SLEEP(2000); delete((ARGUS_PTZCAM *) ptr );#ifdef DEBUG
LOG("Done Successfuly");#endif
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( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ) tL.push_back( (*idx)->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( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) createNode( *idx ); tList->clear(); delete( tList ); }#ifdef DEBUG_EXTRA
else { LOG( "No New Nodes Added"); }#endif
#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 ) { for( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ){ bool tRemoved = true; for( DBC_INT_LIST::iterator idz = tList->begin(); idz < tList->end(); idz++ ) if( (*idz) == (*idx)->getDbId() ) tRemoved = false; tRemoved = !(*idx)->validate(); if( tRemoved ) { deleteNode((*idx)); }; }; tList->clear(); delete( tList ); } else { LOG("All Modules Must be Deleted!"); for( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ) deleteNode((*idx)); m_vNetNodes.clear(); m_mNetNodesIDS.clear(); }; }#ifdef DEBUG
else { LOG("No Nodes 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
};
uint32_t argusNodeFactory::getNodesCount( 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 = getNodesCount( 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
|