Salome HOME
d65d413f48ec934f5fd7fce5d93bf76fb9aa37d8
[modules/shaper.git] / src / Config / Config_ModuleReader.h
1 // Copyright (C) 2014-2020  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef CONFIG_MODULEREADER_H_
21 #define CONFIG_MODULEREADER_H_
22
23 #include <Config_def.h>
24 #include <Config_XMLReader.h>
25
26 #include <map>
27 #include <list>
28 #include <set>
29 #include <string>
30
31 /*!
32  * \class Config_ModuleReader
33  * \ingroup Config
34  * \brief Class to process plugins.xml - definition of plugins (scripts, libraries).
35  */
36 class Config_ModuleReader : public Config_XMLReader
37 {
38   enum PluginType {
39     Binary = 0,
40     Intrenal = 1,
41     Python = 2
42   };
43
44  public:
45   /// Constructor
46   CONFIG_EXPORT Config_ModuleReader(const char* theEventGenerated = 0);
47   /// Destructor
48   CONFIG_EXPORT virtual ~Config_ModuleReader();
49   /// Returns map that describes which file contains a feature
50   /// (the feature is key, the file is value)
51   CONFIG_EXPORT const std::map<std::string, std::string>& featuresInFiles() const;
52   /// Returns list of module's xml files
53   CONFIG_EXPORT const std::set<std::string>& modulePluginFiles() const;
54   /// Returns module name: an xml attribute from the root of the plugins.xml:
55   /// e.g \code <plugins module="PartSet"> \endcode
56   CONFIG_EXPORT std::string getModuleName();
57   /// Detects type of the given plugin and loads it using loadLibrary or loadScript.
58   CONFIG_EXPORT static void loadPlugin(const std::string& thePluginName);
59   /// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform
60   CONFIG_EXPORT static void loadLibrary(const std::string& theLibName);
61   /// loads the python module with specified name
62   /// \param theFileName name of the script
63   /// \param theSendErr send error message in case of faile
64   CONFIG_EXPORT static void loadScript(const std::string& theFileName, bool theSendErr = true);
65   /*!
66    * Extends set of modules,  used for dependency checking (if there is no
67    * required module in the set, a plugin will not be loaded)
68    */
69   CONFIG_EXPORT static void addDependencyModule(const std::string& theModuleName);
70
71  protected:
72   /// Recursively process the given xmlNode
73   virtual void processNode(xmlNodePtr aNode);
74   /// Defines if the reader should process children of the given node
75   virtual bool processChildren(xmlNodePtr aNode);
76   /// check if dependencies of the given node are in the list of loaded modules
77   bool hasRequiredModules(xmlNodePtr aNode) const;
78   /// reads info about plugin's features from plugin xml description
79   std::list<std::string> importPlugin(const std::string& thePluginLibrary,
80                                       const std::string& thePluginFile);
81   /// stores information about plugin in the internal cache
82   std::string addPlugin(const std::string& aPluginLibrary,
83                         const std::string& aPluginScript,
84                         const std::string& aPluginConf);
85   /// Save feature in myFeaturesInFiles.
86   /// Generates an error if the feature name is already registered.
87   void addFeature(const std::string& theFeatureName, const std::string& thePluginConfig);
88
89  private:
90   std::map<std::string, std::string> myFeaturesInFiles; ///< a feature name is key, a file is value
91   std::set<std::string> myPluginFiles; ///< a feature name is key, a file is value
92   /// a plugin name is key, a plugin type is value
93   static std::map<std::string, PluginType> myPluginTypes;
94   static std::set<std::string> myDependencyModules; ///< set of loaded modules
95   const char* myEventGenerated; ///< gives ability to send Feature_Messages to various listeners
96 };
97
98 #endif /* CONFIG_XMLMODULEREADER_H_ */