@ -73,7 +73,7 @@ mojoKernel::mojoKernel(config_setting_t * ptr) :
m_bMediaMode = 0 ;
m_bApplicationFirstRun = false ;
m_bForceCloseSessionOnEndOfTheDay = false ;
m_mDateOfToday = getTimeValue ( ) / 86400000 ; // round to a Day
m_mDateOfToday = getLocalDay ( ) ;
m_pRPC = NULL ;
# ifndef LRF_PROXY_ONLY
m_pMediaHelper = NULL ;
@ -547,37 +547,26 @@ void mojoKernel::stopSession(bool forced)
m_mSessionProtector . unlock ( ) ;
}
void mojoKernel : : validateSession ( )
{
void mojoKernel : : validateSession ( ) {
m_mSessionProtector . lock ( ) ;
if ( m_bSessionStarted )
{
if ( m_nNoAlarmCounter < NOTARGET_SESSION_CLOSE )
{
if ( m_bSessionStarted ) {
if ( m_nNoAlarmCounter < NOTARGET_SESSION_CLOSE ) {
m_nNoAlarmCounter + + ;
}
else
{
} else {
m_mSessionProtector . unlock ( ) ;
stopSession ( false ) ;
stopSession ( m_bForceCloseSessionOnEndOfTheDay ) ;
m_mSessionProtector . lock ( ) ;
} ;
# ifdef EMBED_AUTORESET
if ( m_bEnableAutoReset )
{
if ( m_nSessionCounter < m_nAutoResetTime )
{
if ( m_bEnableAutoReset ) {
if ( m_nSessionCounter < m_nAutoResetTime ) {
m_nSessionCounter + + ;
}
else
{
} else {
m_nSessionCounter = 0 ;
// Reset All Sensors
DBC_INT_LIST * tL = m_pDBC - > listNodes ( false ) ;
if ( tL )
{
for ( DBC_INT_LIST : : iterator idx = tL - > begin ( ) ; idx < tL - > end ( ) ; idx + + )
{
if ( tL ) {
for ( DBC_INT_LIST : : iterator idx = tL - > begin ( ) ; idx < tL - > end ( ) ; idx + + ) {
m_pDBC - > pushMemCMD ( * idx , 1 , " 'A' " ) ;
} ;
delete ( tL ) ;
@ -598,10 +587,8 @@ void mojoKernel::validateSession()
LOG ( " Pereodic Reset to All Sensors " ) ;
# endif
DBC_INT_LIST * tL = m_pDBC - > listNodes ( false ) ;
if ( tL )
{
for ( DBC_INT_LIST : : iterator idx = tL - > begin ( ) ; idx < tL - > end ( ) ; idx + + )
{
if ( tL ) {
for ( DBC_INT_LIST : : iterator idx = tL - > begin ( ) ; idx < tL - > end ( ) ; idx + + ) {
m_pDBC - > pushMemCMD ( * idx , 1 , " 'A' " ) ;
} ;
delete ( tL ) ;
@ -777,23 +764,17 @@ void mojoKernel::getSystemUtilization(DBC_SYS_LOAD_INFO * ptr)
m_mSysInfoProtector . unlock ( ) ;
}
void mojoKernel : : m_fThreadProc ( void )
{
void mojoKernel : : m_fThreadProc ( void ) {
time_t tTimeTSeconds = 0 ;
m_bThreadStatus = TH_WORKING ;
pthread_setname_np ( pthread_self ( ) , " Kernel " ) ;
while ( m_bThreadStatus < TH_ENDED )
{
while ( m_bThreadStatus < TH_ENDED ) {
m_tTimeTSeconds = time ( NULL ) ;
// Each Second
if ( m_tTimeTSeconds ! = tTimeTSeconds )
{
if ( m_tTimeTSeconds ! = tTimeTSeconds ) {
tTimeTSeconds = m_tTimeTSeconds ;
if ( m_bApplicationFirstRun )
{
if ( m_pHardwareManager ! = NULL )
{
if ( m_bApplicationFirstRun ) {
if ( m_pHardwareManager ! = NULL ) {
LOG_ERROR ( " Restart and Detect HardWare! " ) ;
// Must be shutdowned all service that uses hardware prior to detection!
m_bThreadStatus = TH_ENDED ;
@ -802,8 +783,7 @@ void mojoKernel::m_fThreadProc(void)
} ;
} ;
# ifdef LINUX_KERNEL_WATCHDOG
if ( m_iWatchdogFd > - 1 )
{
if ( m_iWatchdogFd > - 1 ) {
char tB [ 64 ] ;
sprintf ( tB , " 4000 \n " ) ;
// ToDo: Make Error Handling here!
@ -812,22 +792,10 @@ void mojoKernel::m_fThreadProc(void)
# endif
m_bDebugMode = m_pDBC - > getAppDebugMode ( ) ;
validateFilters ( ) ;
if ( ! m_bForceCloseSessionOnEndOfTheDay ) {
unsigned long long tD = getTimeValue ( ) / 86400000 ;
if ( m_mDateOfToday ! = tD ) {
//New Day Started
if ( ! m_bSessionStarted ) {
m_mDateOfToday = tD ;
} else {
m_bForceCloseSessionOnEndOfTheDay = true ;
} ;
} ;
} ;
validateSession ( ) ;
validateReports ( ) ;
//??
if ( ! m_pHardwareManager - > validate ( ) )
{
if ( ! m_pHardwareManager - > validate ( ) ) {
LOG ( " Reload Mojo Node Due to Memory Consumption! " ) ;
m_bThreadStatus = TH_ENDED ;
setExitCause ( EXIT_CODE_KERNEL_CLEAR ) ;
@ -842,83 +810,63 @@ void mojoKernel::m_fThreadProc(void)
m_pMediaHelper - > validateService ( ) ;
} ;
# endif
if ( m_sSiteData . use_remote_server )
{
if ( m_pRPC )
{
if ( m_sSiteData . use_remote_server ) {
if ( m_pRPC ) {
m_pRPC - > validate ( ) ;
m_bWorkWithRemoteServer = ( m_pRPC - > getConnectionStatus ( ) = = CS_CONNECTED ) ;
}
else
{
} else {
// Checking if Nodes are Loadded
if ( m_pNodeFactory - > nodesAreLoaded ( ) )
{
if ( m_pNodeFactory - > nodesAreLoaded ( ) ) {
# ifdef DEBUG
LOG ( " Initial Connect to Remote Server " ) ;
# endif
if ( ( m_pRPC = new mojoRemoteClient ( this ) ) )
{
if ( ! ( m_bWorkWithRemoteServer = m_pRPC - > create ( ) ) )
{
if ( ( m_pRPC = new mojoRemoteClient ( this ) ) ) {
if ( ! ( m_bWorkWithRemoteServer = m_pRPC - > create ( ) ) ) {
LOG_ERROR ( " Cannot Connect to Remote Server! " ) ;
}
}
else
{
} else {
m_bWorkWithRemoteServer = false ;
}
} ;
} ;
} ;
DBC_PUSHED_CMD * tCMD = m_pDBC - > getNodePushedCMD ( m_nServerNodeID ) ; // Kernel
if ( tCMD ! = NULL )
{
if ( tCMD ! = NULL ) {
m_pDBC - > updateNodePushedCMD ( tCMD - > id , DBC_CMD_STARTED ) ;
switch ( tCMD - > CMD )
{
case CMD_KRNL_RELOAD :
{
switch ( tCMD - > CMD ) {
case CMD_KRNL_RELOAD : {
LOG ( " Reload Mojo Node! " ) ;
m_bThreadStatus = TH_ENDED ;
setExitCause ( EXIT_CODE_RELOAD_SERVICES ) ;
break ;
} ;
case CMD_KRNL_RESTART :
{
case CMD_KRNL_RESTART : {
LOG ( " Restart Mojo Node! " ) ;
m_bThreadStatus = TH_ENDED ;
setExitCause ( EXIT_CODE_KERNEL_CLEAR ) ;
break ;
} ;
case CMD_KRNL_FACTORY_RESET :
{
case CMD_KRNL_FACTORY_RESET : {
LOG ( " Restart Mojo -> Factory Reset! " ) ;
m_bThreadStatus = TH_ENDED ;
setExitCause ( EXIT_CODE_FACTORY_RESET ) ;
break ;
} ;
case CMD_NODES_RELOAD :
{
if ( m_pNodeFactory ! = NULL )
{
case CMD_NODES_RELOAD : {
if ( m_pNodeFactory ! = NULL ) {
m_pNodeFactory - > reloadNodes ( ) ;
} ;
break ;
} ;
case CMD_NODE_RELOAD :
{
case CMD_NODE_RELOAD : {
uint32_t tNodeID = atoi ( tCMD - > PARAM ) ;
if ( m_pNodeFactory ! = NULL )
{
if ( m_pNodeFactory ! = NULL ) {
m_pNodeFactory - > reloadNode ( tNodeID ) ;
} ;
break ;
} ;
case CMD_KRNL_PNP :
{
if ( m_pHardwareManager ! = NULL )
{
case 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_bThreadStatus = TH_ENDED ;
@ -926,8 +874,7 @@ void mojoKernel::m_fThreadProc(void)
} ;
break ;
} ;
case CMD_KRNL_UPDATE_IDENT :
{
case CMD_KRNL_UPDATE_IDENT : {
LOG ( " Restart Mojo -> Update Ident! " ) ;
sprintf ( m_sIdentity , tCMD - > PARAM ) ;
config_setting_remove ( m_pSettings , MOJO_KERNEL_TAG_SERVER_IDENTITY ) ;
@ -941,18 +888,15 @@ void mojoKernel::m_fThreadProc(void)
setExitCause ( EXIT_CODE_KERNEL_CLEAR ) ;
break ;
} ;
case CMD_KRNL_REPLACE_DATABASE :
{
case CMD_KRNL_REPLACE_DATABASE : {
LOG ( " Restart Mojo -> Replace Database! " ) ;
CSTR tNAME = m_pDBC - > getDataParam ( 0 ) ;
CSTR tUSER = m_pDBC - > getDataParam ( 1 ) ;
CSTR tGROUP = m_pDBC - > getDataParam ( 2 ) ;
if ( tNAME )
{
if ( tNAME ) {
char tB [ 512 ] ;
sprintf ( tB , " ./data/%s.db " , tCMD - > PARAM ) ;
if ( fileExist ( tB ) )
{
if ( fileExist ( tB ) ) {
LOG ( " Restart Mojo -> Close Database! " ) ;
// Closing Database
delete ( m_pDBC ) ;
@ -969,9 +913,7 @@ void mojoKernel::m_fThreadProc(void)
LOG ( " Restart Mojo -> Exit! " ) ;
setExitCause ( EXIT_CODE_NO_DATABASE ) ; // EXIT_CODE_RELOAD_SERVICES );
m_bThreadStatus = TH_ENDED ;
}
else
{
} else {
LOG_ERROR ( " New Database Does not Exists! " ) ;
} ;
// free( tNAME );
@ -980,15 +922,12 @@ void mojoKernel::m_fThreadProc(void)
} ;
break ;
} ;
case CMD_KRNL_SYNC_TIME :
{
case CMD_KRNL_SYNC_TIME : {
uint32_t uts = atoi ( tCMD - > PARAM ) ;
if ( uts )
{
if ( uts ) {
# if (__GLIBC__ < 3) && (__GLIBC_MINOR__ < 31)
time_t ts = ( time_t ) uts ;
if ( stime ( & ts ) = = 0 )
{
if ( stime ( & ts ) = = 0 ) {
// Restert Server;
m_bThreadStatus = TH_ENDED ;
setExitCause ( EXIT_CODE_KERNEL_CLEAR ) ;
@ -997,8 +936,7 @@ void mojoKernel::m_fThreadProc(void)
timespec ts ;
ts . tv_sec = ( time_t ) uts ;
ts . tv_nsec = 0 ;
if ( clock_settime ( CLOCK_REALTIME , & ts ) = = 0 )
{
if ( clock_settime ( CLOCK_REALTIME , & ts ) = = 0 ) {
// Restert Server;
m_bThreadStatus = TH_ENDED ;
setExitCause ( EXIT_CODE_KERNEL_CLEAR ) ;
@ -1007,41 +945,33 @@ void mojoKernel::m_fThreadProc(void)
} ;
break ;
} ;
case CMD_KRNL_SYSTEM_TASK :
{
case CMD_KRNL_SYSTEM_TASK : {
break ;
} ;
case NODE_FORCE_FINISH_ALARM :
{
case NODE_FORCE_FINISH_ALARM : {
stopSession ( ) ;
break ;
} ;
case CMD_FORCE_FREEZE_BUBBLES :
{
case CMD_FORCE_FREEZE_BUBBLES : {
LOG ( " Freeze Bubbles NCQ " ) ;
EVENT_CONTAINER * tTT = createBasicEvent ( m_nServerNodeID , EVT_CLASS_SYSTEM , EVT_FLT_BUBBLES_BLOCK ) ;
if ( tTT )
{
if ( tTT ) {
m_pEventHeap - > broadcast ( tTT ) ;
} ;
break ;
} ;
case CMD_FORCE_POP_BUBBLE :
{
case CMD_FORCE_POP_BUBBLE : {
LOG ( " POP Bubbles NCQ " ) ;
EVENT_CONTAINER * tTT = createBasicEvent ( m_nServerNodeID , EVT_CLASS_SYSTEM , EVT_FLT_BUBBLES_DEL_FB ) ;
if ( tTT )
{
if ( tTT ) {
m_pEventHeap - > broadcast ( tTT ) ;
} ;
break ;
} ;
case CMD_FORCE_RELOAD_BUBBLES :
{
case CMD_FORCE_RELOAD_BUBBLES : {
LOG ( " Reload Bubbles NCQ " ) ;
EVENT_CONTAINER * tTT = createBasicEvent ( m_nServerNodeID , EVT_CLASS_SYSTEM , EVT_FLT_BUBBLES_RELOAD ) ;
if ( tTT )
{
if ( tTT ) {
m_pEventHeap - > broadcast ( tTT ) ;
} ;
break ;
@ -1081,8 +1011,7 @@ void mojoKernel::m_fThreadProc(void)
} ;
free ( tCMD ) ;
} ;
if ( m_pDBC )
{
if ( m_pDBC ) {
m_pDBC - > cleanNodePushedCMD ( ) ;
}
} ;
@ -1943,41 +1872,43 @@ void mojoKernel::handleVideo(VIDEO_SEGMENT_INFO * ptr)
} ;
}
bool mojoKernel : : validateReports ( void )
{
bool mojoKernel : : validateReports ( void ) {
/// @todo Stephane needs to follow this function...
if ( m_bKeepLocalReport )
{
if ( m_bKeepLocalReport ) {
if ( ! m_bForceCloseSessionOnEndOfTheDay ) {
uint8_t cd = getLocalDay ( ) ;
if ( m_mDateOfToday ! = cd ) {
//New Day Started
m_mDateOfToday = cd ;
if ( m_bSessionStarted ) {
m_bForceCloseSessionOnEndOfTheDay = true ;
} ;
} ;
} ;
DBC_SITE_DATA * tSiteData = m_pDBC - > getSiteData ( 1 ) ;
if ( tSiteData )
{
if ( tSiteData ) {
// Check if settings has been changed in DB
if ( tSiteData - > report_cleanup ! = m_sSiteData . report_cleanup | | tSiteData - > preserve_empty ! = m_sSiteData . preserve_empty )
{
if ( tSiteData - > report_cleanup ! = m_sSiteData . report_cleanup | | tSiteData - > preserve_empty ! = m_sSiteData . preserve_empty ) {
memcpy ( & m_sSiteData , tSiteData , sizeof ( DBC_SITE_DATA ) ) ;
} ;
free ( tSiteData ) ;
}
else
{
} else {
LOG_ERROR ( " Error Loading Site DATA! " ) ;
return false ;
} ;
if ( m_sSiteData . report_cleanup )
{
if ( m_sSiteData . report_cleanup ) {
cleanUpReportDir ( m_sSiteData . report_cleanup ) ;
} ;
if ( m_sSiteData . preserve_empty )
{
if ( m_sSiteData . preserve_empty ) {
float tT = 100.0f * ( 1.0f - ( 1.0f / ( ( float ) m_sSiteData . preserve_empty ) ) ) ;
# ifdef DEBUG_EXTRA
char tB [ 128 ] ;
sprintf ( tB , " Check Disk Size: %0.3f %0.3f %d [%d] " , m_sSysInfo . disk , tT , m_sSiteData . preserve_empty ) ;
LOG ( tB ) ;
# endif
if ( m_sSysInfo . disk > tT )
{
if ( m_sSysInfo . disk > tT ) {
# ifdef DEBUG_EXTRA
LOG ( " Delete Some Reports! " ) ;
# endif
@ -1985,7 +1916,7 @@ bool mojoKernel::validateReports(void)
m_pDBC - > deleteReportDate ( m_pDBC - > getFirstEventTS ( ) ) ;
} ;
} ;
}
} ;
return true ;
}