diff --git a/src/zm_event.cpp b/src/zm_event.cpp index fb774d6e7..459fb7f1c 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -227,8 +227,17 @@ void Event::AddCause( const std::string new_cause ) } } +void Event::Close() +{ + if ( ( tot_score == 0 ) && ( alarm_frames == 0 ) ) + { + Info( "Event is empty: Delete data" ); + DeleteData(); + } +} + // This is the transcription of JavaScript function DeleteEvent() -void Event::DeleteEvent() +void Event::DeleteData() { static char sql[ZM_SQL_MED_BUFSIZ]; diff --git a/src/zm_event.h b/src/zm_event.h index 2d9e107f3..ec31cae72 100644 --- a/src/zm_event.h +++ b/src/zm_event.h @@ -133,10 +133,11 @@ public: void AddFrames( int n_frames, Image **images, struct timeval **timestamps ); void AddFrame( Image *image, struct timeval timestamp, int score=0, Image *alarm_frame=NULL ); void AddCause( const std::string new_cause ); - void DeleteEvent(); + void Close(); private: void AddFramesInternal( int n_frames, int start_frame, Image **images, struct timeval **timestamps ); + void DeleteData(); public: static const char *getSubPath( struct tm *time ) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index b685ddf90..2646c917a 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -3117,10 +3117,15 @@ bool Monitor::closeEvent() { gettimeofday( &(event->EndTime()), NULL ); } + + // Inform all plugins that we are closing the event if ( config.load_plugins && ( purpose == ANALYSIS ) ) { ThePluginManager.getImageAnalyser().onCloseEvent( zones, event ); } + + event->Close(); + delete event; event = 0; return( true );