Salome HOME
655a6ca7a91649143313eb953843cc163b8ae1fa
[modules/shaper.git] / src / Config / Config_ModuleReader.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * Config_XMLModuleReader.h
5  *
6  *  Created on: Mar 20, 2014
7  *      Author: sbh
8  */
9
10 #ifndef CONFIG_MODULEREADER_H_
11 #define CONFIG_MODULEREADER_H_
12
13 #include <Config_def.h>
14 #include <Config_XMLReader.h>
15
16 #include <map>
17 #include <list>
18 #include <set>
19 #include <string>
20
21 /*!
22  * \class Config_ModuleReader
23  * \brief Class to process plugins.xml - definition of plugins (scripts, libraries).
24  */
25 class Config_ModuleReader : public Config_XMLReader
26 {
27   enum PluginType {
28     Binary = 0,
29     Intrenal = 1,
30     Python = 2
31   };
32
33  public:
34   /// Constructor
35   CONFIG_EXPORT Config_ModuleReader(const char* theEventGenerated = 0);
36   /// Destructor
37   CONFIG_EXPORT virtual ~Config_ModuleReader();
38   /// Returns map that describes which file contains a feature (the feature is key, the file is value)
39   CONFIG_EXPORT const std::map<std::string, std::string>& featuresInFiles() const;
40   /// Returns module name: an xml attribute from the root of the plugins.xml:
41   /// e.g <plugins module="PartSet">
42   CONFIG_EXPORT std::string getModuleName();
43   /// Detects type of the given plugin and loads it using loadLibrary or loadScript.
44   CONFIG_EXPORT static void loadPlugin(const std::string& thePluginName);
45   /// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform
46   CONFIG_EXPORT static void loadLibrary(const std::string& theLibName);
47   /// loads the python module with specified name
48   CONFIG_EXPORT static void loadScript(const std::string& theFileName);
49   /*!
50    * Extends set of modules,  used for dependency checking (if there is no
51    * required module in the set, a plugin will not be loaded)
52    */
53   CONFIG_EXPORT static void addDependencyModule(const std::string& theModuleName);
54
55  protected:
56   /// Recursively process the given xmlNode
57   virtual void processNode(xmlNodePtr aNode);
58   /// Defines if the reader should process children of the given node
59   virtual bool processChildren(xmlNodePtr aNode);
60   /// check if dependencies of the given node are in the list of loaded modules
61   bool hasRequiredModules(xmlNodePtr aNode) const;
62   /// reads info about plugin's features from plugin xml description
63   std::list<std::string> importPlugin(const std::string& thePluginLibrary,
64                                       const std::string& thePluginFile);
65   /// stores information about plugin in the internal cache
66   std::string addPlugin(const std::string& aPluginLibrary,
67                         const std::string& aPluginScript,
68                         const std::string& aPluginConf);
69
70  private:
71   std::map<std::string, std::string> myFeaturesInFiles; ///< a feature name is key, a file is value
72   static std::map<std::string, PluginType> myPluginTypes; ///< a plugin name is key, a plugin type is value
73   static std::set<std::string> myDependencyModules; ///< set of loaded modules
74   const char* myEventGenerated; ///< gives ability to send Feature_Messages to various listeners
75 };
76
77 #endif /* CONFIG_XMLMODULEREADER_H_ */