Salome HOME
updated copyright message
[modules/shaper.git] / src / Config / Config_ModuleReader.h
1 // Copyright (C) 2014-2023  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 map containing features, which have licensed.
53   /// The valid license should be confirmed first
54   /// (the feature is key, the file is value)
55   CONFIG_EXPORT const std::map<std::string, std::string>& proprietaryFeatures() const;
56   /// Returns proprietary plugins
57   CONFIG_EXPORT const std::set<std::string>& proprietaryPlugins() const;
58   /// Returns list of module's xml files
59   CONFIG_EXPORT const std::set<std::string>& modulePluginFiles() const;
60   /// Returns module name: an xml attribute from the root of the plugins.xml:
61   /// e.g \code <plugins module="PartSet"> \endcode
62   CONFIG_EXPORT std::string getModuleName();
63   /// Detects type of the given plugin and loads it using loadLibrary or loadScript.
64   CONFIG_EXPORT static void loadPlugin(const std::string& thePluginName);
65   /// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform
66   CONFIG_EXPORT static void loadLibrary(const std::string& theLibName);
67   /// loads the python module with specified name
68   /// \param theFileName name of the script
69   /// \param theSendErr send error message in case of faile
70   CONFIG_EXPORT static void loadScript(const std::string& theFileName, bool theSendErr = true);
71   /*!
72    * Extends set of modules,  used for dependency checking (if there is no
73    * required module in the set, a plugin will not be loaded)
74    */
75   CONFIG_EXPORT static void addDependencyModule(const std::string& theModuleName);
76
77  protected:
78   /// Recursively process the given xmlNode
79   virtual void processNode(xmlNodePtr aNode);
80   /// Defines if the reader should process children of the given node
81   virtual bool processChildren(xmlNodePtr aNode);
82   /// check if dependencies of the given node are in the list of loaded modules
83   bool hasRequiredModules(xmlNodePtr aNode) const;
84   /// reads info about plugin's features from plugin xml description
85   std::list<std::string> importPlugin(const std::string& thePluginLibrary,
86                                       const std::string& thePluginFile,
87                                       const std::string& thePluginDocSection);
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);
95   /// Save feature in myFeaturesRequireLicense.
96   /// Generates an error if the feature name is already registered.
97   void addFeatureRequireLicense(const std::string& theFeatureName,
98                                 const std::string& thePluginConfig);
99
100  private:
101   std::map<std::string, std::string> myFeaturesInFiles; ///< a feature name is key, a file is value
102   /// list of features, which need a license, and their config files
103   std::map<std::string, std::string> myProprietaryFeatures;
104   std::set<std::string> myPluginFiles; ///< a feature name is key, a file is value
105   /// a plugin name is key, a plugin type is value
106   static std::map<std::string, PluginType> myPluginTypes;
107   static std::set<std::string> myDependencyModules; ///< set of loaded modules
108   const char* myEventGenerated; ///< gives ability to send Feature_Messages to various listeners
109
110   std::set<std::string> myProprietaryPlugins; ///< list of plugins protected by license
111 };
112
113 #endif /* CONFIG_XMLMODULEREADER_H_ */