Do not use 'using namespace' in header files and raise an error if engine versions mismatch
This commit is contained in:
parent
2acfe5b395
commit
6574a128de
|
@ -5,6 +5,7 @@
|
|||
cmake_minimum_required (VERSION 2.6)
|
||||
project (zoneminder)
|
||||
set(zoneminder_VERSION "1.28.1")
|
||||
set(ZM_ENGINE_VERSION 28)
|
||||
|
||||
# CMake does not allow out-of-source build if CMakeCache.exists
|
||||
# in the source folder. Abort and notify the user
|
||||
|
@ -137,7 +138,6 @@ if(ZM_PLUGIN_SUPPORT)
|
|||
set(ZM_PLUGINSWEBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/zoneminder/plugins" CACHE PATH
|
||||
"Location of the plugin files, default: <prefix>/${CMAKE_INSTALL_DATADIR}/zoneminder/plugins")
|
||||
set(ZM_PROJECTNAME ${CMAKE_PROJECT_NAME})
|
||||
set(ZM_VERSION ${zoneminder_VERSION})
|
||||
set(ZM_PLUGINSEXT ".so" CACHE STRING
|
||||
"Plugin extension, default: .so")
|
||||
add_definitions(-DDEFAULT_PLUGIN_EXT=\"${ZM_PLUGIN_EXT}\")
|
||||
|
|
|
@ -9,6 +9,9 @@ AC_CONFIG_SRCDIR(src/zm.h)
|
|||
AC_CONFIG_HEADERS(config.h)
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
ZM_ENGINE_VERSION=28
|
||||
AC_SUBST(ZM_ENGINE_VERSION)
|
||||
|
||||
AC_SUBST([AM_CXXFLAGS], [-D__STDC_CONSTANT_MACROS])
|
||||
|
||||
AC_SUBST(VERSION)
|
||||
|
@ -256,8 +259,6 @@ if test "$ENABLE_PLUGIN_SUPPORT" == "yes"; then
|
|||
AC_SUBST(ZM_PLUGINSWEBDIR)
|
||||
ZM_PROJECTNAME="${PACKAGE}"
|
||||
AC_SUBST(ZM_PROJECTNAME)
|
||||
ZM_VERSION="${PACKAGE_VERSION}"
|
||||
AC_SUBST(ZM_VERSION)
|
||||
ZM_PLUGINSEXT=".so"
|
||||
AC_SUBST(ZM_PLUGINSEXT)
|
||||
AC_DEFINE_UNQUOTED(DEFAULT_PLUGIN_EXT,"${ZM_PLUGINSEXT}",[File extension to detect plugins])
|
||||
|
|
|
@ -8,7 +8,7 @@ webdir = @ZM_PLUGINSWEBDIR@
|
|||
|
||||
Name: @ZM_PROJECTNAME@
|
||||
Description: ZoneMinder convenience library for plugin development.
|
||||
Version: @ZM_VERSION@
|
||||
Version: @VERSION@
|
||||
Requires:
|
||||
Requires.private:
|
||||
Conflicts:
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#define ZM_CONFIG "@ZM_CONFIG@" // Path to config file
|
||||
#define ZM_VERSION "@VERSION@" // ZoneMinder Version
|
||||
#define ZM_ENGINE_VERSION @ZM_ENGINE_VERSION@ // ZoneMinder engine Version
|
||||
|
||||
#define ZM_HAS_V4L1 @ZM_HAS_V4L1@
|
||||
#define ZM_HAS_V4L2 @ZM_HAS_V4L2@
|
||||
|
|
|
@ -44,7 +44,7 @@ Detector& Detector::operator=(const Detector& source)
|
|||
/*!\fn Detector::getDetectionCause()
|
||||
* return detection cause as string
|
||||
*/
|
||||
string Detector::getDetectionCause()
|
||||
std::string Detector::getDetectionCause()
|
||||
{
|
||||
return m_sDetectionCause;
|
||||
}
|
||||
|
@ -53,16 +53,16 @@ string Detector::getDetectionCause()
|
|||
/*!\fn Detector::getConfigSectionName()
|
||||
* return plugin name as string
|
||||
*/
|
||||
string Detector::getPluginName()
|
||||
std::string Detector::getPluginName()
|
||||
{
|
||||
return m_sConfigSectionName;
|
||||
}
|
||||
|
||||
|
||||
/*!\fn Detector::EnablePlugin(vector<int> zoneList)
|
||||
/*!\fn Detector::EnablePlugin(std::vector<int> zoneList)
|
||||
* \param vnZoneList is the list of enabled zones for the plugin
|
||||
*/
|
||||
void Detector::EnablePlugin(vector<unsigned int> vnZoneList)
|
||||
void Detector::EnablePlugin(std::vector<unsigned int> vnZoneList)
|
||||
{
|
||||
m_vnPluginZones = vnZoneList;
|
||||
m_bIsPluginEnabled = true;
|
||||
|
@ -72,17 +72,17 @@ void Detector::EnablePlugin(vector<unsigned int> vnZoneList)
|
|||
/*!\fn Detector::getPluginZones()
|
||||
* \return the list of zone which have the plugin enabled
|
||||
*/
|
||||
vector<unsigned int> Detector::getPluginZones()
|
||||
std::vector<unsigned int> Detector::getPluginZones()
|
||||
{
|
||||
return m_vnPluginZones;
|
||||
}
|
||||
|
||||
|
||||
/*! \fn Detector::log(int nLogLevel, string sLevel, string sMessage)
|
||||
/*! \fn Detector::log(int nLogLevel, std::string sLevel, std::string sMessage)
|
||||
*/
|
||||
void Detector::log(int nLogLevel, string sLevel, string sMessage)
|
||||
void Detector::log(int nLogLevel, std::string sLevel, std::string sMessage)
|
||||
{
|
||||
string sMessageToLog = sLevel + string(" [") + m_sLogPrefix + string(": ") + sMessage + string("]");
|
||||
std::string sMessageToLog = sLevel + std::string(" [") + m_sLogPrefix + std::string(": ") + sMessage + std::string("]");
|
||||
syslog(nLogLevel, "%s", sMessageToLog.c_str());
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ void Detector::_onCloseEvent(Zone** zones, Event* event)
|
|||
{
|
||||
for(std::vector<unsigned int>::iterator it = m_vnPluginZones.begin(); it != m_vnPluginZones.end(); ++it)
|
||||
{
|
||||
string noteText = " [Zone ";
|
||||
std::string noteText = " [Zone ";
|
||||
noteText += zones[*it]->Label();
|
||||
noteText += "]\n";
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#define LOG_LEVEL LOG_NOTICE
|
||||
#define DEFAULT_CONFIGFILE_SECTION "libzm_vscvl_plugin"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
//! Base class for object detectors, defined in plugins.
|
||||
|
@ -46,17 +45,17 @@ public:
|
|||
}
|
||||
|
||||
//! Constructor with section name parameter.
|
||||
Detector(string sPluginFileName)
|
||||
Detector(std::string sPluginFileName)
|
||||
{
|
||||
m_sLogPrefix = DEFAULT_LOG_PREFIX;
|
||||
|
||||
char* szPluginFileName = strdup(sPluginFileName.c_str());
|
||||
|
||||
string sPluginFileNameName = string(basename(szPluginFileName));
|
||||
std::string sPluginFileNameName = std::string(basename(szPluginFileName));
|
||||
|
||||
size_t idx = sPluginFileNameName.rfind('.');
|
||||
|
||||
if (idx == string::npos)
|
||||
if (idx == std::string::npos)
|
||||
m_sConfigSectionName = sPluginFileNameName;
|
||||
else
|
||||
m_sConfigSectionName = sPluginFileNameName.substr(0, idx);
|
||||
|
@ -82,19 +81,19 @@ public:
|
|||
void _onCloseEvent(Zone** zones, Event *event);
|
||||
|
||||
//! Load detector's parameters.
|
||||
virtual int loadConfig(string sConfigFileName, map<unsigned int,map<string,string> > mapPluginConf) = 0;
|
||||
virtual int loadConfig(std::string sConfigFileName, std::map<unsigned int,std::map<std::string,std::string> > mapPluginConf) = 0;
|
||||
|
||||
//! Returns detection case string.
|
||||
string getDetectionCause();
|
||||
std::string getDetectionCause();
|
||||
|
||||
//! Returns plugin name as string.
|
||||
string getPluginName();
|
||||
std::string getPluginName();
|
||||
|
||||
//! Enable the plugin for the given zones.
|
||||
void EnablePlugin(vector<unsigned int> zoneList);
|
||||
void EnablePlugin(std::vector<unsigned int> zoneList);
|
||||
|
||||
//! Return the list of enabled zones
|
||||
vector<unsigned int> getPluginZones();
|
||||
std::vector<unsigned int> getPluginZones();
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -102,13 +101,13 @@ protected:
|
|||
virtual bool checkZone(Zone *zone, unsigned int n_zone, const Image *zmImage) = 0;
|
||||
|
||||
virtual void onCreateEvent(Zone *zone, unsigned int n_zone, Event *event) = 0;
|
||||
virtual void onCloseEvent(Zone *zone, unsigned int n_zone, Event *event, string ¬eText) = 0;
|
||||
virtual void onCloseEvent(Zone *zone, unsigned int n_zone, Event *event, std::string ¬eText) = 0;
|
||||
|
||||
//! Log messages to the SYSLOG.
|
||||
void log(int, string sLevel, string sMessage);
|
||||
void log(int, std::string sLevel, std::string sMessage);
|
||||
|
||||
//! String to be shown as detection cause for event.
|
||||
string m_sDetectionCause;
|
||||
std::string m_sDetectionCause;
|
||||
|
||||
//! Minimum score value to consider frame as to be alarmed.
|
||||
double m_fMinAlarmScore;
|
||||
|
@ -126,13 +125,13 @@ protected:
|
|||
int m_nNewHeight;
|
||||
|
||||
//! String prefix for SYSLOG messages.
|
||||
string m_sLogPrefix;
|
||||
std::string m_sLogPrefix;
|
||||
|
||||
//! Name of config file section to search parameters.
|
||||
string m_sConfigSectionName;
|
||||
std::string m_sConfigSectionName;
|
||||
|
||||
//! List of zones enabled for the plugin
|
||||
vector<unsigned int> m_vnPluginZones;
|
||||
std::vector<unsigned int> m_vnPluginZones;
|
||||
|
||||
//! Plugin status regarding zone settings
|
||||
bool m_bIsPluginEnabled;
|
||||
|
|
|
@ -61,14 +61,14 @@ void ImageAnalyser::onCloseEvent(Zone** zones, Event* event)
|
|||
}
|
||||
}
|
||||
|
||||
/*!\fn ImageAnalyser::DoDetection(const Image &comp_image, Zone** zones, Event::StringSetMap noteSetMap, string& det_cause)
|
||||
/*!\fn ImageAnalyser::DoDetection(const Image &comp_image, Zone** zones, Event::StringSetMap noteSetMap, std::string& det_cause, unsigned int& score)
|
||||
* \param comp_image is the image to analyse
|
||||
* \param zones is the zones array to analyse
|
||||
* \param noteSetMap is the map of events descriptions
|
||||
* \param det_cause is a string describing detection cause
|
||||
* \param score is the plugin score
|
||||
*/
|
||||
bool ImageAnalyser::DoDetection(const Image &comp_image, Zone** zones, Event::StringSetMap& noteSetMap, string& det_cause, unsigned int& score)
|
||||
bool ImageAnalyser::DoDetection(const Image &comp_image, Zone** zones, Event::StringSetMap& noteSetMap, std::string& det_cause, unsigned int& score)
|
||||
{
|
||||
Event::StringSet zoneSet;
|
||||
score = 0;
|
||||
|
@ -98,25 +98,25 @@ bool ImageAnalyser::DoDetection(const Image &comp_image, Zone** zones, Event::St
|
|||
|
||||
|
||||
|
||||
/*!\fn ImageAnalyser::configurePlugins(string sConfigFileName)
|
||||
/*!\fn ImageAnalyser::configurePlugins(std::string sConfigFileName, bool bDoNativeDet)
|
||||
*\param sConfigFileName is the path to the configuration file, where parameters for all plugins are given.
|
||||
* \param bDoNativeDet is true if native detection will be performed
|
||||
*/
|
||||
void ImageAnalyser::configurePlugins(string sConfigFileName, bool bDoNativeDet)
|
||||
void ImageAnalyser::configurePlugins(std::string sConfigFileName, bool bDoNativeDet)
|
||||
{
|
||||
string sLoadedPlugins;
|
||||
std::string sLoadedPlugins;
|
||||
if ( !m_bIsAnalyserEnabled ) return;
|
||||
m_bIsNativeDetEnabled = bDoNativeDet;
|
||||
for ( DetectorsList::iterator It = m_Detectors.begin(); It != m_Detectors.end(); ++It )
|
||||
{
|
||||
string sPluginName = (*It)->getPluginName();
|
||||
std::string sPluginName = (*It)->getPluginName();
|
||||
try
|
||||
{
|
||||
if ( isValidConfigFile( sPluginName, sConfigFileName ) )
|
||||
{
|
||||
Info("Configure plugin '%s' with config file '%s'.", sPluginName.c_str(), sConfigFileName.c_str());
|
||||
map<unsigned int,map<string,string> > mapPluginConf;
|
||||
vector<unsigned int> vnPluginZones;
|
||||
std::map<unsigned int,std::map<std::string,std::string> > mapPluginConf;
|
||||
std::vector<unsigned int> vnPluginZones;
|
||||
bool plugEnabled = getEnabledZonesForPlugin( sPluginName, vnPluginZones );
|
||||
if ( getPluginConfig( sPluginName, vnPluginZones, mapPluginConf )
|
||||
&& (*It)->loadConfig( sConfigFileName, mapPluginConf ) )
|
||||
|
@ -142,15 +142,15 @@ void ImageAnalyser::configurePlugins(string sConfigFileName, bool bDoNativeDet)
|
|||
|
||||
|
||||
|
||||
/*!\fn ImageAnalyser::isValidConfigFile(string sPluginName, string sConfigFileName)
|
||||
/*!\fn ImageAnalyser::isValidConfigFile(std::string sPluginName, std::string sConfigFileName)
|
||||
* \param sPluginName is the name of the plugin (filename without extension)
|
||||
* \param sConfigFileName is the path to the configuration file which should include configuration directives for the plugin
|
||||
* \return true if the config file contains the right section name
|
||||
*/
|
||||
bool ImageAnalyser::isValidConfigFile(string sPluginName, string sConfigFileName)
|
||||
bool ImageAnalyser::isValidConfigFile(std::string sPluginName, std::string sConfigFileName)
|
||||
{
|
||||
ifstream ifs(sConfigFileName.c_str());
|
||||
string line;
|
||||
std::ifstream ifs(sConfigFileName.c_str());
|
||||
std::string line;
|
||||
bool rtnVal = false;
|
||||
while (getline(ifs, line))
|
||||
{
|
||||
|
@ -199,8 +199,8 @@ bool ImageAnalyser::getMonitorZones()
|
|||
}
|
||||
zSetting zone;
|
||||
zone.id = (unsigned int)strtoul(dbrow[0], NULL, 0);
|
||||
zone.name = string(dbrow[1]);
|
||||
zone.type = string(dbrow[2]);
|
||||
zone.name = std::string(dbrow[1]);
|
||||
zone.type = std::string(dbrow[2]);
|
||||
m_vMonitorZones.push_back(zone);
|
||||
}
|
||||
}
|
||||
|
@ -211,13 +211,13 @@ bool ImageAnalyser::getMonitorZones()
|
|||
|
||||
|
||||
|
||||
/*!\fn ImageAnalyser::getPluginConfig(string sPluginName, map<unsigned int,map<string,string> >& mapPluginConf)
|
||||
/*!\fn ImageAnalyser::getPluginConfig(std::string sPluginName, std::vector<unsigned int> vnPluginZones, std::map<unsigned int,std::map<std::string,std::string> >& mapPluginConf)
|
||||
* \param sPluginName is the name of the plugin (filename without extension)
|
||||
* \param vnPluginZones is a vector containing the index of zones enabled for the plugin (not the zone Id in the database)
|
||||
* \param mapPluginConf is the map filled with configuration parameters for the plugin
|
||||
* \return true if all found parameters are applied to the map
|
||||
*/
|
||||
bool ImageAnalyser::getPluginConfig(string sPluginName, vector<unsigned int> vnPluginZones, map<unsigned int,map<string,string> >& mapPluginConf)
|
||||
bool ImageAnalyser::getPluginConfig(std::string sPluginName, std::vector<unsigned int> vnPluginZones, std::map<unsigned int,std::map<std::string,std::string> >& mapPluginConf)
|
||||
{
|
||||
static char sql[ZM_SQL_MED_BUFSIZ];
|
||||
|
||||
|
@ -242,7 +242,7 @@ bool ImageAnalyser::getPluginConfig(string sPluginName, vector<unsigned int> vnP
|
|||
|
||||
if (nParamNum > 0)
|
||||
{
|
||||
vector<MYSQL_ROW> vRows;
|
||||
std::vector<MYSQL_ROW> vRows;
|
||||
for (unsigned int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++)
|
||||
{
|
||||
if (mysql_errno(&dbconn))
|
||||
|
@ -257,14 +257,14 @@ bool ImageAnalyser::getPluginConfig(string sPluginName, vector<unsigned int> vnP
|
|||
for (size_t i = 0; i < m_vMonitorZones.size(); i++)
|
||||
{
|
||||
// Iterate over the configuration parameters
|
||||
for (vector<MYSQL_ROW>::iterator it = vRows.begin(); it != vRows.end(); it++)
|
||||
for (std::vector<MYSQL_ROW>::iterator it = vRows.begin(); it != vRows.end(); it++)
|
||||
{
|
||||
// Add the parameter to the map if the zone id is found
|
||||
if ( (unsigned int)strtoul((*it)[0], NULL, 0) == m_vMonitorZones[i].id )
|
||||
{
|
||||
nParamCnt++;
|
||||
string name((*it)[1]);
|
||||
string value((*it)[2]);
|
||||
std::string name((*it)[1]);
|
||||
std::string value((*it)[2]);
|
||||
if((name == "Enabled") && (value == "Yes")) {
|
||||
mapRegPluginZoneConf[sPluginName][m_vMonitorZones[i].id].Enabled = true;
|
||||
} else if((name == "RequireNatDet") && (value == "Yes")) {
|
||||
|
@ -293,16 +293,16 @@ bool ImageAnalyser::getPluginConfig(string sPluginName, vector<unsigned int> vnP
|
|||
|
||||
|
||||
|
||||
/*!\fn ImageAnalyser::getEnabledZonesForPlugin(string sPluginName, vector<unsigned int>& vnPluginZones)
|
||||
/*!\fn ImageAnalyser::getEnabledZonesForPlugin(std::string sPluginName, std::vector<unsigned int>& vnPluginZones)
|
||||
* \param sPluginName is the name of the plugin (filename without extension)
|
||||
* \param vnPluginZones is the vector list filled with zones enabled for this plugin
|
||||
* \return true if at least one active or exclusive zone exist
|
||||
*/
|
||||
bool ImageAnalyser::getEnabledZonesForPlugin(string sPluginName, vector<unsigned int>& vnPluginZones)
|
||||
bool ImageAnalyser::getEnabledZonesForPlugin(std::string sPluginName, std::vector<unsigned int>& vnPluginZones)
|
||||
{
|
||||
static char sql[ZM_SQL_MED_BUFSIZ];
|
||||
bool bPluginEnabled = false;
|
||||
string sZones;
|
||||
std::string sZones;
|
||||
|
||||
// Get the sorted list of zones ids which have the plugin enabled
|
||||
snprintf(sql, sizeof(sql), "SELECT `ZoneId` FROM `PluginsConfig` WHERE `MonitorId`=%d AND `pluginName`='%s' AND `Name`='Enabled' AND `Value`='yes' ORDER BY `ZoneId` ASC;", m_nMonitorId, sPluginName.c_str());
|
||||
|
@ -322,7 +322,7 @@ bool ImageAnalyser::getEnabledZonesForPlugin(string sPluginName, vector<unsigned
|
|||
|
||||
if (mysql_num_rows(result) > 0)
|
||||
{
|
||||
vector<unsigned int> vnEnabledZoneIds;
|
||||
std::vector<unsigned int> vnEnabledZoneIds;
|
||||
for (unsigned int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++)
|
||||
{
|
||||
if (mysql_errno(&dbconn))
|
||||
|
@ -341,7 +341,7 @@ bool ImageAnalyser::getEnabledZonesForPlugin(string sPluginName, vector<unsigned
|
|||
{
|
||||
// Add the index to the vector if the zone id is found
|
||||
vnPluginZones.push_back(i);
|
||||
string sZoneType = m_vMonitorZones[i].type;
|
||||
std::string sZoneType = m_vMonitorZones[i].type;
|
||||
if ((sZoneType == "Active") || (sZoneType == "Exclusive"))
|
||||
bPluginEnabled = true;
|
||||
if ( sZones.length() )
|
||||
|
@ -364,10 +364,10 @@ bool ImageAnalyser::getEnabledZonesForPlugin(string sPluginName, vector<unsigned
|
|||
}
|
||||
|
||||
|
||||
/*!\fn ImageAnalyser::getZonesConfig()
|
||||
/*!\fn ImageAnalyser::getZonesConfig(std::string sLoadedPlugins)
|
||||
* \param sLoadedPlugins is the formatted list of loaded plugins
|
||||
*/
|
||||
bool ImageAnalyser::getZonesConfig(string sLoadedPlugins)
|
||||
bool ImageAnalyser::getZonesConfig(std::string sLoadedPlugins)
|
||||
{
|
||||
static char sql[ZM_SQL_MED_BUFSIZ];
|
||||
|
||||
|
@ -388,7 +388,7 @@ bool ImageAnalyser::getZonesConfig(string sLoadedPlugins)
|
|||
}
|
||||
if (mysql_num_rows(result) > 0)
|
||||
{
|
||||
vector<zIdName> vSettings;
|
||||
std::vector<zIdName> vSettings;
|
||||
for (unsigned int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++)
|
||||
{
|
||||
if (mysql_errno(&dbconn))
|
||||
|
@ -407,7 +407,7 @@ bool ImageAnalyser::getZonesConfig(string sLoadedPlugins)
|
|||
for (size_t i = 0; i != m_vMonitorZones.size(); i++)
|
||||
{
|
||||
zConf zoneConf;
|
||||
for (vector<zIdName>::iterator it = vSettings.begin(); it != vSettings.end(); it++)
|
||||
for (std::vector<zIdName>::iterator it = vSettings.begin(); it != vSettings.end(); it++)
|
||||
{
|
||||
if (it->zoneId == m_vMonitorZones[i].id)
|
||||
{
|
||||
|
@ -442,14 +442,14 @@ bool ImageAnalyser::getZoneConfig(unsigned int nZone, zConf& zoneConf)
|
|||
}
|
||||
|
||||
|
||||
/*!\fn ImageAnalyser::getRegPluginGenConf(string sPluginName, pGenConf& regPluginGenConf)
|
||||
/*!\fn ImageAnalyser::getRegPluginGenConf(std::string sPluginName, pGenConf& regPluginGenConf)
|
||||
* \param sPluginName is the name of the plugin (filename without extension)
|
||||
* \param regPluginGenConf is a structure filled with the general settings of the plugin
|
||||
* \return false if no setting is found
|
||||
*/
|
||||
bool ImageAnalyser::getRegPluginGenConf(string sPluginName, pGenConf& regPluginGenConf)
|
||||
bool ImageAnalyser::getRegPluginGenConf(std::string sPluginName, pGenConf& regPluginGenConf)
|
||||
{
|
||||
map<string,pGenConf>::iterator it = mapRegPluginGenConf.find( sPluginName );
|
||||
std::map<std::string,pGenConf>::iterator it = mapRegPluginGenConf.find( sPluginName );
|
||||
if ( it == mapRegPluginGenConf.end() )
|
||||
return false;
|
||||
regPluginGenConf = it->second;
|
||||
|
@ -457,13 +457,13 @@ bool ImageAnalyser::getRegPluginGenConf(string sPluginName, pGenConf& regPluginG
|
|||
}
|
||||
|
||||
|
||||
/*!\fn ImageAnalyser::getRegPluginZoneConf(string sPluginName, PluginZoneConf& regPluginZoneConf)
|
||||
/*!\fn ImageAnalyser::getRegPluginZoneConf(std::string sPluginName, PluginZoneConf& regPluginZoneConf)
|
||||
* \param sPluginName is the name of the plugin (filename without extension)
|
||||
* \param regPluginZoneConf is a map filled with the zone settings of the plugin
|
||||
*/
|
||||
void ImageAnalyser::getRegPluginZoneConf(string sPluginName, PluginZoneConf& regPluginZoneConf)
|
||||
void ImageAnalyser::getRegPluginZoneConf(std::string sPluginName, PluginZoneConf& regPluginZoneConf)
|
||||
{
|
||||
map<string,PluginZoneConf>::iterator it = mapRegPluginZoneConf.find( sPluginName );
|
||||
std::map<std::string,PluginZoneConf>::iterator it = mapRegPluginZoneConf.find( sPluginName );
|
||||
|
||||
if ( it != mapRegPluginZoneConf.end() )
|
||||
regPluginZoneConf = it->second;
|
||||
|
@ -481,8 +481,8 @@ void ImageAnalyser::getRegPluginZoneConf(string sPluginName, PluginZoneConf& reg
|
|||
void ImageAnalyser::cleanupPlugins()
|
||||
{
|
||||
|
||||
string sPluginsToKeep;
|
||||
string sRequest;
|
||||
std::string sPluginsToKeep;
|
||||
std::string sRequest;
|
||||
static char sql[ZM_SQL_MED_BUFSIZ];
|
||||
|
||||
for ( DetectorsList::iterator It = m_Detectors.begin(); It != m_Detectors.end(); ++It )
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "zm_event.h"
|
||||
#include "zm_db.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
//! List of available detectors.
|
||||
typedef std::list<Detector *> DetectorsList;
|
||||
|
@ -75,31 +75,31 @@ class ImageAnalyser {
|
|||
bool DoDetection(const Image &comp_image, Zone** zones, Event::StringSetMap& noteSetMap, std::string& det_cause, unsigned int& score);
|
||||
|
||||
//! Configure all loaded plugins using given configuration file.
|
||||
void configurePlugins(string sConfigFileName, bool bDoNativeDet = 0);
|
||||
void configurePlugins(std::string sConfigFileName, bool bDoNativeDet = 0);
|
||||
|
||||
//! Check if the configuration file contains the right section name
|
||||
bool isValidConfigFile(string sPluginName, string sConfigFileName);
|
||||
bool isValidConfigFile(std::string sPluginName, std::string sConfigFileName);
|
||||
|
||||
//! Get index of enabled zones for this monitor (same ordering as in Monitor::Load)
|
||||
bool getMonitorZones();
|
||||
|
||||
//! Get plugin configuration from database
|
||||
bool getPluginConfig(string sPluginName, vector<unsigned int> vnPluginZones, map<unsigned int,map<string,string> >& mapPluginConf);
|
||||
bool getPluginConfig(std::string sPluginName, std::vector<unsigned int> vnPluginZones, std::map<unsigned int,std::map<std::string,std::string> >& mapPluginConf);
|
||||
|
||||
//! Get enabled zones for the plugin
|
||||
bool getEnabledZonesForPlugin(string sPluginName, vector<unsigned int>& vnPluginZones);
|
||||
bool getEnabledZonesForPlugin(std::string sPluginName, std::vector<unsigned int>& vnPluginZones);
|
||||
|
||||
//! Get zones configuration from database
|
||||
bool getZonesConfig(string sLoadedPlugins);
|
||||
bool getZonesConfig(std::string sLoadedPlugins);
|
||||
|
||||
//! Get Zone configuration from this class
|
||||
bool getZoneConfig(unsigned int nZone, zConf& zoneConf);
|
||||
|
||||
//! Get the general settings of a registered plugin
|
||||
bool getRegPluginGenConf(string sPluginName, pGenConf& regPluginGenConf);
|
||||
bool getRegPluginGenConf(std::string sPluginName, pGenConf& regPluginGenConf);
|
||||
|
||||
//! Get the zone settings of a registered plugin
|
||||
void getRegPluginZoneConf(string sPluginName, PluginZoneConf& regPluginZoneConf);
|
||||
void getRegPluginZoneConf(std::string sPluginName, PluginZoneConf& regPluginZoneConf);
|
||||
|
||||
//! Remove from db plugins no longer detected
|
||||
void cleanupPlugins();
|
||||
|
@ -121,27 +121,27 @@ class ImageAnalyser {
|
|||
//! A structure to store a plugin parameter
|
||||
struct zIdName {
|
||||
unsigned int zoneId;
|
||||
string name;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
//! A vector filled with parameters of zones
|
||||
vector<zConf> m_vZonesConfig;
|
||||
std::vector<zConf> m_vZonesConfig;
|
||||
|
||||
//! A structure to store basic settings of a zone
|
||||
struct zSetting {
|
||||
unsigned int id;
|
||||
string name;
|
||||
string type;
|
||||
std::string name;
|
||||
std::string type;
|
||||
};
|
||||
|
||||
//! A vector filled with settings of zones enabled for the monitor
|
||||
vector<zSetting> m_vMonitorZones;
|
||||
std::vector<zSetting> m_vMonitorZones;
|
||||
|
||||
//! A map to store the general configuration of registered plugins
|
||||
map<string,pGenConf> mapRegPluginGenConf;
|
||||
std::map<std::string,pGenConf> mapRegPluginGenConf;
|
||||
|
||||
//! A map to store the zone configuration of registered plugins
|
||||
map<string,PluginZoneConf> mapRegPluginZoneConf;
|
||||
std::map<std::string,PluginZoneConf> mapRegPluginZoneConf;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -4452,7 +4452,7 @@ void Monitor::SingleImageZip( int scale)
|
|||
#if ZM_PLUGINS_ON
|
||||
void Monitor::DumpPluginStatus()
|
||||
{
|
||||
map<string,pGenConf> mapPluginGenConf;
|
||||
std::map<std::string,pGenConf> mapPluginGenConf;
|
||||
unsigned int nNumPlugins = ThePluginManager.getPluginsGenConf(mapPluginGenConf);
|
||||
bool bDoNativeDet = !config.turnoff_native_analysis && iDoNativeMotDet;
|
||||
|
||||
|
@ -4463,7 +4463,7 @@ void Monitor::DumpPluginStatus()
|
|||
}
|
||||
printf("%79sNATIVE DETECTION\n", " ");
|
||||
printf("PLUGIN NAME%*sREGISTERED CONFIGURED ZONE ENABLED ACTIVE REQUIRE INCLUDE REINIT\n", 19, " ");
|
||||
for (map<string,pGenConf>::iterator it = mapPluginGenConf.begin() ; it != mapPluginGenConf.end(); ++it)
|
||||
for (std::map<std::string,pGenConf>::iterator it = mapPluginGenConf.begin() ; it != mapPluginGenConf.end(); ++it)
|
||||
{
|
||||
PluginZoneConf mapPluginZoneConf;
|
||||
ThePluginManager.getPluginZoneConf( it->first, mapPluginZoneConf );
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "zm_plugin.h"
|
||||
#include "zm_config.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
/*!\fn Plugin::Plugin(const std::string &sFilename)
|
||||
|
@ -18,7 +20,7 @@ Plugin::Plugin(const std::string &sFilename)
|
|||
|
||||
if(!m_hDLL) // if library hasn't been loaded successfully
|
||||
{
|
||||
throw runtime_error("Could not load '" + sFilename + "' (" + dlerror() + ")");
|
||||
throw std::runtime_error("Could not load '" + sFilename + "' (" + dlerror() + ")");
|
||||
}
|
||||
|
||||
// Locate the plugin's exported functions
|
||||
|
@ -30,12 +32,12 @@ Plugin::Plugin(const std::string &sFilename)
|
|||
// If the functions aren't found, we're going to assume this is
|
||||
// a plain simple DLL and not one of our plugins
|
||||
if(!m_pfnGetEngineVersion || ! m_pfnRegisterPlugin)
|
||||
throw runtime_error("'" + sFilename + "' is not a valid plugin");
|
||||
throw std::runtime_error("'" + sFilename + "' is not a valid plugin");
|
||||
|
||||
// Initialize a new DLL reference counter
|
||||
m_pDLLRefCount = new size_t(1);
|
||||
}
|
||||
catch(runtime_error &ex)
|
||||
catch(std::runtime_error &ex)
|
||||
{
|
||||
dlclose(m_hDLL);
|
||||
throw ex;
|
||||
|
@ -43,7 +45,7 @@ Plugin::Plugin(const std::string &sFilename)
|
|||
catch(...)
|
||||
{
|
||||
dlclose(m_hDLL);
|
||||
throw runtime_error("Unknown exception while loading plugin '" + sFilename + "'");
|
||||
throw std::runtime_error("Unknown exception while loading plugin '" + sFilename + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,5 +103,21 @@ Plugin::~Plugin()
|
|||
*/
|
||||
void Plugin::registerPlugin(PluginManager &K)
|
||||
{
|
||||
int pluginEngineVersion = m_pfnGetEngineVersion();
|
||||
|
||||
if(pluginEngineVersion == ZM_ENGINE_VERSION)
|
||||
m_pfnRegisterPlugin(K, m_sPluginFileName);
|
||||
else
|
||||
{
|
||||
// Raise an exception to inform the plugin manager that something bad happened
|
||||
std::ostringstream strPluginVersion;
|
||||
std::ostringstream strZMVersion;
|
||||
std::string strError;
|
||||
strPluginVersion << pluginEngineVersion;
|
||||
strZMVersion << ZM_ENGINE_VERSION;
|
||||
strError = "Could not load '" + m_sPluginFileName
|
||||
+ "' (engine version mistmatch: ZM=" + strZMVersion.str()
|
||||
+ " / plugin=" + strPluginVersion.str() + ")";
|
||||
throw std::logic_error(strError.c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef ZM_PLUGIN_H
|
||||
#define ZM_PLUGIN_H
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
|
@ -10,11 +8,6 @@
|
|||
#include <stdexcept>
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
class PluginManager;
|
||||
|
||||
|
||||
|
@ -23,7 +16,7 @@ class PluginManager;
|
|||
typedef int fnGetEngineVersion();
|
||||
|
||||
//! Signature for the plugin's registration function
|
||||
typedef void fnRegisterPlugin(PluginManager &, string);
|
||||
typedef void fnRegisterPlugin(PluginManager &, std::string);
|
||||
|
||||
|
||||
|
||||
|
@ -57,7 +50,7 @@ public:
|
|||
private:
|
||||
|
||||
//! Shared file name.
|
||||
string m_sPluginFileName;
|
||||
std::string m_sPluginFileName;
|
||||
|
||||
//! DLL handle
|
||||
void* m_hDLL;
|
||||
|
|
|
@ -28,15 +28,15 @@ int file_select(const struct direct *entry)
|
|||
|
||||
|
||||
|
||||
/*! \fn join_paths(const string& p1, const string& p2)
|
||||
/*! \fn join_paths(const std::string& p1, const std::string& p2)
|
||||
* \param p1 is the first part of desired path
|
||||
* \param p2 is the second part of desired path
|
||||
* \return joined path string.
|
||||
*/
|
||||
string join_paths(const string& p1, const string& p2)
|
||||
std::string join_paths(const std::string& p1, const std::string& p2)
|
||||
{
|
||||
char sep = '/';
|
||||
string tmp = p1;
|
||||
std::string tmp = p1;
|
||||
|
||||
#ifdef _WIN32
|
||||
sep = '\\';
|
||||
|
@ -53,7 +53,7 @@ string join_paths(const string& p1, const string& p2)
|
|||
|
||||
|
||||
|
||||
string PluginManager::m_sPluginExt = DEFAULT_PLUGIN_EXT;
|
||||
std::string PluginManager::m_sPluginExt = DEFAULT_PLUGIN_EXT;
|
||||
|
||||
|
||||
PluginManager::PluginManager() {}
|
||||
|
@ -67,37 +67,42 @@ PluginManager::PluginManager(
|
|||
|
||||
|
||||
|
||||
/*!\fn PluginManager::loadPlugin(const string &sFilename))
|
||||
/*!\fn PluginManager::loadPlugin(const std::string &sFilename))
|
||||
* \param sFilename is the name of plugin file to load
|
||||
*/
|
||||
bool PluginManager::loadPlugin(const string &sFilename)
|
||||
bool PluginManager::loadPlugin(const std::string &sFilename)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(m_LoadedPlugins.find(sFilename) == m_LoadedPlugins.end())
|
||||
m_LoadedPlugins.insert(PluginMap::value_type(sFilename, Plugin(sFilename))).first->second.registerPlugin(*this);
|
||||
}
|
||||
catch(runtime_error &ex)
|
||||
catch(std::runtime_error &ex)
|
||||
{
|
||||
Error("Runtime error: %s", ex.what());
|
||||
Error("Runtime error: %s.", ex.what());
|
||||
return false;
|
||||
}
|
||||
catch(std::logic_error &el)
|
||||
{
|
||||
Error("Logic error: %s.", el.what());
|
||||
return false;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
Error("Unknown exception. Could not load %s.", sFilename.c_str());
|
||||
Error("Unknown error: Could not load %s.", sFilename.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*!\fn PluginManager::findPlugins(const string &sPath, bool loadPlugins)
|
||||
/*!\fn PluginManager::findPlugins(const std::string &sPath, bool loadPlugins, unsigned int& nNumPlugLoaded)
|
||||
* \param sPath is the path to folder to search plugins
|
||||
* \param loadPlugins is a flag to allow loading of plugins
|
||||
* \param nNumPlugLoaded is the number of loaded plugins
|
||||
* \return the number of found plugins
|
||||
*/
|
||||
int PluginManager::findPlugins(const string sPath, bool loadPlugins, unsigned int& nNumPlugLoaded)
|
||||
int PluginManager::findPlugins(const std::string sPath, bool loadPlugins, unsigned int& nNumPlugLoaded)
|
||||
{
|
||||
struct direct **files;
|
||||
int count = scandir(sPath.c_str(), &files, file_select, alphasort);
|
||||
|
@ -105,10 +110,10 @@ int PluginManager::findPlugins(const string sPath, bool loadPlugins, unsigned in
|
|||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
string sFileName = string(files[i]->d_name);
|
||||
string sFullPath = join_paths(sPath, sFileName);
|
||||
std::string sFileName = std::string(files[i]->d_name);
|
||||
std::string sFullPath = join_paths(sPath, sFileName);
|
||||
size_t idx = sFileName.rfind('.');
|
||||
if (idx != string::npos)
|
||||
if (idx != std::string::npos)
|
||||
sFileName = sFileName.substr(0, idx);
|
||||
bool IsPluginRegistered = false;
|
||||
if(config.load_plugins || loadPlugins)
|
||||
|
@ -116,45 +121,46 @@ int PluginManager::findPlugins(const string sPath, bool loadPlugins, unsigned in
|
|||
Info("Loading plugin %s ... ", sFullPath.c_str());
|
||||
IsPluginRegistered = loadPlugin(sFullPath);
|
||||
}
|
||||
mapPluginReg.insert( pair<string,bool>(sFileName, IsPluginRegistered) );
|
||||
mapPluginReg.insert( std::pair<std::string,bool>(sFileName, IsPluginRegistered) );
|
||||
if (IsPluginRegistered) nNumPlugLoaded++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/*!\fn PluginManager::configurePlugins(string sConfigFileName)
|
||||
/*!\fn PluginManager::configurePlugins(std::string sConfigFileName, bool bDoNativeDet)
|
||||
* \param sConfigFileName is the path to the configuration file, where parameters for all plugins are given.
|
||||
* \param bDoNativeDet is true if native detection will be performed
|
||||
*/
|
||||
void PluginManager::configurePlugins(string sConfigFileName, bool bDoNativeDet)
|
||||
void PluginManager::configurePlugins(std::string sConfigFileName, bool bDoNativeDet)
|
||||
{
|
||||
m_ImageAnalyser.configurePlugins(sConfigFileName, bDoNativeDet);
|
||||
}
|
||||
|
||||
|
||||
/*!\fn PluginManager::getPluginsGenConf(map<string,pGenConf>& mapPluginGenConf)
|
||||
/*!\fn PluginManager::getPluginsGenConf(std::map<std::string,pGenConf>& mapPluginGenConf)
|
||||
* \param mapPluginGenConf is the map of general settings for the plugins
|
||||
* \param mapPluginZoneConf is the map of zone settings for the plugins
|
||||
* \return the number of found plugins
|
||||
*/
|
||||
unsigned long PluginManager::getPluginsGenConf(map<string,pGenConf>& mapPluginGenConf)
|
||||
unsigned long PluginManager::getPluginsGenConf(std::map<std::string,pGenConf>& mapPluginGenConf)
|
||||
{
|
||||
for (map<string,bool>::iterator it = mapPluginReg.begin() ; it != mapPluginReg.end(); ++it)
|
||||
for (std::map<std::string,bool>::iterator it = mapPluginReg.begin() ; it != mapPluginReg.end(); ++it)
|
||||
{
|
||||
pGenConf plugGenConf;
|
||||
m_ImageAnalyser.getRegPluginGenConf( it->first, plugGenConf );
|
||||
plugGenConf.Registered = it->second;
|
||||
mapPluginGenConf.insert( pair<string,pGenConf>(it->first, plugGenConf) );
|
||||
mapPluginGenConf.insert( std::pair<std::string,pGenConf>(it->first, plugGenConf) );
|
||||
}
|
||||
return mapPluginGenConf.size();
|
||||
}
|
||||
|
||||
|
||||
/*!\fn PluginManager::getPluginZoneConf(string sPluginName, PluginZoneConf& mapPluginZoneConf)
|
||||
/*!\fn PluginManager::getPluginZoneConf(std::string sPluginName, PluginZoneConf& mapPluginZoneConf)
|
||||
* \param sPluginName is the plugin name
|
||||
* \param mapPluginZoneConf is the map of zone settings for the plugin
|
||||
*/
|
||||
void PluginManager::getPluginZoneConf(string sPluginName, PluginZoneConf& mapPluginZoneConf)
|
||||
void PluginManager::getPluginZoneConf(std::string sPluginName, PluginZoneConf& mapPluginZoneConf)
|
||||
{
|
||||
m_ImageAnalyser.getRegPluginZoneConf( sPluginName, mapPluginZoneConf );
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef ZM_PLUGIN_MANAGER_H
|
||||
#define ZM_PLUGIN_MANAGER_H
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
@ -19,12 +17,6 @@
|
|||
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#define ZM_ENGINE_VERSION 24
|
||||
|
||||
|
||||
//! Map of plugins by their associated file names.
|
||||
typedef std::map<std::string, Plugin> PluginMap;
|
||||
|
||||
|
@ -38,7 +30,7 @@ int file_select(const struct direct *entry);
|
|||
|
||||
|
||||
//! Join two path strings.
|
||||
string join_paths(const string& p1, const string& p2);
|
||||
std::string join_paths(const std::string& p1, const std::string& p2);
|
||||
|
||||
|
||||
|
||||
|
@ -56,26 +48,26 @@ public:
|
|||
ImageAnalyser &getImageAnalyser() {return m_ImageAnalyser;}
|
||||
|
||||
//! Loads a plugin.
|
||||
bool loadPlugin(const string &sFilename);
|
||||
bool loadPlugin(const std::string &sFilename);
|
||||
|
||||
//! Find all plugins from given directory, load them if required and
|
||||
//! return the number of found plugins and the number of loaded plugins
|
||||
int findPlugins(const string sPath, bool loadPlugins, unsigned int& nNumPlugLoaded);
|
||||
int findPlugins(const std::string sPath, bool loadPlugins, unsigned int& nNumPlugLoaded);
|
||||
|
||||
//! Get general settings of plugins
|
||||
unsigned long getPluginsGenConf(map<string,pGenConf>& mapPluginGenConf);
|
||||
unsigned long getPluginsGenConf(std::map<std::string,pGenConf>& mapPluginGenConf);
|
||||
|
||||
//! Get zone settings of a plugin
|
||||
void getPluginZoneConf(string sPluginName, PluginZoneConf& mapPluginZoneConf);
|
||||
void getPluginZoneConf(std::string sPluginName, PluginZoneConf& mapPluginZoneConf);
|
||||
|
||||
//! Configure all loaded plugins using given configuration file.
|
||||
void configurePlugins(string sConfigFileName, bool bDoNativeDet);
|
||||
void configurePlugins(std::string sConfigFileName, bool bDoNativeDet);
|
||||
|
||||
//! Set plugin extension.
|
||||
void setPluginExt(string sPluginExt) { m_sPluginExt = sPluginExt; }
|
||||
void setPluginExt(std::string sPluginExt) { m_sPluginExt = sPluginExt; }
|
||||
|
||||
//! Extension for zm plugins.
|
||||
static string m_sPluginExt;
|
||||
static std::string m_sPluginExt;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -86,7 +78,7 @@ private:
|
|||
ImageAnalyser m_ImageAnalyser;
|
||||
|
||||
//! Plugin list
|
||||
map<string,bool> mapPluginReg;
|
||||
std::map<std::string,bool> mapPluginReg;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue