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.
 
 
 
 
 
 

1100 lines
40 KiB

/*******************************************************************
*
* DESCRIPTION: ARGUS Kernel source
*
* AUTHOR: gagua
*
* HISTORY:
*
* DATE:5/29/2019
*
*******************************************************************/
#include "rgooseKernel.h"
#include "rgooseFilterAPF.h"
#include <sys/types.h>
#include <sys/sysinfo.h>
#include <sys/statvfs.h>
#include <time.h>
#include "../data/json/json_tool.h"
#include <strings.h>
#include <json/value.h>
#include <json/writer.h>
#include <json/reader.h>
#define LOG( X ) m_pLog->Log( "KRNL", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG2w34[256];\
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X );
#endif
argusKernel *argusKernel::_instance = NULL;
/**
* Returns the single instance of the object.
*/
argusKernel* argusKernel::getInstance( bool cold_start, config_setting_t *Settings ) {
// check if the instance has been created yet
if( 0 == _instance ){
// if not, then create it
_instance = new argusKernel( cold_start, Settings );
};
// return the single instance
return _instance;
};
argusKernel::argusKernel( bool cold_start, config_setting_t *Settings ):basicThread(), basicEventHandler(){
m_bExitCause = 0;
m_nServerID = 0;
m_nSiteID = 0;
m_pDBC = NULL;
m_bSkipResignComponents = cold_start;
m_tTimeTSeconds = time( NULL );
m_pLog = basicLogCollection::getInstance();
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
//m_pServiceAnnouncer = NULL;
m_pEventHeap = NULL;
//m_pOnvifMediaObserver = NULL;
m_pNodeFactory = NULL;
m_pModuleFactory = NULL;
#ifdef SIMULATE_KERNEL_TARGETS
sprintf( m_cCurrentMission,"" );
m_bLandingTO = 0;
m_bJamingTO = 0;
#endif
};
argusKernel::~argusKernel(){
WaitFinish( true );
#ifdef DEBUG
LOG(" Deleting Node Factory...");
#endif
if( m_pNodeFactory != NULL ) delete( m_pNodeFactory );
#ifdef DEBUG
LOG(" Deleting Module Factory...");
#endif
if( m_pModuleFactory != NULL ) delete( m_pModuleFactory );
#ifdef DEBUG
LOG(" Deleting Target Filters...");
#endif
unloadFilters();
if( m_bExitCause == 0 ) {
#ifdef DEBUG
LOG("Unregister Server");
#endif
m_pDBC->unregisterServer( m_nSiteID, m_nServerNodeID );
#ifdef DEBUG
LOG("Close DataBase Connection...");
#endif
if( m_pDBC != NULL ) delete( m_pDBC );
m_pDBC = NULL;
} else {
if( m_bExitCause == 4 ) {
#ifdef DEBUG
LOG("HW PNP Detection Requested...");
#endif
//m_pDBC->updateNodePushedCMD( tCMD->id, 30 );
m_pHardwareManager->enumerateHardware();
//m_pDBC->updateNodePushedCMD( tCMD->id, 60 );
};
#ifdef DEBUG
LOG("Close DataBase Connection...");
#endif
if( m_pDBC != NULL ) delete( m_pDBC );
m_pDBC = NULL;
};
_instance = NULL;
};
bool argusKernel::create( void ){
char tBuffer[256];
if( m_pSettings != NULL ) {
config_setting_t * pSetting;
int tVal;
const char * tBuf;
LOG("Getting Settings ...");
if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){
char * tVar;
char * tTS;
tTS = getTStr(NULL);
tVar = MD5String(tTS);
free(tTS);
sprintf( m_sIdentity, tVar );
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, CONFIG_TYPE_STRING );
config_setting_set_string( pSetting, tVar );
free( tVar );
basicSettingsProvider::getInstance()->compromise();
LOG("Server Identity not defined - generating new!");
} else {
sprintf( m_sIdentity, tBuf );
sprintf( tBuffer, "Server Identity Read From Settings: %s", tBuf );
LOG( tBuffer );
};
if( !config_setting_lookup_int( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, &tVal ) ){
tVal = m_nSiteID = 1;
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, CONFIG_TYPE_INT );
config_setting_set_int( pSetting, tVal );
basicSettingsProvider::getInstance()->compromise();
LOG("Site ID not defined - using [1] as number!");
} else {
m_nSiteID = tVal;
sprintf( tBuffer, "Site ID Read From Settings: %d", m_nSiteID );
LOG( tBuffer );
};
} else {
LOG_ERROR("Failed Read Config Settings!");
return false;
};
if( m_pDBC == NULL ) {
LOG("Explicitly Create DBC Object");
m_pDBC = argusDBC::getInstance( m_pSettings );
};
if( m_pDBC == NULL ){
LOG_ERROR("DBC Object Creation Failure!");
return false;
} else LOG("DBC Object is OK");
if(!m_pDBC->connect()){
LOG_ERROR("DBC Connection Failure!");
SLEEP(5000);
//ToDO: Set Restart Kernel!
return false;
};
#ifdef DEBUG
LOG( "Settings Read Done" );
#endif
m_pDBC->registerServer( m_nSiteID, m_sIdentity, getpid(), &m_nServerID, &m_nServerNodeID );
//m_nServerID = m_pDBC->getServerID( m_sIdentity );
//m_nServerNodeID = m_pDBC->getServerNode( m_nServerID );
DBC_SITE_DATA *tSiteData = m_pDBC->getSiteData( m_nSiteID );
if( tSiteData ) {
C3D_WGS84_LOC t;
t.lat = tSiteData->lat;
t.lon = tSiteData->lon;
t.alt = tSiteData->alt;
m_pSystemAnchor = systemAnchor::getInstance( tSiteData->SH, &t, tSiteData->local_binding );
free( tSiteData );
} else {
LOG_ERROR("Error Loading Site DATA!");
};
//Check To Finish Reset
DBC_PUSHED_CMD *tCMD = m_pDBC->getActivePushedCMD( m_nServerNodeID );
if( tCMD ) {
m_pDBC->updateNodePushedCMD( tCMD->id, 100 );
free( tCMD );
};
//Init Subcomponents
m_pHardwareManager = argusHardwareManager::getInstance( m_bSkipResignComponents );
if( m_pHardwareManager!= NULL ) {
m_pHardwareManager->validate();
} else {
LOG_ERROR("Failure to get HardwareManager Instance!");
return false;
};
m_pDBC->setNodeOnline( m_nServerNodeID, ARGUS_NODE_STATUS_WORK );
//m_pServiceAnnouncer = new ssdpAnnouncer( m_pSettings );
basicSettingsProvider::getInstance()->validate();
m_pEventHeap = basicEventHeap::getInstance();
m_pModuleFactory = argusModuleFactory::getInstance( m_nServerID );
if( !m_pModuleFactory ) {
LOG_ERROR("Failure to get Module Factory Instance!");
return false;
} else {
#ifdef DEBUG
LOG( "Module Factory Created" );
#endif
while( !m_pModuleFactory->isValidationDone() ) SLEEP( 10 );
#ifdef DEBUG
LOG( "Module Factory Validated" );
#endif
};
#ifdef DEBUG
LOG( "Load Filters" );
#endif
loadFilters();
#ifdef DEBUG
LOG( "Filters Loaded" );
#endif
m_pNodeFactory = argusNodeFactory::getInstance( m_nSiteID, m_nServerID );
if( !m_pNodeFactory ) {
LOG_ERROR("Failure to get Node Factory Instance!");
return false;
}
#ifdef DEBUG
else {
LOG( "Node Factory Created" );
}
#endif
;
#ifdef DEBUG
LOG( "Kernel Trhead is about to be Created" );
#endif
if( init() == false ){
LOG_ERROR("Error in starting Kernel Thread!");
return false;
};
#ifdef DEBUG
LOG( "Kernel Thread Created" );
sprintf( tBuffer, "Server is registered as id[%d]", m_nServerID );
LOG( tBuffer );
#endif
return true;
};
void argusKernel::loadFilters(){
if( m_pDBC == NULL ) return;
DBC_INT_LIST *tList = m_pDBC->listFilters( m_nServerID );
if( tList != NULL ) {
if( tList->size() > 0 ) {
for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) {
DBC_TARGET_FLITER_DATA *tData = NULL;
tData = m_pDBC->getTargetFilterData( (*idx) );
if( tData != NULL ) {
switch( tData->type ) {
case TF_AUTHORISED_PEOPLE_FILTER: {
ARGUS_APF *tFilter = new ARGUS_APF( tData->aux_id );
if( tFilter != NULL ) {
if( tFilter->initFilter() ){
m_vTargetFilters.push_back( (ARGUS_TARGET_FILTER*) tFilter );
} else {
delete( tFilter );
};
};
break;
};
};
free( tData );
};
};
tList->clear();
};
delete( tList );
} else {
#ifdef DEBUG
LOG("No Target Filters Assigned!");
#endif
};
};
void argusKernel::unloadFilters(){
if( m_vTargetFilters.size() > 0 ) {
#ifdef DEBUG
LOG("Have Filters to Unload");
#endif
for( V_TARGET_FILTERS::iterator idx = m_vTargetFilters.begin(); idx < m_vTargetFilters.end(); idx++ ){
switch( (*idx)->getType() ) {
case TF_AUTHORISED_PEOPLE_FILTER:{
delete( (ARGUS_APF*)(*idx) );
break;
};
default:{
char tBuffer[64];
sprintf( tBuffer, "Unknown Filter: %d", (*idx)->getType() );
LOG( tBuffer );
};
};
};
m_vTargetFilters.clear();
LOG("Unload Filters Done!");
}
#ifdef DEBUG
else {
LOG("No Filters to Unload!");
}
#endif
;
};
ARGUS_TARGET_FILTER *argusKernel::getFilter( uint32_t id ){
ARGUS_TARGET_FILTER *RetVal = NULL;
if( m_vTargetFilters.size() > 0 ) {
for( V_TARGET_FILTERS::iterator idx = m_vTargetFilters.begin(); idx < m_vTargetFilters.end(); idx++ ){
if( (*idx)->getID() == id ) {
RetVal = (*idx);
break;
};
};
};
return RetVal;
};
void argusKernel::WaitFinish( bool Force ){
if( Force ){
#ifdef DEBUG
LOG( "Forced Exit" );
#endif
} else {
#ifdef DEBUG
LOG( "Start Waiting for Thread to End (usually at MAIN)." );
#endif
};
waitThreadEnd( Force );
};
typedef enum E_SYS_COMMAND_ENUMERATOR{
SYS_CMD_NONE = -1,
SYS_CMD_REBOOT = 0,
SYS_CMD_SET_STATIC,
P_ST_MAX_OPTICAL_ZOOM,
P_ST_PAN_REVERSE
}SYS_COMMAND_ENUMERATOR;
CSTR SYS_COMANDS_SCRIPTS[]={
"REBOOT",
"SET_STATIC",
"SET_DYNAMIC",
"SET_SSID",
"SET_AP",
"REFRESH_WIFI",
"CONNECT_2AP"
};
/* Main Kernel Thread Procedure */
void argusKernel::m_fThreadProc( void ){
char Buffer[CTEXT];
time_t tTimeTSeconds = 0;
int lastTSS = 0;
int lastTMS = 0;
DBC_EVT_RECORD * tEvtPtr;
uint32_t tLazyTimer = ARGUS_KERNEL_LAZY_SECONDS;
char pidBuf[16];
sprintf(pidBuf,"pid: %d tid: %d", getpid(), gettid() );
LOG( pidBuf );
#ifdef SIMULATE_KERNEL_TARGETS
LOG("SIMULATION ENABLED");
#endif
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ){
m_tTimeTSeconds = time( NULL );
// Process Once per Second
if( m_tTimeTSeconds != tTimeTSeconds ){
tTimeTSeconds = m_tTimeTSeconds;
struct sysinfo SI;
struct statvfs DI;
float cpu1 = 0.0f;
float cpu5 = 0.0f;
float cpu15 = 0.0f;
float mem = 0.0f;
float disk = 0.0f;
uint64_t tMEM = 0;
uint64_t tDISK = 0;
uint64_t cMEM = 0;
uint64_t cDISK = 0;
uint32_t cCORES = get_nprocs();
if( sysinfo( &SI ) == 0 ){
float f_load = 100.f / (float)( cCORES * ( 1 << SI_LOAD_SHIFT ) );
cpu1 = SI.loads[0] * f_load;
cpu5 = SI.loads[1] * f_load;
cpu15 = SI.loads[2] * f_load;
tMEM = SI.totalram;
cMEM = SI.totalram - SI.freeram;
mem = (float)cMEM / (float)tMEM;
} else {
LOG_ERROR("Error while getting System Info!");
};
//const uint32_t MB = 1 << 10;//(1024 * 1024);// * 1024;
if( statvfs("/", &DI) == 0 ){
tDISK = ( DI.f_blocks * (unsigned long long) DI.f_frsize ) >> 10;// / MB;
//cDISK = ( DI.f_bavail * (unsigned long long) DI.f_bsize ) >> 10;// / MB;
cDISK = tDISK - ( ( DI.f_bfree * (unsigned long long) DI.f_bsize ) >> 10 );
disk = (float)cDISK / (float)tDISK;
} else {
LOG_ERROR("Error while getting Disk Info!");
};
if( !m_pDBC->updateServerUtilisation( m_nServerID, cCORES, cpu1, cpu5, cpu15, mem, disk, tMEM, cMEM, tDISK, cDISK ) ) LOG_ERROR("Cannot update System Utilisation Stats!");
//Get Queued Commands
DBC_PUSHED_CMD *tCMD = m_pDBC->getNodePushedCMD( m_nServerNodeID );
//tCMD = m_pDBC->getActiveSiteCommand( m_nSiteID );
if( tCMD != NULL ){
// Mask as Started!
m_pDBC->updateNodePushedCMD( tCMD->id, 1 );
switch( tCMD->CMD ) {
case ARGUS_CMD_KRNL_RELOAD:{
LOG("Reload ARGUS SERVER!");
m_bThreadStatus = TH_ENDED;
m_bExitCause = 1;
break;
};
case ARGUS_CMD_KRNL_RESTART:{
LOG("Restart ARGUS SERVER!");
m_bThreadStatus = TH_ENDED;
m_bExitCause = 0;
break;
};
case ARGUS_CMD_NODES_RELOAD:{
if( m_pNodeFactory != NULL ) {
m_pNodeFactory->reloadNodes( m_nSiteID );
};
break;
};
case ARGUS_CMD_NODE_RELOAD:{
uint32_t tNodeID = atoi( tCMD->PARAM );
if( m_pNodeFactory != NULL ) {
m_pNodeFactory->reloadNode( tNodeID );
};
break;
};
case ARGUS_CMD_KRNL_PNP:{
if( m_pHardwareManager!= NULL ) {
LOG_ERROR( "Restart and Detect HardWare!" );
// Must be shutdowned all service that uses hardware prior to detection!
// m_pHardwareManager->enumerateHardware();
m_bThreadStatus = TH_ENDED;
m_bExitCause = 4; // Go -> Detect Hardware in BACKEND
};
break;
};
case ARGUS_CMD_KRNL_DELNODE:{
uint32_t tNodeID = atoi( tCMD->PARAM );
if (tNodeID == 0) break;
if( m_pNodeFactory == NULL) break;
// Turn Off Node
m_pNodeFactory->deleteNode( tNodeID );
break;
};
case ARGUS_CMD_KRNL_RESET_SITE:{
//Shutdown All Nodes
delete( m_pNodeFactory );
m_pNodeFactory = NULL;
//Shutdown All Modules
delete( m_pModuleFactory );
m_pModuleFactory = NULL;
DBC_INT_LIST *tList = m_pDBC->listNodes( m_nSiteID, true );
if ( tList ) {
for( int idx = 0; idx < tList->size(); idx++ ) destroyNode( tList->at( idx ) );
tList->clear();
delete( tList );
};
m_bThreadStatus = TH_ENDED;
m_bExitCause = 4; // Go -> Detect Hardware in BACKEND
break;
};
case ARGUS_CMD_KRNL_SYNC_TIME:{
uint32_t uts = atoi( tCMD->PARAM );
if( uts ){
time_t ts = (time_t)uts;
if( stime( &ts ) == 0 ){
// Restert Server;
m_bThreadStatus = TH_ENDED;
m_bExitCause = 0;
};
};
break;
};
case ARGUS_CMD_KRNL_SYSTEM_TASK:{
try{
Json::Value root;
JSONCPP_STRING err;
Json::CharReaderBuilder builder;
int len = strlen( tCMD->PARAM );
if ( len ) {
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
if (!reader->parse( tCMD->PARAM, tCMD->PARAM + len, &root, &err)) {
LOG_ERROR( "Error parsing the string" );
LOG_ERROR( err.c_str() );
} else {
if (root.size()) {
Json::Value tVal;
tVal = root["action"];
if (!tVal.isNull()) {
LOG( tVal.asString().c_str() );
//SYS_COMMAND_ENUMERATOR tENUM = SYS_CMD_NONE;
CSTR pTemp = NULL;
SYS_COMMAND_ENUMERATOR eType = SYS_CMD_NONE;
for( int i = 0; i < 4; i++ ){
pTemp = (CSTR) strstr( tVal.asString().c_str(), SYS_COMANDS_SCRIPTS[i] );
if( pTemp ){
eType = (SYS_COMMAND_ENUMERATOR)i;
break;
};
};
if( eType != SYS_CMD_NONE ){
switch( eType ){
case SYS_CMD_REBOOT: {
int rv = system("./scripts/linux/reboot_system.sh");
if( rv == -1 ) {
LOG_ERROR("Error issuing System Command!");
} else {
m_bThreadStatus = TH_ENDED;
m_bExitCause = 0;
};
break;
};
case SYS_CMD_SET_STATIC:{
tVal = root["nif_id"];
if (!tVal.isNull()) {
LOG( tVal.asString().c_str() );
};
break;
};
};
};
};
};
};
};
} catch (exception e) {
m_pDBC->updateNodePushedCMD( tCMD->id, 226 );
LOG_ERROR("EXCEPTION");
};
break;
};
};
free( tCMD );
};
// Validate Hardware
if( m_pHardwareManager!= NULL ) {
if( !m_pHardwareManager->validate() ){
LOG_ERROR( "Restart Because of HW!" );
m_bThreadStatus = TH_ENDED;
m_bExitCause = 0; // 0 to real exit from app
};
};
// Validate Modules
if( m_pModuleFactory != NULL ) {
m_pModuleFactory->validate();
};
// Validate Nodes
if( m_pNodeFactory != NULL ) {
m_pNodeFactory->validate();
};
// Archive Events;
if( tLazyTimer ){
tLazyTimer--;
} else {
tLazyTimer = ARGUS_KERNEL_LAZY_SECONDS;
//m_pDBC->lazyEventArchiver( ARGUS_KERNEL_LAZY_SECONDS );
};
};// ops loop
SLEEP( SLEEP_KERNEL_INTERVAL );
};
};
void argusKernel::destroyCamCapPicture( uint32_t PicID ){
m_pDBC->cleanEvents2PictureBinding( PicID );
DBC_CAP_DATA *tData = m_pDBC->getCamCapPictureData( PicID );
if ( tData ) {
char tBuff[1024];
char tB[MAX_PATH];
sprintf( tB, "%s/data/reports/%c%c/%c%c/%s.%s", getcwd(tBuff, 1024), tData->md5[0], tData->md5[1], tData->md5[2], tData->md5[3], tData->md5, tData->ext );
LOG( tB );
if( fileExist( tB ) ){
if( 0 != unlink( tB ) ) LOG_ERROR("Error while unlinking Picture!");
} else LOG_ERROR("Picture is missed!")
sprintf( tB, "%s/data/reports/%c%c/%c%c", tBuff, tData->md5[0], tData->md5[1], tData->md5[2], tData->md5[3] );
if( dirEmpty( tB ) ){
if( 0 != rmdir( tB ) ) LOG_ERROR("Can not remove report dir lvl 2 ");
} else LOG_ERROR("Dir(2) is not empty!")
sprintf( tB, "%s/data/reports/%c%c", tBuff, tData->md5[0], tData->md5[1] );
if( dirEmpty( tB ) ){
if( 0 != rmdir( tB ) ) LOG_ERROR("Can not remove report dir lvl 1 ");
} else LOG_ERROR("Dir(1) is not empty!")
free( tData );
m_pDBC->deleteCamCapPicture( PicID );
};
};
void argusKernel::destroyNode( uint32_t NodeID ){
DBC_NODE_DATA * tNData = m_pDBC->getNodeData( NodeID );
if( tNData == NULL ) return;
switch( tNData->type ) {
case ARGUS_SERVER:{
break;
};
case ARGUS_ALS_SENSOR:
case ARGUS_LFS_SENSOR:
case ARGUS_PLS_200_SENSOR:
case ARGUS_PLS_360_SENSOR:{
m_pDBC->deleteSensor( tNData->aux_id );
break;
}
case ARGUS_3D_SENSOR:
case ARGUS_NET_PLS_200:{
m_pDBC->deleteSensor( tNData->aux_id );
break;
};
case ARGUS_ANALOG_STATIC_CAMERA:
case ARGUS_ANALOG_PTZ_CAMERA:
case ARGUS_IP_STATIC_CAMERA:
case ARGUS_IP_PTZ_CAMERA:{
DBC_INT_LIST *sList = m_pDBC->listCamMediaStreams( tNData->aux_id );
if( sList != NULL ){
for( int zdx = 0; zdx < sList->size(); zdx++ ){
DBC_INT_LIST *pList = m_pDBC->listStreamCapPictures( sList->at( zdx ), 100 );
while( pList != NULL ){
if( pList->size() == 0 ) break;
for( int pxd = 0; pxd < pList->size(); pxd++ ) destroyCamCapPicture( pList->at( pxd ) );
delete( pList );
pList = m_pDBC->listStreamCapPictures( sList->at( zdx ), 100 );
};
};
delete( sList );
};
m_pDBC->deleteCamera( tNData->aux_id );
break;
};
case ARGUS_IP_UART_GATEWAY:{
break;
};
case ARGUS_JAMER:
case ARGUS_IP_VIDEO_SERVER:
case ARGUS_DRONE_CONTROL:
case ARGUS_CELLULAR_GATEWAY:
default:
break;
};
DBC_INT_LIST *tResList = m_pDBC->listResources( tNData->node_id );
if ( tResList ) {
for ( int rd = 0; rd < tResList->size(); rd++ ) destroyResource( tResList->at( rd ) );
tResList->clear();
delete( tResList );
};
m_pDBC->deleteConnections( tNData->node_id );
m_pDBC->deleteNodeEvents( tNData->node_id );
m_pDBC->deleteNode( tNData->node_id );
free( tNData );
};
void argusKernel::destroyResource( uint32_t ResID ){
DBC_RESOURCE_DATA *rData = m_pDBC->getResourceData( ResID );
if ( rData == NULL ) return;
switch( rData->type ) {
case ARGUS_HARDWARE_UART:{
m_pDBC->deleteUART( rData->aux_id );
break;
};
case ARGUS_HARDWARE_NIF_ETHERNET:{
};
case ARGUS_HARDWARE_NIF_WIFI:{
};
case ARGUS_HARDWARE_NIF_TUNEL:{
};
case ARGUS_HARDWARE_NIF_WAN:{
};
};
m_pDBC->deleteResource( rData->id );
free( rData );
};
/*
int argusKernel::isCameraListed( CSTR uid ){
if( m_vCamRecords.size() ){
for( int index = 0; index < m_vCamRecords.size(); index++ ){
if(strstr(m_vCamRecords.at(index)->uuid,uid)!=NULL){
m_vCamRecords.at(index)->online = true;
return index;
};
};
} else {
LOG("No Registered Cameras!");
};
return -1;
};
void argusKernel::validateCameras( void ){
vectorWoWoResults *DiscoverResults = m_pOnvifMediaObserver->getResults();
if( DiscoverResults->size() > 0 ) {
for (int index = 0; index < DiscoverResults->size(); index++) {
char tBuffer[256];
sprintf( tBuffer,"Found Camwera [%s] %s", DiscoverResults->at(index)->XAddrs, DiscoverResults->at(index)->RefID );
LOG( tBuffer );
uint32_t cid = m_pDBC->getCamId( DiscoverResults->at(index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID );
if( cid ) {
sprintf( tBuffer, "Camera is Listed as %d", cid );
LOG( tBuffer );
//if( strstr(DiscoverResults->at(index)->XAddrs,m_vCamRecords.at(cid)->ip)==NULL ) {
// LOG( DiscoverResults->at(index)->XAddrs );
m_pDBC->updateIPCam( m_nSiteID, cid, DiscoverResults->at(index)->XAddrs );// DiscoverResults->at(index));
//};
} else {
// Uncknown camera - no checking
LOG("Camera is Not Listed");
m_pDBC->addIPCam( m_nSiteID, DiscoverResults->at(index) );
};
};
} else {
LOG("No Online IP Cameras in Network");
};
};
void argusKernel::validateEvents( int &lastTSS, int &lastTMS ){
DBC_EVT_DATA *tPtr = NULL;
EVENT_CONTAINER *tEvt = NULL;
if(m_vEvtRecords.size()) {
lastTSS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_s;
lastTMS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_ms;
#ifndef ONE_EVENT_PER_LOOP
while( m_vEvtRecords.size() ){
#endif
tPtr = *m_vEvtRecords.begin();
if( tPtr != NULL ) {
if( tEvt != NULL ) {
m_pEventHeap->broadcast( tEvt );
};
free( tPtr );
};
m_vEvtRecords.erase( m_vEvtRecords.begin() );
#ifndef ONE_EVENT_PER_LOOP
};
#endif
};
};
*/
CSTR argusKernel::getServerIp( void ){
CSTR tVAL = NULL;
if( m_pNetClientsServer != NULL ){
tVAL = m_pNetClientsServer->getAddress();
};
return tVAL;
};
CSTR argusKernel::getServerName( void ){
CSTR tVAL = NULL;
//if( m_pNetClientsServer != NULL ){
// tVAL = m_pNetClientsServer->getAddress();
//};
return tVAL;
};
bool argusKernel::signalEvent( void ){
//if( m_pDBC->getLastEvents( m_vEvtRecords, 0,0 ) ){
//};
return true;
};
int argusKernel::getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){
RA = NULL;
int cnt = 0;
if( m_pNodeFactory != NULL ){
cnt = m_pNodeFactory->getNodesCount( type );
if( cnt ) {
RA = (argusNetNode **) calloc( cnt, sizeof( argusNetNode * ) );
m_pNodeFactory->fetchNodes(type, RA );
};
};
return cnt;
};
argusNetNode *argusKernel::getNetNode( int id ){
if( m_pNodeFactory != NULL ){
return m_pNodeFactory->getNode( id );
};
return NULL;
};
/*
int argusKernel::getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA ){
RA = NULL;
int cnt = 0;
if( m_pModuleFactory != NULL ){
cnt = m_pModuleFactory->getModulesCount( type );
if( cnt ) {
RA = (argusKernelModule **) calloc( cnt, sizeof( argusKernelModule * ) );
m_pModuleFactory->fetchModules( type, RA );
};
};
return cnt;
};
argusKernelModule *argusKernel::getModule( int id ){
if( m_pModuleFactory != NULL ){
return m_pModuleFactory->getModule( id );
};
return NULL;
};
*/
void argusKernel::dispatchEvent( EVENT_CONTAINER *Evt ){
// Register all events in Database;
//LOG( "New EVENT!!" );
if( m_pDBC == NULL ) return;
if( Evt == NULL ) return;
switch( Evt->m_eClass ) {
case EVT_CLASS_EXTERNAL_CMD:
switch( Evt->m_eType ){
case EVT_FH_JAMER_ON:{
uint32_t TS_A, TS_B;
TS_A = Evt->m_UMSTS / 1000;
TS_B = Evt->m_UMSTS % 1000;
#ifdef SIMULATE_KERNEL_TARGETS
m_bJamingTO = SIMULATE_JAMER_TO;
#endif
FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
if( tData ) {
if( m_pDBC->addEvent(
0,
Evt->m_UUID,
TS_A,
TS_B,
EVT_FH_JAMER_ON,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
tData->evtUUID
) ){
//Simulate FH Module Event;
EVENT_CONTAINER *ttt;
FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
if( nnn ){
nnn->location.lat = 0;
nnn->location.lon = 0;
nnn->location.alt = 0;
sprintf( nnn->missionID, tData->evtUUID );
ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_ON, NULL, NULL, nnn );
if( ttt ) {
m_pEventHeap->broadcast( ttt );
} else {
free( nnn );
};
};
};
free(tData);
};
break;
};
case EVT_FH_MISSION_END:{
FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
if( tData ) {
//DBC_EVT_DATA * tEVT = m_pDBC->getEventByUUID( tData->targetUUID );
if( 1 /*tEVT*/ ) {
uint32_t TS_A, TS_B;
TS_A = Evt->m_UMSTS / 1000;
TS_B = Evt->m_UMSTS % 1000;
if( m_pDBC->addEvent(
0,
Evt->m_UUID,
TS_A,
TS_B,
EVT_FH_LANDED ) ){
//Simulate FH Module Event;
EVENT_CONTAINER *ttt;
FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
if( nnn ){
nnn->location.lat = 0;
nnn->location.lon = 0;
nnn->location.alt = 0;
sprintf( nnn->missionID, tData->evtUUID );
ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_LANDED, NULL, NULL, nnn );
if( ttt ) {
m_pEventHeap->broadcast( ttt );
} else {
free( nnn );
};
};
};
//free( tEVT );
} else {
LOG_ERROR("Linked Event Was Not Found!");
};
};
break;
}
case EVT_FH_MISSION_BEGIN:{
FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
#ifdef SIMULATE_KERNEL_TARGETS
m_bLandingTO = SIMULATE_LANDING_TO;
#endif
if( tData ) {
#ifdef SIMULATE_KERNEL_TARGETS
sprintf( m_cCurrentMission, tData->evtUUID );
#endif
DBC_EVT_RECORD * tEVT = m_pDBC->getEventByUUID( tData->targetUUID );
if( tEVT ) {
uint32_t TS_A, TS_B;
TS_A = Evt->m_UMSTS / 1000;
TS_B = Evt->m_UMSTS % 1000;
if( Evt->m_db_id = m_pDBC->addEvent(
0,
Evt->m_UUID,
TS_A,
TS_B,
EVT_FH_FLY_TO,
0,
0,
0,
0,
0,
0,
tEVT->lat,
tEVT->lon,
tEVT->alt,
tEVT->id,
tEVT->uuid
) ){
//Simulate FH Module Event;
EVENT_CONTAINER * ttt;
FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
if( nnn ){
nnn->location.lat = tEVT->lat;
nnn->location.lon = tEVT->lon;
nnn->location.alt = tEVT->alt;
sprintf( nnn->missionID, tData->evtUUID );
ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_MISSION_BEGIN, NULL, NULL, nnn );
if( ttt ) {
m_pEventHeap->broadcast( ttt );
} else {
free( nnn );
};
};
};
free( tEVT );
} else {
LOG_ERROR("Linked Event Was Not Found!");
};
};
break;
};
};
break;
case EVT_CLASS_SENSOR_CLD:
case EVT_CLASS_SENSOR_LGS:
case EVT_CLASS_SENSOR_LFS:
case EVT_CLASS_SENSOR_MND:
case EVT_CLASS_SENSOR_PLS_210:
case EVT_CLASS_SENSOR_PLS_360:
case EVT_CLASS_SENSOR_ALS:
case EVT_CLASS_SENSOR_3D:
case EVT_CLASS_SENSOR_ACC:
switch( Evt->m_eType ) {
case EVT_TARGET_1D:{
TARGET_DATA *tDATA =(TARGET_DATA *) Evt->m_pEvtData;
if( tDATA != NULL ) {
uint32_t TS_A, TS_B;
TS_A = Evt->m_UMSTS / 1000;
TS_B = Evt->m_UMSTS % 1000;
Evt->m_db_id = m_pDBC->addEvent(
Evt->m_nSourceNodeID,
Evt->m_UUID,
TS_A,
TS_B,
Evt->m_eType,
0,
tDATA->digital,
0,
0,
tDATA->local_target.r,
tDATA->area,
tDATA->global_target.lat,
tDATA->global_target.lon,
tDATA->global_target.alt
);
};
break;
};
case EVT_ROI_ACTIVE:
case EVT_TARGET_2D_BLACK:
case EVT_TARGET_2D_WHITE:{
TARGET_DATA *tDATA = (TARGET_DATA *)Evt->m_pEvtData;
if( tDATA != NULL ) {
uint32_t TS_A, TS_B;
TS_A = Evt->m_UMSTS / 1000;
TS_B = Evt->m_UMSTS % 1000;
Evt->m_db_id = m_pDBC->addEvent(
Evt->m_nSourceNodeID,
Evt->m_UUID,
TS_A,
TS_B,
Evt->m_eType,
tDATA->lrf_id,
tDATA->digital,
tDATA->local_target.tetta,
tDATA->local_target.fi,
tDATA->local_target.r,
tDATA->area,
tDATA->global_target.lat,
tDATA->global_target.lon,
tDATA->global_target.alt
);
};
break;
};
case EVT_TARGET_3D_BLACK:
case EVT_TARGET_3D_WHITE:{
TARGET_DATA *tDATA = (TARGET_DATA *) Evt->m_pEvtData;
if( tDATA != NULL ) {
uint32_t TS_A, TS_B;
TS_A = Evt->m_UMSTS / 1000;
TS_B = Evt->m_UMSTS % 1000;
Evt->m_db_id = m_pDBC->addEvent(
Evt->m_nSourceNodeID,
Evt->m_UUID,
TS_A,
TS_B,
Evt->m_eType,
tDATA->lrf_id,
tDATA->digital,
tDATA->local_target.tetta,
tDATA->local_target.fi,
tDATA->local_target.r,
tDATA->area,
tDATA->global_target.lat,
tDATA->global_target.lon,
tDATA->global_target.alt
);
};
break;
};
case EVT_FLIP:{
uint32_t TS_A, TS_B;
TS_A = Evt->m_UMSTS / 1000;
TS_B = Evt->m_UMSTS % 1000;
Evt->m_db_id = m_pDBC->addEvent( Evt->m_nSourceNodeID, Evt->m_UUID, TS_A, TS_B, Evt->m_eType);
break;
};
};
break;
case EVT_CLASS_VIDEO:{
switch( Evt->m_eType ) {
case EVT_CAPTURE_START:{
break;
};
};
break;
};
};
};
#undef LOG
#undef LOG_ERROR