X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConfig%2FConfig_ModuleReader.cpp;h=41ceda577b62f7b4bb1eb58cc767cabcde8e86f2;hb=1d92b37c3a412e565c82b8dce640a035d9f554c2;hp=21925af599b1b91fca64131371d931ed98ad6443;hpb=94a0bf3ae8768e2f4ec5848692276dca05208e80;p=modules%2Fshaper.git diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index 21925af59..41ceda577 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -21,14 +21,17 @@ //Necessary for cerr #include +#include #ifdef WIN32 #include +#pragma warning(disable : 4996) // for getenv #else #include #endif std::map Config_ModuleReader::myPluginTypes; +std::set Config_ModuleReader::myDependencyModules; Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated) : Config_XMLReader(PLUGIN_FILE), @@ -45,7 +48,12 @@ const std::map& Config_ModuleReader::featuresInFiles() return myFeaturesInFiles; } -/* +const std::set& Config_ModuleReader::modulePluginFiles() const +{ + return myPluginFiles; +} + +/*! * Get module name from plugins.xml * (property "module") */ @@ -55,13 +63,13 @@ std::string Config_ModuleReader::getModuleName() return getProperty(aRoot, PLUGINS_MODULE); } -/* - * - */ void Config_ModuleReader::processNode(xmlNodePtr theNode) { if (isNode(theNode, NODE_PLUGIN, NULL)) { + if (!hasRequiredModules(theNode)) + return; std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG); + if (!aPluginConf.empty()) myPluginFiles.insert(aPluginConf); std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY); std::string aPluginScript = getProperty(theNode, PLUGIN_SCRIPT); std::string aPluginName = addPlugin(aPluginLibrary, aPluginScript, aPluginConf); @@ -79,6 +87,18 @@ bool Config_ModuleReader::processChildren(xmlNodePtr theNode) return isNode(theNode, NODE_PLUGINS, NULL); } +bool Config_ModuleReader::hasRequiredModules(xmlNodePtr theNode) const +{ + std::string aRequiredModule = normalize(getProperty(theNode, PLUGIN_DEPENDENCY)); + if(aRequiredModule.empty()) + return true; + std::set::iterator it = myDependencyModules.begin(); + for ( ; it != myDependencyModules.end(); it++ ) { + if (*it == aRequiredModule) return true; + } + return false; +} + std::list Config_ModuleReader::importPlugin(const std::string& thePluginLibrary, const std::string& thePluginXmlConf) { @@ -111,12 +131,12 @@ std::string Config_ModuleReader::addPlugin(const std::string& aPluginLibrary, } if(!aPluginName.empty()) { myPluginTypes[aPluginName] = aType; - } + addDependencyModule(aPluginName); return aPluginName; } -void Config_ModuleReader::loadPlugin(const std::string thePluginName) +void Config_ModuleReader::loadPlugin(const std::string& thePluginName) { PluginType aType = Config_ModuleReader::Binary; if(myPluginTypes.find(thePluginName) != myPluginTypes.end()) { @@ -134,22 +154,25 @@ void Config_ModuleReader::loadPlugin(const std::string thePluginName) } } -void Config_ModuleReader::loadScript(const std::string theFileName) +void Config_ModuleReader::loadScript(const std::string& theFileName) { /* aquire python thread */ PyGILState_STATE gstate = PyGILState_Ensure(); - PyObject* module = PyImport_ImportModule(theFileName.c_str()); + 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 *ptype, *pvalue, *ptraceback; + PyObject *pstr, *ptype, *pvalue, *ptraceback; PyErr_Fetch(&ptype, &pvalue, &ptraceback); - std::string aPyError = std::string(PyString_AsString(pvalue)); + 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); @@ -161,7 +184,7 @@ void Config_ModuleReader::loadScript(const std::string theFileName) PyGILState_Release(gstate); } -void Config_ModuleReader::loadLibrary(const std::string theLibName) +void Config_ModuleReader::loadLibrary(const std::string& theLibName) { std::string aFileName = library(theLibName); if (aFileName.empty()) @@ -177,7 +200,13 @@ void Config_ModuleReader::loadLibrary(const std::string theLibName) #ifndef WIN32 anErrorMsg += ": " + std::string(dlerror()); #endif + std::cerr << anErrorMsg << std::endl; Events_Error::send(anErrorMsg); } } +void Config_ModuleReader::addDependencyModule(const std::string& theModuleName) +{ + myDependencyModules.insert(normalize(theModuleName)); +} +