From 2227d9c85230346e1c42959c46acd16cbba55916 Mon Sep 17 00:00:00 2001 From: Emmanuel Papin Date: Thu, 15 Jan 2015 16:51:46 +0100 Subject: [PATCH] Add new fuctions for plugins --- src/zm_detector.cpp | 14 ++++++++++++++ src/zm_detector.h | 8 ++++++++ src/zm_image_analyser.cpp | 18 ++++++++++++++++++ src/zm_image_analyser.h | 3 +++ src/zm_monitor.cpp | 5 ++++- 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/zm_detector.cpp b/src/zm_detector.cpp index fca106ec1..3cc343bf3 100644 --- a/src/zm_detector.cpp +++ b/src/zm_detector.cpp @@ -230,3 +230,17 @@ bool Detector::Detect(const Image &zmImage, Zone** zones, Event::StringSet &zone return alarm; } + + +void Detector::_onCreateEvent(const Image &zmImage, Zone** zones) +{ + for(std::vector::iterator it = m_vnPluginZones.begin(); it != m_vnPluginZones.end(); ++it) + onCreateEvent(zones[*it], *it, const Image *zmImage); +} + + +void Detector::_onCloseEvent(const Image &zmImage, Zone** zones) +{ + for(std::vector::iterator it = m_vnPluginZones.begin(); it != m_vnPluginZones.end(); ++it) + onCloseEvent(zones[*it], *it, const Image *zmImage); +} diff --git a/src/zm_detector.h b/src/zm_detector.h index 9850bda6d..727bcb84f 100644 --- a/src/zm_detector.h +++ b/src/zm_detector.h @@ -78,6 +78,10 @@ public: //! Detect (in an image later) bool Detect(const Image &image, Zone** zones, Event::StringSet &zoneSet, unsigned int &score); + + void _onCreateEvent(const Image &zmImage, Zone** zones); + void _onCloseEvent(const Image &zmImage, Zone** zones); + //! Load detector's parameters. virtual int loadConfig(string sConfigFileName, map > mapPluginConf) = 0; @@ -98,6 +102,10 @@ protected: //! Do detection inside one given zone. virtual bool checkZone(Zone *zone, unsigned int n_zone, const Image *zmImage) = 0; + + virtual void onCreateEvent(Zone *zone, unsigned int n_zone, const Image *zmImage) = 0; + virtual void onCloseEvent(Zone *zone, unsigned int n_zone, const Image *zmImage) = 0; + //! Log messages to the SYSLOG. void log(int, string sLevel, string sMessage); diff --git a/src/zm_image_analyser.cpp b/src/zm_image_analyser.cpp index 20e02fda6..0fa4f95de 100644 --- a/src/zm_image_analyser.cpp +++ b/src/zm_image_analyser.cpp @@ -41,7 +41,25 @@ ImageAnalyser::~ImageAnalyser() delete *It; } +void ImageAnalyser::onCreateEvent(const Image &comp_image, Zone** zones, Event* event) +{ + for ( DetectorsList::iterator It = m_Detectors.begin(); + It != m_Detectors.end(); + ++It ) + { + (*It)->_onCreateEvent(const comp_image, zones, event); + } +} +void ImageAnalyser::onCloseEvent(const Image &comp_image, Zone** zones, Event* event) +{ + for ( DetectorsList::iterator It = m_Detectors.begin(); + It != m_Detectors.end(); + ++It ) + { + (*It)->_onCloseEvent(const comp_image, zones, event); + } } +} /*!\fn ImageAnalyser::DoDetection(const Image &comp_image, Zone** zones, Event::StringSetMap noteSetMap, string& det_cause) * \param comp_image is the image to analyse diff --git a/src/zm_image_analyser.h b/src/zm_image_analyser.h index eb516653f..9b5060d48 100644 --- a/src/zm_image_analyser.h +++ b/src/zm_image_analyser.h @@ -75,6 +75,9 @@ class ImageAnalyser { m_Detectors.push_back(Det.release()); } + void onCreateEvent(const Image &comp_image, Zone** zones); + void onCloseEvent(const Image &comp_image, Zone** zones); + //! Do detection in an image by calling all available detectors. bool DoDetection(const Image &comp_image, Zone** zones, Event::StringSetMap& noteSetMap, std::string& det_cause, unsigned int& score); diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 9793decff..fc6bb3e15 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -1520,7 +1520,10 @@ bool Monitor::Analyse() // Create event event = new Event( this, *timestamp, "Continuous", noteSetMap ); shared_data->last_event = event->Id(); - +#if ZM_PLUGINS_ON + if (config.load_plugins) + ThePluginManager.getImageAnalyser().onCreateEvent( *snap_image, zones, event ); +#endif // ZM_PLUGINS_ON Info( "%s: %03d - Opening new event %d, section start", name, image_count, event->Id() ); /* To prevent cancelling out an existing alert\prealarm\alarm state */