1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 * Config_XMLModuleReader.h
23 * Created on: Mar 20, 2014
27 #ifndef CONFIG_MODULEREADER_H_
28 #define CONFIG_MODULEREADER_H_
30 #include <Config_def.h>
31 #include <Config_XMLReader.h>
39 * \class Config_ModuleReader
41 * \brief Class to process plugins.xml - definition of plugins (scripts, libraries).
43 class Config_ModuleReader : public Config_XMLReader
53 CONFIG_EXPORT Config_ModuleReader(const char* theEventGenerated = 0);
55 CONFIG_EXPORT virtual ~Config_ModuleReader();
56 /// Returns map that describes which file contains a feature
57 /// (the feature is key, the file is value)
58 CONFIG_EXPORT const std::map<std::string, std::string>& featuresInFiles() const;
59 /// Returns list of module's xml files
60 CONFIG_EXPORT const std::set<std::string>& modulePluginFiles() const;
61 /// Returns module name: an xml attribute from the root of the plugins.xml:
62 /// e.g \code <plugins module="PartSet"> \endcode
63 CONFIG_EXPORT std::string getModuleName();
64 /// Detects type of the given plugin and loads it using loadLibrary or loadScript.
65 CONFIG_EXPORT static void loadPlugin(const std::string& thePluginName);
66 /// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform
67 CONFIG_EXPORT static void loadLibrary(const std::string& theLibName);
68 /// loads the python module with specified name
69 /// \param theFileName name of the script
70 /// \param theSendErr send error message in case of faile
71 CONFIG_EXPORT static void loadScript(const std::string& theFileName, bool theSendErr = true);
73 * Extends set of modules, used for dependency checking (if there is no
74 * required module in the set, a plugin will not be loaded)
76 CONFIG_EXPORT static void addDependencyModule(const std::string& theModuleName);
79 /// Recursively process the given xmlNode
80 virtual void processNode(xmlNodePtr aNode);
81 /// Defines if the reader should process children of the given node
82 virtual bool processChildren(xmlNodePtr aNode);
83 /// check if dependencies of the given node are in the list of loaded modules
84 bool hasRequiredModules(xmlNodePtr aNode) const;
85 /// reads info about plugin's features from plugin xml description
86 std::list<std::string> importPlugin(const std::string& thePluginLibrary,
87 const std::string& thePluginFile);
88 /// stores information about plugin in the internal cache
89 std::string addPlugin(const std::string& aPluginLibrary,
90 const std::string& aPluginScript,
91 const std::string& aPluginConf);
92 /// Save feature in myFeaturesInFiles.
93 /// Generates an error if the feature name is already registered.
94 void addFeature(const std::string& theFeatureName, const std::string& thePluginConfig);
97 std::map<std::string, std::string> myFeaturesInFiles; ///< a feature name is key, a file is value
98 std::set<std::string> myPluginFiles; ///< a feature name is key, a file is value
99 /// a plugin name is key, a plugin type is value
100 static std::map<std::string, PluginType> myPluginTypes;
101 static std::set<std::string> myDependencyModules; ///< set of loaded modules
102 const char* myEventGenerated; ///< gives ability to send Feature_Messages to various listeners
105 #endif /* CONFIG_XMLMODULEREADER_H_ */