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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef CONFIG_MODULEREADER_H_
22 #define CONFIG_MODULEREADER_H_
24 #include <Config_def.h>
25 #include <Config_XMLReader.h>
33 * \class Config_ModuleReader
35 * \brief Class to process plugins.xml - definition of plugins (scripts, libraries).
37 class Config_ModuleReader : public Config_XMLReader
47 CONFIG_EXPORT Config_ModuleReader(const char* theEventGenerated = 0);
49 CONFIG_EXPORT virtual ~Config_ModuleReader();
50 /// Returns map that describes which file contains a feature
51 /// (the feature is key, the file is value)
52 CONFIG_EXPORT const std::map<std::string, std::string>& featuresInFiles() const;
53 /// Returns list of module's xml files
54 CONFIG_EXPORT const std::set<std::string>& modulePluginFiles() const;
55 /// Returns module name: an xml attribute from the root of the plugins.xml:
56 /// e.g \code <plugins module="PartSet"> \endcode
57 CONFIG_EXPORT std::string getModuleName();
58 /// Detects type of the given plugin and loads it using loadLibrary or loadScript.
59 CONFIG_EXPORT static void loadPlugin(const std::string& thePluginName);
60 /// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform
61 CONFIG_EXPORT static void loadLibrary(const std::string& theLibName);
62 /// loads the python module with specified name
63 /// \param theFileName name of the script
64 /// \param theSendErr send error message in case of faile
65 CONFIG_EXPORT static void loadScript(const std::string& theFileName, bool theSendErr = true);
67 * Extends set of modules, used for dependency checking (if there is no
68 * required module in the set, a plugin will not be loaded)
70 CONFIG_EXPORT static void addDependencyModule(const std::string& theModuleName);
73 /// Recursively process the given xmlNode
74 virtual void processNode(xmlNodePtr aNode);
75 /// Defines if the reader should process children of the given node
76 virtual bool processChildren(xmlNodePtr aNode);
77 /// check if dependencies of the given node are in the list of loaded modules
78 bool hasRequiredModules(xmlNodePtr aNode) const;
79 /// reads info about plugin's features from plugin xml description
80 std::list<std::string> importPlugin(const std::string& thePluginLibrary,
81 const std::string& thePluginFile);
82 /// stores information about plugin in the internal cache
83 std::string addPlugin(const std::string& aPluginLibrary,
84 const std::string& aPluginScript,
85 const std::string& aPluginConf);
86 /// Save feature in myFeaturesInFiles.
87 /// Generates an error if the feature name is already registered.
88 void addFeature(const std::string& theFeatureName, const std::string& thePluginConfig);
91 std::map<std::string, std::string> myFeaturesInFiles; ///< a feature name is key, a file is value
92 std::set<std::string> myPluginFiles; ///< a feature name is key, a file is value
93 /// a plugin name is key, a plugin type is value
94 static std::map<std::string, PluginType> myPluginTypes;
95 static std::set<std::string> myDependencyModules; ///< set of loaded modules
96 const char* myEventGenerated; ///< gives ability to send Feature_Messages to various listeners
99 #endif /* CONFIG_XMLMODULEREADER_H_ */