+
+ Config_FeatureReader aReader = Config_FeatureReader(thePluginXmlConf,
+ thePluginLibrary,
+ myEventGenerated);
+ aReader.readAll();
+ return aReader.features();
+}
+
+std::string Config_ModuleReader::addPlugin(const std::string& aPluginLibrary,
+ const std::string& aPluginScript,
+ const std::string& aPluginConf)
+{
+ PluginType aType = Config_ModuleReader::Binary;
+ std::string aPluginName;
+ if (!aPluginLibrary.empty()) {
+ aPluginName = aPluginLibrary;
+ if (aPluginConf.empty()) {
+ aType = Config_ModuleReader::Intrenal;
+ }
+ } else if (!aPluginScript.empty()) {
+ aPluginName = aPluginScript;
+ aType = Config_ModuleReader::Python;
+ }
+ if(!aPluginName.empty()) {
+ myPluginTypes[aPluginName] = aType;
+ }
+ addDependencyModule(aPluginName);
+ return aPluginName;
+}
+
+void Config_ModuleReader::loadPlugin(const std::string& thePluginName)
+{
+ PluginType aType = Config_ModuleReader::Binary;
+ if(myPluginTypes.find(thePluginName) != myPluginTypes.end()) {
+ aType = myPluginTypes.at(thePluginName);
+ }
+ switch (aType) {
+ case Config_ModuleReader::Python:
+ loadScript(thePluginName);
+ break;
+ case Config_ModuleReader::Binary:
+ case Config_ModuleReader::Intrenal:
+ default:
+ loadLibrary(thePluginName);
+ break;
+ }
+}
+
+void Config_ModuleReader::loadScript(const std::string& theFileName)
+{
+ /* aquire python thread */
+ PyGILState_STATE gstate = PyGILState_Ensure();
+
+ PyObject* module = PyImport_ImportModule(theFileName.c_str());
+ if (!module) {
+ std::string anErrorMsg = "An error occured while importing " + theFileName;
+ //Get detailed error message:
+ if (PyErr_Occurred()) {
+ PyObject *pstr, *ptype, *pvalue, *ptraceback;
+ PyErr_Fetch(&ptype, &pvalue, &ptraceback);
+ PyErr_NormalizeException(&ptype, &pvalue, &ptraceback);
+ pstr = PyObject_Str(pvalue);
+ std::string aPyError = std::string(PyString_AsString(pstr));
+ if (!aPyError.empty()) {
+ anErrorMsg += ":\n" + aPyError;
+ }
+ Py_XDECREF(pstr);
+ Py_XDECREF(ptype);
+ Py_XDECREF(pvalue);
+ Py_XDECREF(ptraceback);
+ }
+ Events_Error::send(anErrorMsg);
+ }
+
+ /* release python thread */
+ PyGILState_Release(gstate);