Browse Source

Fix of Midnight Session Problem, and also Fix for continuing to old report file(wrong date/folder) for report history

pull/7/head
Evgeny Gagua 3 months ago
parent
commit
572376dd4a
  1. 142
      lib/App/common/SQLite_dataBinder.cpp
  2. 2
      lib/App/common/SQLite_dataBinder.h
  3. 15
      lib/App/common/kernelModuleEmbedVideo.cpp
  4. 1
      lib/App/common/kernelModuleEmbedVideo.h
  5. 7
      lib/App/common/streamHandler.h
  6. 44
      lib/App/mojo/mojoKernel.cpp
  7. 2
      lib/App/mojo/mojoKernel.h

142
lib/App/common/SQLite_dataBinder.cpp

@ -91,7 +91,7 @@ sqliteDBC::sqliteDBC(config_setting_t * Settings) :
m_bMemIsConnected = false; m_bMemIsConnected = false;
m_bRepIsConnected = false; m_bRepIsConnected = false;
m_bStaIsConnected = false; m_bStaIsConnected = false;
m_bLastEventWasClosed = false;
//m_bLastEventWasClosed = false;
m_pDataStorage = NULL; m_pDataStorage = NULL;
m_pDataMemory = NULL; m_pDataMemory = NULL;
m_pDataReports = NULL; m_pDataReports = NULL;
@ -137,7 +137,8 @@ bool sqliteDBC::connect(void)
m_bMemIsConnected = false; m_bMemIsConnected = false;
m_bRepIsConnected = false; m_bRepIsConnected = false;
m_bStaIsConnected = false; m_bStaIsConnected = false;
m_bLastEventWasClosed = false;
//m_bLastEventWasClosed = false;
bool bLastEventWasClosed = true; // Workaround
// Apply New Config // Apply New Config
#ifdef DEBUG #ifdef DEBUG
@ -293,22 +294,17 @@ bool sqliteDBC::connect(void)
}; };
sprintf(m_pDbStat, "%s/stat.db", m_pDbReportBase); sprintf(m_pDbStat, "%s/stat.db", m_pDbReportBase);
m_pDataStatistics = new SQLite_Connector(); m_pDataStatistics = new SQLite_Connector();
if (m_pDataStatistics)
{
if (fileExist(m_pDbStat))
{
if (m_pDataStatistics){
if (fileExist(m_pDbStat)){
m_bStaIsCreated = false; m_bStaIsCreated = false;
if (m_pDataStatistics->Connect(m_pDbStat, 0, true))
{
if (m_pDataStatistics->Connect(m_pDbStat, 0, true)){
#ifdef DEBUG #ifdef DEBUG
LOG(m_pDbStat); LOG(m_pDbStat);
LOG("DB Statistics Opened"); LOG("DB Statistics Opened");
#endif #endif
m_pDataStatistics->SilentQuery("PRAGMA journal_mode=WAL"); m_pDataStatistics->SilentQuery("PRAGMA journal_mode=WAL");
m_bStaIsConnected = true; m_bStaIsConnected = true;
}
else
{
} else {
LOG_ERROR("Cannot Connect to DB Statistics"); LOG_ERROR("Cannot Connect to DB Statistics");
delete(m_pDataStorage); delete(m_pDataStorage);
delete(m_pDataMemory); delete(m_pDataMemory);
@ -320,12 +316,9 @@ bool sqliteDBC::connect(void)
m_pDataStatistics = NULL; m_pDataStatistics = NULL;
return false; return false;
}; };
}
else
{
} else {
m_bStaIsCreated = true; m_bStaIsCreated = true;
if (m_pDataStatistics->Connect(m_pDbStat, 0, true))
{
if (m_pDataStatistics->Connect(m_pDbStat, 0, true)){
#ifdef DEBUG #ifdef DEBUG
LOG("NEW DB Statistics Creating"); LOG("NEW DB Statistics Creating");
#endif #endif
@ -336,9 +329,7 @@ bool sqliteDBC::connect(void)
"CREATE TABLE IF NOT EXISTS \"days\" (\"year\" INTEGER,\"month\" INTEGER,\"day\" INTEGER,\"evt_count\" INTEGER DEFAULT 0,\"session_count\" INTEGER DEFAULT 0,\"videos_count\" INTEGER DEFAULT 0,\"session_closed\" INTEGER " "CREATE TABLE IF NOT EXISTS \"days\" (\"year\" INTEGER,\"month\" INTEGER,\"day\" INTEGER,\"evt_count\" INTEGER DEFAULT 0,\"session_count\" INTEGER DEFAULT 0,\"videos_count\" INTEGER DEFAULT 0,\"session_closed\" INTEGER "
"DEFAULT 0, CONSTRAINT \"date_uni\" UNIQUE(\"year\",\"month\",\"day\") );"); "DEFAULT 0, CONSTRAINT \"date_uni\" UNIQUE(\"year\",\"month\",\"day\") );");
m_bStaIsConnected = true; m_bStaIsConnected = true;
}
else
{
} else {
LOG_ERROR("Cannot Connect to DB Statistics"); LOG_ERROR("Cannot Connect to DB Statistics");
delete(m_pDataStorage); delete(m_pDataStorage);
delete(m_pDataMemory); delete(m_pDataMemory);
@ -352,42 +343,34 @@ bool sqliteDBC::connect(void)
}; };
}; };
}; };
m_pDataReports = new SQLite_Connector();
if (m_pDataReports)
{
m_pDataReports = new SQLite_Connector();
if (m_pDataReports){
/*
memset(&m_sPRepInfo, 0, sizeof(REPORT_DIRINFO)); memset(&m_sPRepInfo, 0, sizeof(REPORT_DIRINFO));
if (! m_bStaIsCreated)
{
if (! m_bStaIsCreated ){
#ifdef DEBUG #ifdef DEBUG
LOG("OLD Statistics PRESENT Report Created!"); LOG("OLD Statistics PRESENT Report Created!");
#endif #endif
AAssoc * result = m_pDataStatistics->Query("SELECT * FROM `days` ORDER BY `year` DESC, `month` DESC, `day` DESC LIMIT 1"); AAssoc * result = m_pDataStatistics->Query("SELECT * FROM `days` ORDER BY `year` DESC, `month` DESC, `day` DESC LIMIT 1");
if (result)
{
if (result->size() > 0)
{
if (result){
if (result->size() > 0){
Assoc * cArr; Assoc * cArr;
Assoc::iterator it; Assoc::iterator it;
cArr = result->at(0); cArr = result->at(0);
it = cArr->find("year"); it = cArr->find("year");
if (it != cArr->end())
{
if (it != cArr->end()){
strncpy(m_sPRepInfo.YEAR, it->second.c_str(), 4); strncpy(m_sPRepInfo.YEAR, it->second.c_str(), 4);
}; };
it = cArr->find("month"); it = cArr->find("month");
if (it != cArr->end())
{
if (it != cArr->end()){
sprintf(m_sPRepInfo.MONTH, "%02d", atoi(it->second.c_str())); sprintf(m_sPRepInfo.MONTH, "%02d", atoi(it->second.c_str()));
}; };
it = cArr->find("day"); it = cArr->find("day");
if (it != cArr->end())
{
if (it != cArr->end()){
sprintf(m_sPRepInfo.DAY, "%02d", atoi(it->second.c_str())); sprintf(m_sPRepInfo.DAY, "%02d", atoi(it->second.c_str()));
}; };
m_sPRepInfo.ts = getTsFromRDF(m_sPRepInfo); m_sPRepInfo.ts = getTsFromRDF(m_sPRepInfo);
}
else
{
} else {
#ifdef DEBUG #ifdef DEBUG
LOG("No Rows Fetched from STAT!"); LOG("No Rows Fetched from STAT!");
#endif #endif
@ -396,94 +379,71 @@ bool sqliteDBC::connect(void)
m_pDataMemory->deleteResult(result); m_pDataMemory->deleteResult(result);
}; };
if (m_sPRepInfo.ts != 0)
{
if( m_sPRepInfo.ts != 0 ){
#ifdef DEBUG #ifdef DEBUG
LOG("Have Old Reports!"); LOG("Have Old Reports!");
#endif #endif
if (checkRDFDir(m_pDbReportBase, m_sPRepInfo, false) == 0)
{
if (checkRDFDir(m_pDbReportBase, m_sPRepInfo, false) == 0){
LOG_ERROR("Error Connecting to Prev Report!"); LOG_ERROR("Error Connecting to Prev Report!");
m_bLastEventWasClosed = true;
}
else
{
bLastEventWasClosed = true;
} else {
#ifdef DEBUG #ifdef DEBUG
LOG("Connect to old Report Database"); LOG("Connect to old Report Database");
#endif #endif
sprintf(m_pDbReport, "%s/%s/%s/%s/report.db", m_pDbReportBase, m_sPRepInfo.YEAR, m_sPRepInfo.MONTH, m_sPRepInfo.DAY); sprintf(m_pDbReport, "%s/%s/%s/%s/report.db", m_pDbReportBase, m_sPRepInfo.YEAR, m_sPRepInfo.MONTH, m_sPRepInfo.DAY);
LOG(m_pDbReport); LOG(m_pDbReport);
if (fileExist(m_pDbReport))
{
if (fileExist(m_pDbReport)) {
SQLite_Connector * tDBC = new SQLite_Connector(); SQLite_Connector * tDBC = new SQLite_Connector();
if (tDBC)
{
if (tDBC->Connect(m_pDbReport, 0, true))
{
if (tDBC) {
if (tDBC->Connect(m_pDbReport, 0, true)){
char tQBuf[CTEXT]; char tQBuf[CTEXT];
AAssoc * result; AAssoc * result;
sprintf(tQBuf, "SELECT `evt_type` FROM `events` WHERE `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1", EVT_LRF_START_SESSION, EVT_LRF_END_SESSION_MA, EVT_LRF_END_SESSION_TO);
//sprintf(tQBuf, "SELECT `evt_type` FROM `events` WHERE `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1", EVT_LRF_START_SESSION, EVT_LRF_END_SESSION_MA, EVT_LRF_END_SESSION_TO);
sprintf( tQBuf, "SELECT `evt_type`, `ts`, `ts_ms` FROM `events` ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1" );
#ifdef DEBUG_ALL #ifdef DEBUG_ALL
LOG(tQBuf); LOG(tQBuf);
#endif #endif
result = tDBC->Query(tQBuf); result = tDBC->Query(tQBuf);
if (result != NULL)
{
if (result->size() > 0)
{
if (result != NULL){
if (result->size() > 0){
Assoc * cArr; Assoc * cArr;
Assoc::iterator it; Assoc::iterator it;
cArr = result->at(0); cArr = result->at(0);
it = cArr->find("evt_type"); it = cArr->find("evt_type");
if (it != cArr->end())
{
if (atoi(it->second.c_str()) != EVT_LRF_START_SESSION)
{
m_bLastEventWasClosed = true;
if (it != cArr->end()){
if (atoi(it->second.c_str()) != EVT_LRF_START_SESSION){
bLastEventWasClosed = true;
} }
}; };
}
else
{
m_bLastEventWasClosed = true;
}
} else {
bLastEventWasClosed = true;
};
}; };
deleteResult(result); deleteResult(result);
}
else
{
} else {
LOG_ERROR("Error Connecting to Prev Report!"); LOG_ERROR("Error Connecting to Prev Report!");
m_bLastEventWasClosed = true;
bLastEventWasClosed = true;
}; };
delete(tDBC); delete(tDBC);
}
else
{
} else {
LOG_ERROR("Error Create DB Connection Object!"); LOG_ERROR("Error Create DB Connection Object!");
m_bLastEventWasClosed = true;
bLastEventWasClosed = true;
}; };
}
else
{
} else {
LOG_ERROR("Error No Prev Report Database!"); LOG_ERROR("Error No Prev Report Database!");
m_bLastEventWasClosed = true;
bLastEventWasClosed = true;
}; };
}; };
}
else
{
m_bLastEventWasClosed = true;
} else {
bLastEventWasClosed = true;
}; };
if (m_bLastEventWasClosed)
{
*/
if( bLastEventWasClosed ){
#ifdef DEBUG #ifdef DEBUG
LOG("Last Session is Closed!"); LOG("Last Session is Closed!");
#endif #endif
fillRDF(time(NULL), m_sCRepInfo); fillRDF(time(NULL), m_sCRepInfo);
}
else
{
} else {
#ifdef DEBUG #ifdef DEBUG
LOG("Last Session is NOT Closed!"); LOG("Last Session is NOT Closed!");
#endif #endif
@ -492,8 +452,7 @@ bool sqliteDBC::connect(void)
#ifdef DEBUG #ifdef DEBUG
LOG(m_pDbReportBase); LOG(m_pDbReportBase);
#endif #endif
if (! checkRDFDir(m_pDbReportBase, m_sCRepInfo, true, getUserUid(web_access_user), getUserGid(web_access_group)))
{
if (! checkRDFDir(m_pDbReportBase, m_sCRepInfo, true, getUserUid(web_access_user), getUserGid(web_access_group))){
LOG_ERROR("Cannot Open Report!!"); LOG_ERROR("Cannot Open Report!!");
return false; return false;
}; };
@ -501,8 +460,7 @@ bool sqliteDBC::connect(void)
#ifdef DEBUG #ifdef DEBUG
LOG(m_pDbReport); LOG(m_pDbReport);
#endif #endif
if (m_pDataReports->Connect(m_pDbReport, 0, true))
{
if (m_pDataReports->Connect(m_pDbReport, 0, true)){
#ifdef DEBUG #ifdef DEBUG
LOG("Report File Opened"); LOG("Report File Opened");
#endif #endif

2
lib/App/common/SQLite_dataBinder.h

@ -32,7 +32,7 @@ class sqliteDBC : public dataBinder
bool m_bRepIsConnected; bool m_bRepIsConnected;
bool m_bStaIsConnected; bool m_bStaIsConnected;
bool m_bStaIsCreated; bool m_bStaIsCreated;
bool m_bLastEventWasClosed;
//bool m_bLastEventWasClosed;
bool m_bRecreateMemStructures; bool m_bRecreateMemStructures;
char m_pDbFile[CLOG]; char m_pDbFile[CLOG];

15
lib/App/common/kernelModuleEmbedVideo.cpp

@ -314,7 +314,20 @@ void signal_pipe_handler(int SIG)
basicLogCollection::getInstance()->Log("SIG_PIPE", NULL, _LOG_ERROR, "Sig Pipe Received Web Client Disconnected!"); basicLogCollection::getInstance()->Log("SIG_PIPE", NULL, _LOG_ERROR, "Sig Pipe Received Web Client Disconnected!");
#endif #endif
} }
bool kernelModuleEmbedVideo::isProcessingVideoStream(){
bool RV = false;
m_mStreamHandlersProtector.lock();
if (m_mapHANDLERS.size() ){
for (mapSTREAMHANDLERS::iterator idx = m_mapHANDLERS.begin(); idx != m_mapHANDLERS.end(); idx++){
if( (*idx).second->preservingCurrentRecording() ){
RV = true;
break;
};
};
};
m_mStreamHandlersProtector.unlock();
return RV;( m_mapHANDLERS.size() > 0 );
};
uint8_t kernelModuleEmbedVideo::getMediaMode(void) uint8_t kernelModuleEmbedVideo::getMediaMode(void)
{ {
return m_sEmbedVideoData.output_mode; return m_sEmbedVideoData.output_mode;

1
lib/App/common/kernelModuleEmbedVideo.h

@ -141,6 +141,7 @@ class kernelModuleEmbedVideo : public kernelModule
bool registerStream(uint32_t streamID, uint8_t flip_mode = 0); bool registerStream(uint32_t streamID, uint8_t flip_mode = 0);
bool unregisterStream(uint32_t streamID); bool unregisterStream(uint32_t streamID);
uint8_t getMediaMode(void); uint8_t getMediaMode(void);
bool isProcessingVideoStream();
friend class streamHandler; friend class streamHandler;
}; };
#else //LRF_PROXY_ONLY #else //LRF_PROXY_ONLY

7
lib/App/common/streamHandler.h

@ -365,6 +365,13 @@ class streamHandler :
bool triggerEvent(uint32_t eid, uint32_t & dbid, uint32_t & frame); bool triggerEvent(uint32_t eid, uint32_t & dbid, uint32_t & frame);
bool triggerCamMove(void); bool triggerCamMove(void);
bool validate(void); bool validate(void);
bool preservingCurrentRecording(){
#ifdef EVE_SEQUENTAL_OUTPUT
return !m_bSegDelete;
#else
return !( m_bSegADelete || m_bSegBDelete );
#endif
};
}; };
#endif // !LRF_PROXY_ONLY #endif // !LRF_PROXY_ONLY

44
lib/App/mojo/mojoKernel.cpp

@ -72,6 +72,8 @@ mojoKernel::mojoKernel(config_setting_t * ptr) :
m_bKeepLocalReport = true; m_bKeepLocalReport = true;
m_bMediaMode = 0; m_bMediaMode = 0;
m_bApplicationFirstRun = false; m_bApplicationFirstRun = false;
m_bForceCloseSessionOnEndOfTheDay = false;
m_mDateOfToday = getTimeValue() / 86400000; // round to a Day
m_pRPC = NULL; m_pRPC = NULL;
#ifndef LRF_PROXY_ONLY #ifndef LRF_PROXY_ONLY
m_pMediaHelper = NULL; m_pMediaHelper = NULL;
@ -810,6 +812,17 @@ void mojoKernel::m_fThreadProc(void)
#endif #endif
m_bDebugMode = m_pDBC->getAppDebugMode(); m_bDebugMode = m_pDBC->getAppDebugMode();
validateFilters(); 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(); validateSession();
validateReports(); validateReports();
//?? //??
@ -1316,7 +1329,25 @@ bool mojoKernel::dispatchEvent(EVENT_CONTAINER * Evt)
{ {
return false; return false;
} }
switch (Evt->m_eClass)
if( m_bForceCloseSessionOnEndOfTheDay && m_bSessionStarted ) {
#ifndef LRF_PROXY_ONLY
kernelModuleEmbedVideo * tMO = (kernelModuleEmbedVideo *) m_pModuleFactory->getModule(KERNEL_MODULE_EMBED_VIDEO);
if( tMO ){
if( !tMO->isProcessingVideoStream() ) {
stopSession();
m_bForceCloseSessionOnEndOfTheDay = false;
};
} else {
LOG_ERROR("No Embed Video Processing Module!");
};
#else
stopSession();
m_bForceCloseSessionOnEndOfTheDay = false;
#endif
}
switch (Evt->m_eClass)
{ {
case EVT_CLASS_SYSTEM: case EVT_CLASS_SYSTEM:
switch (Evt->m_eType) switch (Evt->m_eType)
@ -1902,11 +1933,14 @@ void mojoKernel::handleVideo(VIDEO_SEGMENT_INFO * ptr)
LOG("Video Scratch Deleted!"); LOG("Video Scratch Deleted!");
#endif #endif
}; };
}
else
{
} else {
LOG_ERROR("Video File is Missing!"); LOG_ERROR("Video File is Missing!");
}
};
//In case end of the day Force Session Close after Video File is saved
if ( m_bForceCloseSessionOnEndOfTheDay ) {
stopSession( m_bForceCloseSessionOnEndOfTheDay );
m_bForceCloseSessionOnEndOfTheDay = false;
};
} }
bool mojoKernel::validateReports(void) bool mojoKernel::validateReports(void)

2
lib/App/mojo/mojoKernel.h

@ -79,6 +79,8 @@ class mojoKernel : public kernelPrototype
kernelHelperMediaMTX * m_pMediaHelper; kernelHelperMediaMTX * m_pMediaHelper;
#endif #endif
basicMutex m_mSysInfoProtector; basicMutex m_mSysInfoProtector;
unsigned long long m_mDateOfToday;
bool m_bForceCloseSessionOnEndOfTheDay;
bool m_bDebugMode; bool m_bDebugMode;
bool m_bKeepLocalReport; bool m_bKeepLocalReport;
bool m_bWorkWithRemoteServer; bool m_bWorkWithRemoteServer;

Loading…
Cancel
Save