summaryrefslogtreecommitdiffstats
path: root/lib/MiddleWare
diff options
context:
space:
mode:
authorZdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com>2009-04-16 17:54:20 +0200
committerZdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com>2009-04-16 17:54:20 +0200
commitb67b664e6f3019a142996c5bdc3a2e8c32f4306a (patch)
tree95aaf34561d8abc9cd59da1229b4ff620ac194e0 /lib/MiddleWare
parentd71fe39576ded4e9567f5f938e9ef67183bb8afd (diff)
- reporter plugins can tak an argiment
- added "Reporters" option which allows report basic info after a crash occurs - fixed interface of plugins
Diffstat (limited to 'lib/MiddleWare')
-rw-r--r--lib/MiddleWare/MiddleWare.cpp20
-rw-r--r--lib/MiddleWare/MiddleWare.h15
-rw-r--r--lib/MiddleWare/Plugin.h2
-rw-r--r--lib/MiddleWare/PluginManager.cpp154
-rw-r--r--lib/MiddleWare/Reporter.h4
5 files changed, 100 insertions, 95 deletions
diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp
index e1e679a..bc8e9de 100644
--- a/lib/MiddleWare/MiddleWare.cpp
+++ b/lib/MiddleWare/MiddleWare.cpp
@@ -182,8 +182,8 @@ void CMiddleWare::Report(const std::string& pDebugDumpDir)
set_reporters_t::iterator it_r;
for (it_r = m_setReporters.begin(); it_r != m_setReporters.end(); it_r++)
{
- CReporter* reporter = m_pPluginManager->GetReporter(*it_r);
- reporter->Report(crashReport);
+ CReporter* reporter = m_pPluginManager->GetReporter((*it_r).first);
+ reporter->Report(crashReport, (*it_r).second);
}
}
@@ -206,8 +206,8 @@ void CMiddleWare::Report(const map_crash_report_t& pCrashReport)
it_r != m_mapAnalyzerReporters[analyzer].end();
it_r++)
{
- CReporter* reporter = m_pPluginManager->GetReporter(*it_r);
- reporter->Report(pCrashReport);
+ CReporter* reporter = m_pPluginManager->GetReporter((*it_r).first);
+ reporter->Report(pCrashReport, (*it_r).second);
}
}
@@ -337,7 +337,7 @@ void CMiddleWare::RunAnalyzerActions(const std::string& pAnalyzer, const std::st
{
if (m_mapAnalyzerActions.find(pAnalyzer) != m_mapAnalyzerActions.end())
{
- set_actions_t::iterator it_a;
+ set_pairt_strings_t::iterator it_a;
for (it_a = m_mapAnalyzerActions[pAnalyzer].begin();
it_a != m_mapAnalyzerActions[pAnalyzer].end();
it_a++)
@@ -491,9 +491,10 @@ void CMiddleWare::AddBlackListedPackage(const std::string& pPackage)
}
void CMiddleWare::AddAnalyzerReporter(const std::string& pAnalyzer,
- const std::string& pReporter)
+ const std::string& pReporter,
+ const std::string& pArgs)
{
- m_mapAnalyzerReporters[pAnalyzer].insert(pReporter);
+ m_mapAnalyzerReporters[pAnalyzer].insert(make_pair(pReporter, pArgs));
}
void CMiddleWare::AddAnalyzerAction(const std::string& pAnalyzer,
@@ -503,7 +504,8 @@ void CMiddleWare::AddAnalyzerAction(const std::string& pAnalyzer,
m_mapAnalyzerActions[pAnalyzer].insert(make_pair(pAction, pArgs));
}
-void CMiddleWare::AddReporter(const std::string& pReporter)
+void CMiddleWare::AddReporter(const std::string& pReporter,
+ const std::string& pArgs)
{
- m_setReporters.insert(pReporter);
+ m_setReporters.insert(make_pair(pReporter, pArgs));
}
diff --git a/lib/MiddleWare/MiddleWare.h b/lib/MiddleWare/MiddleWare.h
index 28afb2a..4ec3df3 100644
--- a/lib/MiddleWare/MiddleWare.h
+++ b/lib/MiddleWare/MiddleWare.h
@@ -34,10 +34,11 @@ class CMiddleWare
private:
typedef set_strings_t set_blacklist_t;
typedef set_strings_t set_enabled_plugins_t;
- typedef set_strings_t set_reporters_t;
- typedef std::map<std::string, set_reporters_t> map_reporter_associations_t;
- typedef std::set<pair_string_string_t> set_actions_t;
- typedef std::map<std::string, set_actions_t> map_action_associations_t;
+
+ typedef std::set<pair_string_string_t> set_pairt_strings_t;
+ typedef std::map<std::string, set_pairt_strings_t> map_reporter_associations_t;
+ typedef std::map<std::string, set_pairt_strings_t> map_action_associations_t;
+ typedef set_pairt_strings_t set_reporters_t;
CPluginManager* m_pPluginManager;
CRPM m_RPM;
@@ -98,11 +99,13 @@ class CMiddleWare
void AddOpenGPGPublicKey(const std::string& pKey);
void AddBlackListedPackage(const std::string& pPackage);
void AddAnalyzerReporter(const std::string& pAnalyzer,
- const std::string& pReporter);
+ const std::string& pReporter,
+ const std::string& pArgs);
void AddAnalyzerAction(const std::string& pAnalyzer,
const std::string& pAction,
const std::string& pArgs);
- void AddReporter(const std::string& pReporter);
+ void AddReporter(const std::string& pReporter,
+ const std::string& pArgs);
};
#endif /*MIDDLEWARE_H_*/
diff --git a/lib/MiddleWare/Plugin.h b/lib/MiddleWare/Plugin.h
index e4ebc3c..9fd5929 100644
--- a/lib/MiddleWare/Plugin.h
+++ b/lib/MiddleWare/Plugin.h
@@ -26,7 +26,7 @@
#include <string>
#include <map>
-#define PLUGINS_MAGIC_NUMBER 1
+#define PLUGINS_MAGIC_NUMBER 2
#define PLUGINS_CONF_EXTENSION "conf"
#define PLUGINS_LIB_EXTENSION "so"
diff --git a/lib/MiddleWare/PluginManager.cpp b/lib/MiddleWare/PluginManager.cpp
index 2f103f2..cbdd2c1 100644
--- a/lib/MiddleWare/PluginManager.cpp
+++ b/lib/MiddleWare/PluginManager.cpp
@@ -27,8 +27,8 @@
CPluginManager::CPluginManager(const std::string& pPlugisConfDir,
const std::string& pPlugisLibDir) :
- m_sPlugisConfDir(pPlugisConfDir),
- m_sPlugisLibDir(pPlugisLibDir)
+ m_sPlugisConfDir(pPlugisConfDir),
+ m_sPlugisLibDir(pPlugisLibDir)
{}
CPluginManager::~CPluginManager()
@@ -36,26 +36,26 @@ CPluginManager::~CPluginManager()
void CPluginManager::LoadPlugins()
{
- DIR *dir = opendir(m_sPlugisLibDir.c_str());
- struct dirent *dent = NULL;
- if (dir != NULL)
- {
- while ((dent = readdir(dir)) != NULL)
- {
- if (dent->d_type == DT_REG)
- {
- std::string name = dent->d_name;
- std::string extension = name.substr(name.length()-sizeof(PLUGINS_LIB_EXTENSION)+1);
- if (extension == PLUGINS_LIB_EXTENSION)
- {
- name.erase(0, sizeof(PLUGINS_LIB_PREFIX) - 1);
- name.erase(name.length() - sizeof(PLUGINS_LIB_EXTENSION));
- LoadPlugin(name);
- }
- }
- }
- closedir(dir);
- }
+ DIR *dir = opendir(m_sPlugisLibDir.c_str());
+ struct dirent *dent = NULL;
+ if (dir != NULL)
+ {
+ while ((dent = readdir(dir)) != NULL)
+ {
+ if (dent->d_type == DT_REG)
+ {
+ std::string name = dent->d_name;
+ std::string extension = name.substr(name.length()-sizeof(PLUGINS_LIB_EXTENSION)+1);
+ if (extension == PLUGINS_LIB_EXTENSION)
+ {
+ name.erase(0, sizeof(PLUGINS_LIB_PREFIX) - 1);
+ name.erase(name.length() - sizeof(PLUGINS_LIB_EXTENSION));
+ LoadPlugin(name);
+ }
+ }
+ }
+ closedir(dir);
+ }
}
void CPluginManager::UnLoadPlugins()
@@ -70,41 +70,41 @@ void CPluginManager::UnLoadPlugins()
void CPluginManager::LoadPlugin(const std::string& pName)
{
- if (m_mapABRTPlugins.find(pName) == m_mapABRTPlugins.end())
- {
- CABRTPlugin* abrtPlugin = NULL;
- try
- {
- std::string libPath = m_sPlugisLibDir + "/" + PLUGINS_LIB_PREFIX + pName + "." + PLUGINS_LIB_EXTENSION;
- abrtPlugin = new CABRTPlugin(libPath);
- if (abrtPlugin->GetMagicNumber() != PLUGINS_MAGIC_NUMBER ||
- (abrtPlugin->GetType() < ANALYZER && abrtPlugin->GetType() > DATABASE))
- {
- throw std::string("non-compatible plugin");
- }
- std::cerr << "Plugin " << pName << " (" << abrtPlugin->GetVersion() << ") " << "succesfully loaded." << std::endl;
- m_mapABRTPlugins[pName] = abrtPlugin;
- }
- catch (std::string sError)
- {
- if (abrtPlugin != NULL)
- {
- delete abrtPlugin;
- }
- std::cerr << "Failed to load plugin " << pName << " (" << sError << ")." << std::endl;
- }
- }
+ if (m_mapABRTPlugins.find(pName) == m_mapABRTPlugins.end())
+ {
+ CABRTPlugin* abrtPlugin = NULL;
+ try
+ {
+ std::string libPath = m_sPlugisLibDir + "/" + PLUGINS_LIB_PREFIX + pName + "." + PLUGINS_LIB_EXTENSION;
+ abrtPlugin = new CABRTPlugin(libPath);
+ if (abrtPlugin->GetMagicNumber() != PLUGINS_MAGIC_NUMBER ||
+ (abrtPlugin->GetType() < ANALYZER && abrtPlugin->GetType() > DATABASE))
+ {
+ throw std::string("non-compatible plugin");
+ }
+ std::cerr << "Plugin " << pName << " (" << abrtPlugin->GetVersion() << ") " << "succesfully loaded." << std::endl;
+ m_mapABRTPlugins[pName] = abrtPlugin;
+ }
+ catch (std::string sError)
+ {
+ if (abrtPlugin != NULL)
+ {
+ delete abrtPlugin;
+ }
+ std::cerr << "Failed to load plugin " << pName << " (" << sError << ")." << std::endl;
+ }
+ }
}
void CPluginManager::UnLoadPlugin(const std::string& pName)
{
- if (m_mapABRTPlugins.find(pName) != m_mapABRTPlugins.end())
- {
- UnRegisterPlugin(pName);
- delete m_mapABRTPlugins[pName];
- m_mapABRTPlugins.erase(pName);
- std::cerr << "Plugin " << pName << " sucessfully unloaded." << std::endl;
- }
+ if (m_mapABRTPlugins.find(pName) != m_mapABRTPlugins.end())
+ {
+ UnRegisterPlugin(pName);
+ delete m_mapABRTPlugins[pName];
+ m_mapABRTPlugins.erase(pName);
+ std::cerr << "Plugin " << pName << " sucessfully unloaded." << std::endl;
+ }
}
@@ -155,41 +155,41 @@ void CPluginManager::UnRegisterPlugin(const std::string& pName)
CAnalyzer* CPluginManager::GetAnalyzer(const std::string& pName)
{
- if (m_mapPlugins.find(pName) == m_mapPlugins.end())
- {
- throw std::string("CPluginManager::GetAnalyzer():"
- "Analyzer plugin: '"+pName+"' is not loaded.");
- }
- return dynamic_cast<CAnalyzer*>(m_mapPlugins[pName]);
+ if (m_mapPlugins.find(pName) == m_mapPlugins.end())
+ {
+ throw std::string("CPluginManager::GetAnalyzer():"
+ "Analyzer plugin: '"+pName+"' is not loaded.");
+ }
+ return dynamic_cast<CAnalyzer*>(m_mapPlugins[pName]);
}
CReporter* CPluginManager::GetReporter(const std::string& pName)
{
- if (m_mapPlugins.find(pName) == m_mapPlugins.end())
- {
- throw std::string("CPluginManager::GetReporter():"
- "Reporter plugin: '"+pName+"' is not loaded.");
- }
- return dynamic_cast<CReporter*>(m_mapPlugins[pName]);
+ if (m_mapPlugins.find(pName) == m_mapPlugins.end())
+ {
+ throw std::string("CPluginManager::GetReporter():"
+ "Reporter plugin: '"+pName+"' is not loaded.");
+ }
+ return dynamic_cast<CReporter*>(m_mapPlugins[pName]);
}
CAction* CPluginManager::GetAction(const std::string& pName)
{
- if (m_mapPlugins.find(pName) == m_mapPlugins.end())
- {
- throw std::string("CPluginManager::GetAction():"
- "Action plugin: '"+pName+"' is not loaded.");
- }
- return dynamic_cast<CAction*>(m_mapPlugins[pName]);
+ if (m_mapPlugins.find(pName) == m_mapPlugins.end())
+ {
+ throw std::string("CPluginManager::GetAction():"
+ "Action plugin: '"+pName+"' is not loaded.");
+ }
+ return dynamic_cast<CAction*>(m_mapPlugins[pName]);
}
CDatabase* CPluginManager::GetDatabase(const std::string& pName)
{
- if (m_mapPlugins.find(pName) == m_mapPlugins.end())
- {
- throw std::string("CPluginManager::GetDatabase():"
- "Database plugin: '"+pName+"' is not loaded.");
- }
- return dynamic_cast<CDatabase*>(m_mapPlugins[pName]);
+ if (m_mapPlugins.find(pName) == m_mapPlugins.end())
+ {
+ throw std::string("CPluginManager::GetDatabase():"
+ "Database plugin: '"+pName+"' is not loaded.");
+ }
+ return dynamic_cast<CDatabase*>(m_mapPlugins[pName]);
}
diff --git a/lib/MiddleWare/Reporter.h b/lib/MiddleWare/Reporter.h
index 02fae12..76680df 100644
--- a/lib/MiddleWare/Reporter.h
+++ b/lib/MiddleWare/Reporter.h
@@ -29,9 +29,9 @@
class CReporter : public CPlugin
{
public:
-
virtual ~CReporter() {}
- virtual void Report(const map_crash_report_t& pCrashReport) = 0;
+ virtual void Report(const map_crash_report_t& pCrashReport,
+ const std::string& pArgs) = 0;
};
#endif /* REPORTER_H_ */