diff options
| author | Zdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com> | 2009-07-31 17:08:49 +0200 |
|---|---|---|
| committer | Zdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com> | 2009-07-31 17:08:49 +0200 |
| commit | de2c473ef6cb27a080bb0491f21d1280e2c971c5 (patch) | |
| tree | 7189bf00de07ea69fe29ee0a1435e7b65316a8d4 /lib/MiddleWare | |
| parent | 3f89291d3dbb6ebd28cf7aaa1cbde24b27810bfc (diff) | |
| download | abrt-de2c473ef6cb27a080bb0491f21d1280e2c971c5.tar.gz abrt-de2c473ef6cb27a080bb0491f21d1280e2c971c5.tar.xz abrt-de2c473ef6cb27a080bb0491f21d1280e2c971c5.zip | |
added new interface for geting plugins' settings (will be used in gui)
Diffstat (limited to 'lib/MiddleWare')
| -rw-r--r-- | lib/MiddleWare/MiddleWare.cpp | 10 | ||||
| -rw-r--r-- | lib/MiddleWare/MiddleWare.h | 27 | ||||
| -rw-r--r-- | lib/MiddleWare/Plugin.h | 81 | ||||
| -rw-r--r-- | lib/MiddleWare/PluginManager.cpp | 26 | ||||
| -rw-r--r-- | lib/MiddleWare/PluginManager.h | 13 | ||||
| -rw-r--r-- | lib/MiddleWare/test.cpp | 14 |
6 files changed, 161 insertions, 10 deletions
diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp index 9177755..b4f8da0 100644 --- a/lib/MiddleWare/MiddleWare.cpp +++ b/lib/MiddleWare/MiddleWare.cpp @@ -108,6 +108,16 @@ void CMiddleWare::UnRegisterPlugin(const std::string& pName) m_pPluginManager->UnRegisterPlugin(pName); } +void CMiddleWare::SetPluginSettings(const std::string& pName, + const map_plugin_settings_t& pSettings) +{ + m_pPluginManager->SetPluginSettings(pName, pSettings); +} + +map_plugin_settings_t CMiddleWare::GetPluginSettings(const std::string& pName) +{ + return m_pPluginManager->GetPluginSettings(pName); +} std::string CMiddleWare::GetLocalUUID(const std::string& pAnalyzer, const std::string& pDebugDumpDir) diff --git a/lib/MiddleWare/MiddleWare.h b/lib/MiddleWare/MiddleWare.h index 2144bba..6783c4e 100644 --- a/lib/MiddleWare/MiddleWare.h +++ b/lib/MiddleWare/MiddleWare.h @@ -198,6 +198,26 @@ class CMiddleWare */ void UnRegisterPlugin(const std::string& pName); /** + * A method, which sets up a plugin. + * @param pName A plugin name. + * @param pSettings A plugin's settings. + */ + void SetPluginSettings(const std::string& pName, + const map_plugin_settings_t& pSettings); + /** + * A method, which returns plugin's settings. + * @param pName A plugin name. + * @return Plugin's settings + */ + map_plugin_settings_t GetPluginSettings(const std::string& pName); + /** + * A method, which gets all plugins info (event those plugins which are + * disabled). It can be send via DBus to GUI and displayed to an user. + * Then a user can fill all needed informations like URLs etc. + * @return A vector of maps <key, vaule> + */ + vector_map_string_string_t GetPluginsInfo(); + /** * A method, which takes care of getting all additional data needed * for computing UUIDs and creating a report for particular analyzer * plugin. This report could be send somewhere afterwards. If a creation @@ -288,13 +308,6 @@ class CMiddleWare */ vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID); /** - * A method, which gets all plugins info (event those plugins which are - * disabled). It can be send via DBus to GUI and displayed to an user. - * Then a user can fill all needed informations like URLs etc. - * @return A vector of maps <key, vaule> - */ - vector_map_string_string_t GetPluginsInfo(); - /** * A method, which set a GPG finger print check. * @param pCheck Is it enabled? */ diff --git a/lib/MiddleWare/Plugin.h b/lib/MiddleWare/Plugin.h index c7ae9ce..47915ce 100644 --- a/lib/MiddleWare/Plugin.h +++ b/lib/MiddleWare/Plugin.h @@ -25,15 +25,20 @@ #include <string> #include <map> +#include <fstream> -#define PLUGINS_MAGIC_NUMBER 3 + +#define PLUGINS_MAGIC_NUMBER 4 #define PLUGINS_CONF_EXTENSION "conf" #define PLUGINS_LIB_EXTENSION "so" #define PLUGINS_LIB_PREFIX "lib" +typedef std::map<std::string, std::string> map_plugin_settings_t; + /** - * An abstract class. The class defines a common plugin interface. + * An abstract class. The class defines a common plugin interface. If a plugin + * has some settings, then a *Settings(*) method has to be written. */ class CPlugin { @@ -51,10 +56,20 @@ class CPlugin */ virtual void DeInit() {} /** - * A method, which loads a plugin settings. It is not mandatory method. + * A method, which loads a plugin settings from a file. It is not mandatory method. * @param pPath A path to plugin configuration file. */ virtual void LoadSettings(const std::string& pPath) {} + /** + * A method, which takes a settings and apply them. It is not a mandatory method. + * @param pSettings Plugin's settings + */ + virtual void SetSettings(const map_plugin_settings_t& pSettings) {} + /** + * A method, which return current settings. It is not mandatory method. + * @return Plugin's settings + */ + virtual map_plugin_settings_t GetSettings() {return map_plugin_settings_t();} }; /** @@ -101,4 +116,64 @@ typedef struct SPluginInfo PLUGINS_MAGIC_NUMBER,\ }; +inline void plugin_load_settings(const std::string& path, map_plugin_settings_t& settings) +{ + std::ifstream fIn; + fIn.open(path.c_str()); + if (fIn.is_open()) + { + std::string line; + while (!fIn.eof()) + { + getline(fIn, line); + + int ii; + bool is_value = false; + bool valid = false; + bool in_quote = false; + std::string key = ""; + std::string value = ""; + for (ii = 0; ii < line.length(); ii++) + { + if (line[ii] == '\"') + { + in_quote = in_quote == true ? false : true; + } + if (isspace(line[ii]) && !in_quote) + { + continue; + } + if (line[ii] == '#' && !in_quote) + { + break; + } + else if (line[ii] == '=' && !in_quote) + { + is_value = true; + } + else if (line[ii] == '=' && is_value && !in_quote) + { + key = ""; + value = ""; + break; + } + else if (!is_value) + { + key += line[ii]; + } + else + { + valid = true; + value += line[ii]; + } + } + if (valid && !in_quote) + { + settings[key] = value; + } + } + fIn.close(); + } +} + #endif /* PLUGIN_H_ */ diff --git a/lib/MiddleWare/PluginManager.cpp b/lib/MiddleWare/PluginManager.cpp index 2d11093..2002a4a 100644 --- a/lib/MiddleWare/PluginManager.cpp +++ b/lib/MiddleWare/PluginManager.cpp @@ -240,6 +240,8 @@ vector_map_string_string_t CPluginManager::GetPluginsInfo() { map_string_string_t plugin_info; + plugin_info["Enabled"] = (m_mapPlugins.find(it_abrt_plugin->second->GetName()) != m_mapPlugins.end()) ? + "yes" : "no"; plugin_info["Type"] = plugin_type_str_t[it_abrt_plugin->second->GetType()]; plugin_info["Name"] = it_abrt_plugin->second->GetName(); plugin_info["Version"] = it_abrt_plugin->second->GetVersion(); @@ -253,3 +255,27 @@ vector_map_string_string_t CPluginManager::GetPluginsInfo() return ret; } +void CPluginManager::SetPluginSettings(const std::string& pName, + const map_plugin_settings_t& pSettings) +{ + if (m_mapABRTPlugins.find(pName) != m_mapABRTPlugins.end()) + { + if (m_mapPlugins.find(pName) != m_mapPlugins.end()) + { + m_mapPlugins[pName]->SetSettings(pSettings); + } + } +} + +map_plugin_settings_t CPluginManager::GetPluginSettings(const std::string& pName) +{ + map_plugin_settings_t ret; + if (m_mapABRTPlugins.find(pName) != m_mapABRTPlugins.end()) + { + if (m_mapPlugins.find(pName) != m_mapPlugins.end()) + { + ret = m_mapPlugins[pName]->GetSettings(); + } + } + return ret; +} diff --git a/lib/MiddleWare/PluginManager.h b/lib/MiddleWare/PluginManager.h index 4883a10..21c37fa 100644 --- a/lib/MiddleWare/PluginManager.h +++ b/lib/MiddleWare/PluginManager.h @@ -138,6 +138,19 @@ class CPluginManager * @return A vector of maps <key, vaule> */ vector_map_string_string_t GetPluginsInfo(); + /** + * A method, which sets up a plugin. + * @param pName A plugin name. + * @param pSettings A plugin's settings. + */ + void SetPluginSettings(const std::string& pName, + const map_plugin_settings_t& pSettings); + /** + * A method, which returns plugin's settings. + * @param pName A plugin name. + * @return Plugin's settings + */ + map_plugin_settings_t GetPluginSettings(const std::string& pName); }; #endif /*PLUGINMANAGER_H_*/ diff --git a/lib/MiddleWare/test.cpp b/lib/MiddleWare/test.cpp index 5a3519c..9e2498f 100644 --- a/lib/MiddleWare/test.cpp +++ b/lib/MiddleWare/test.cpp @@ -57,6 +57,9 @@ int main(int argc, char** argv) int ii; for ( ii = 0; ii < loaded_plugins.size(); ii++) { + std::cout << "-------------------------------------------" << std::endl; + map_plugin_settings_t settings; + std::cout << "Enabled: " << loaded_plugins[ii]["Enabled"] << std::endl; std::cout << "Type: " << loaded_plugins[ii]["Type"] << std::endl; std::cout << "Name: " << loaded_plugins[ii]["Name"] << std::endl; std::cout << "Version: " << loaded_plugins[ii]["Version"] << std::endl; @@ -64,6 +67,17 @@ int main(int argc, char** argv) std::cout << "Email: " << loaded_plugins[ii]["Email"] << std::endl; std::cout << "WWW: " << loaded_plugins[ii]["WWW"] << std::endl; std::cout << "GTKBuilder: " << loaded_plugins[ii]["GTKBuilder"] << std::endl; + if (loaded_plugins[ii]["Enabled"] == "yes") + { + std::cout << std::endl << "Settings: " << std::endl; + settings = middleWare.GetPluginSettings(loaded_plugins[ii]["Name"]); + map_plugin_settings_t::iterator it; + for (it = settings.begin(); it != settings.end(); it++) + { + std::cout << "\t" << it->first << ": " << it->second << std::endl; + } + } + std::cout << "-------------------------------------------" << std::endl; } /* Try to save it into DB */ map_crash_info_t crashInfo; |
