Browse Source

Changes for MER-1

AGP
Evgeny Gagua 3 years ago
parent
commit
3fced8da3d
  1. 4
      Projects/la_mojo/build
  2. 38
      lib/App/common/SQLite_dataBinder.cpp
  3. 14
      lib/App/common/SQLite_dataBinder.h
  4. 2
      lib/App/common/dataBinder.h
  5. 1580
      lib/App/common/dataBinder_structures.h
  6. 59
      lib/App/mojo/mojoBackend.cpp
  7. 45
      lib/App/mojo/mojoKernel.cpp
  8. 1
      lib/App/mojo/mojoKernel.h

4
Projects/la_mojo/build

@ -7,8 +7,8 @@
make clean -e "CFG=Debug86"
make -e "CFG=Debug86" -j4
make clean -e "CFG=Release86"
make -e "CFG=Release86" -j4
#make clean -e "CFG=Release86"
#make -e "CFG=Release86" -j4
#cd Release86
#strip ./mojo
#cd ..

38
lib/App/common/SQLite_dataBinder.cpp

@ -1669,6 +1669,36 @@ uint32_t sqliteDBC::getLastEventTS(){
return rv;
};
uint32_t sqliteDBC::getFirstEventTS(){
uint32_t rv = 0;
if( m_bRepIsConnected ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf( tQBuf, "SELECT `ts` FROM `events` ORDER BY `ts`, `ts_ms` LIMIT 1" );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDataReports->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
Assoc *cArr;
Assoc::iterator it;
cArr = result->at(0);
it = cArr->find("ts");
if( it != cArr->end() ){
rv = atoi( it->second.c_str() );
};
};
};
deleteResult( result );
};
return rv;
};
bool sqliteDBC::deleteReportDate( uint32_t ts ){
return false;
};
DBC_LRF_DATA *sqliteDBC::getLRFData( uint32_t ID ){
DBC_LRF_DATA * tVal = NULL;
if( m_bStoIsConnected ){
@ -2413,9 +2443,9 @@ DBC_SITE_DATA *sqliteDBC::getSiteData( uint32_t ID ){
if( it != cArr->end() ){
tVal->report_cleanup = atoi(it->second.c_str());
};
it = cArr->find("report_backup");
it = cArr->find("preserve_empty");
if( it != cArr->end() ){
tVal->report_backup = atoi(it->second.c_str());
tVal->preserve_empty = atoi(it->second.c_str());
};
};
};
@ -3578,7 +3608,9 @@ uint32_t sqliteDBC::getCamId( CSTR UUID ){
CSTR sqliteDBC::getDataParam( uint8_t pid ){
switch ( pid ) {
case 0: return strdup( m_pDbFile );
case 0: return strdup( m_pDbFile ); break;
case 1: return strdup( web_access_user ); break;
case 2: return strdup( web_access_group ); break;
};
return NULL;
};

14
lib/App/common/SQLite_dataBinder.h

@ -8,18 +8,6 @@
#include "../../alg/lgs/mask.h"
#include "../../components/base/basicEvent.h"
#define DB_SHMEM_POINT "/dev/shm/argus"
#ifndef STORAGE_DIR_MODE
#define STORAGE_DIR_MODE 0x1F5 //f disabled write by others
#endif
#ifndef STORAGE_FILE_MODE
#define STORAGE_FILE_MODE 0x1B4 //6
#endif
#define DB_FILE_MODE 0x1B4
#define SESSION_CONTINUE 0x00
#define SESSION_START 0x01
#define SESSION_END 0x02
@ -113,6 +101,8 @@ class sqliteDBC: public dataBinder {
virtual DBC_LRF_INI * getINIData( uint32_t lrfID );
virtual bool getEventSessionStatus( uint32_t nodeID );
virtual uint32_t getLastEventTS();
virtual uint32_t getFirstEventTS();
virtual bool deleteReportDate( uint32_t ts );
virtual DBC_LRF_DATA * getLRFData( uint32_t ID );
virtual uint8_t getLRFDataStatus( uint32_t ID );
virtual PLGS_2D_PARAMETERS getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master );

2
lib/App/common/dataBinder.h

@ -94,6 +94,8 @@ class dataBinder{
virtual DBC_LRF_INI * getINIData( uint32_t lrfID ){ return NULL; };
virtual bool getEventSessionStatus( uint32_t nodeID ){ return false; };
virtual uint32_t getLastEventTS(){ return 0; };
virtual uint32_t getFirstEventTS(){ return 0; };
virtual bool deleteReportDate( uint32_t ts ){ return false; };
virtual DBC_LRF_DATA * getLRFData( uint32_t ID ){ return NULL;};
virtual uint8_t getLRFDataStatus( uint32_t ID ){ return 0;};
virtual PLGS_2D_PARAMETERS getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){ return NULL;};

1580
lib/App/common/dataBinder_structures.h
File diff suppressed because it is too large
View File

59
lib/App/mojo/mojoBackend.cpp

@ -437,33 +437,50 @@ int main( int argc, char *argv[] ){
delete( Kernel );
LOG( "++++ Server Ended ++++" );
};
switch( ExitCode ){
case EXIT_CODE_RELOAD_SERVICES:{
delete( DBC );
#ifdef USE_MYSQL
DBC = mysqlDBC::getInstance( Settings );
#else
DBC = sqliteDBC::getInstance( Settings );
#endif
if( DBC ) {
if(!DBC->connect()) ExitCode = 0;
if( ExitCode == EXIT_CODE_FACTORY_RESET ){
CSTR tNAME = DBC->getDataParam( 0 );
CSTR tUSER = DBC->getDataParam( 1 );
CSTR tGROUP = DBC->getDataParam( 2 );
delete( DBC );
DBC = NULL;
if ( tNAME != NULL ) {
LOG("FACTORY RESET ISSUED!");
if( !fileExist( "data/factory.db" ) ){
LOG_ERROR( "++++ No Factory Backup ++++" );
} else {
if ( fileExist( tNAME ) ) {
LOG("Replace Working DB by Factory Clean one!");
unlink( tNAME );
} else ExitCode = 0;
break;
};
case EXIT_CODE_FACTORY_RESET:{
CSTR tNAME = DBC->getDataParam( 0 );
CSTR tUSER = DBC->getDataParam( 1 );
CSTR tGROUP = DBC->getDataParam( 2 );
delete( DBC );
DBC = NULL;
if ( tNAME != NULL ) {
LOG("FACTORY RESET ISSUED!");
if( !fileExist( "data/factory.db" ) ){
LOG_ERROR( "++++ No Factory Backup ++++" );
} else {
LOG("No Old DB! Just copy Factory Clean one!");
if ( fileExist( tNAME ) ) {
LOG("Replace Working DB by Factory Clean one!");
unlink( tNAME );
} else {
LOG("No Old DB! Just copy Factory Clean one!");
};
fileCopy( "data/factory.db", tNAME );
chown( tNAME, tUSER, tGROUP );
};
fileCopy( "data/factory.db", tNAME );
free( tNAME );
free( tUSER );
free( tGROUP );
} else {
LOG_ERROR( "++++ No DB File Assigned ++++" );
};
free( tNAME );
} else {
LOG_ERROR( "++++ No DB File Assigned ++++" );
ExitCode = 0;
break;
};
ExitCode = 0;
};
} while( ExitCode > 0 );
if ( DBC ){

45
lib/App/mojo/mojoKernel.cpp

@ -25,6 +25,12 @@
#include "../common/kernelEventFilterAPF.h"
#include "../common/kernelEventFilterTrain.h"
#ifdef USE_MYSQL
#include "../common/MySQL_dataBinder.h"
#else
#include "../common/SQLite_dataBinder.h"
#endif
#define LOG( X ) kernelPrototype::m_pLog->Log( "KRNL", this, X )
#ifdef DEBUG
@ -360,6 +366,31 @@ void mojoKernel::m_fThreadProc( void ){
setExitCause( EXIT_CODE_KERNEL_CLEAR );
break;
};
case CMD_KRNL_REPLACE_DATABASE:{
CSTR tNAME = m_pDBC->getDataParam( 0 );
CSTR tUSER = m_pDBC->getDataParam( 1 );
CSTR tGROUP = m_pDBC->getDataParam( 2 );
if ( tNAME ) {
char tB[256];
sprintf( tB,"./data/%s.db", tCMD->PARAM );
if ( fileExist( tB )) {
//Closing Database
delete( m_pDBC );
unlink( tNAME );
fileCopy( tB, tNAME );
chown( tNAME, tUSER, tGROUP );
unlink( tB );
m_bThreadStatus = TH_ENDED;
setExitCause( EXIT_CODE_RELOAD_SERVICES );
} else {
LOG_ERROR("New Database Does not Exists!");
};
free( tNAME );
free( tUSER );
free( tGROUP );
};
break;
};
case CMD_KRNL_SYNC_TIME:{
uint32_t uts = atoi( tCMD->PARAM );
if( uts ){
@ -921,20 +952,20 @@ bool mojoKernel::validateReports( void ){
DBC_SITE_DATA *tSiteData = m_pDBC->getSiteData( 1 );
if( tSiteData ) {
// Check if settings has been changed in DB
if ( tSiteData->report_cleanup != m_sSiteData.report_cleanup || tSiteData->report_backup != m_sSiteData.report_backup ) return false;
if ( tSiteData->report_cleanup != m_sSiteData.report_cleanup || tSiteData->preserve_empty != m_sSiteData.preserve_empty ) return false;
} else {
LOG_ERROR("Error Loading Site DATA!");
return false;
};
if ( m_sSiteData.report_cleanup ) {
if ( m_sSiteData.report_cleanup > m_sSiteData.report_backup ) {
if ( m_sSiteData.report_backup ) {
// Do needed backup
};
};
//if ( m_sSiteData.report_cleanup > m_sSiteData.report_backup ) {
// if ( m_sSiteData.preserve_empty ) {
// // Do needed backup
// };
//};
cleanUpReportDir( m_sSiteData.report_cleanup );
} else {
if ( m_sSiteData.report_backup ) {
if ( m_sSiteData.preserve_empty ) {
// Only Do Backup - No Cleanup
};
};

1
lib/App/mojo/mojoKernel.h

@ -93,6 +93,7 @@ class mojoKernel: public kernelPrototype{
bool createCronJob( uint8_t job, CSTR param_str = NULL, int param_int = 0 );
void cleanUpReportDir( uint32_t days );
void backupReports( uint32_t days );
protected:
virtual void m_fThreadProc( void );
// Constructor

Loading…
Cancel
Save