Tellurium Plugin C++ API  1.0.0
 All Classes Files Functions Variables Friends Pages
telPluginManager.h
Go to the documentation of this file.
1 
41 #ifndef telPluginManagerH
42 #define telPluginManagerH
43 #include <vector>
44 #include <string>
45 #include <sstream>
46 #include <ostream>
47 #include "telCoreExporter.h"
48 #include "telConstants.h"
49 #include "telStringList.h"
50 #include "Poco/SharedLibrary.h"
51 
52 //---------------------------------------------------------------------------
53 /* A minimalistic Plugin manager. */
54 
55 namespace tlp
56 {
57 
58 using std::stringstream;
59 using std::string;
60 using std::vector;
61 using std::pair;
62 using std::ostream;
63 using tlp::gEmptyString;
64 
65 //using tlp::StringList;
66 using Poco::SharedLibrary;
67 
68 class Plugin;
69 
73 typedef pair< Poco::SharedLibrary*, Plugin* > telPlugin;
74 
85 class CORE_DECLSPEC PluginManager
86 {
87  public:
94  PluginManager(const string& pluginFolder = gEmptyString);
98  virtual ~PluginManager();
99 
105  string getInfo() const;
106 
112  bool setPluginDir(const string& dir);
113 
118  string getPluginDir() const;
119 
124  int load(const string& pluginName = gEmptyString);
125 
130  bool unload(Plugin* plugin = NULL);
131 
135  int getNumberOfPlugins() const;
136 
141  int getNumberOfCategories() const;
142 
149  Plugin* getFirstPlugin() const;
150 
156  Plugin* getNextPlugin() const;
157 
163  Plugin* getPreviousPlugin() const;
164 
169  Plugin* getCurrentPlugin() const;
170 
176  Plugin* getPlugin(const string& name) const;
177 
182  tlp::StringList getPluginNames() const;
183 
188  tlp::StringList getPluginLibraryNames() const;
189 
193  CORE_DECLSPEC
194  friend ostream& operator<<(ostream& os, PluginManager& pm);
195 
199  Plugin* operator[](const int& i);
200 
201  bool hasLoadErrors() const;
202  string getLoadErrors() const;
203 
204  private:
205  string mPluginFolder;
206  string mPluginExtension; //Different on different OS's
207  string mPluginPrefix; //Different on different OS's
208  stringstream mLoadPluginErrors; //Accumulated load errors
209  mutable vector< telPlugin > mPlugins;
210  mutable vector< telPlugin >::iterator mPluginsIter;
211 
212  bool loadPlugin(const string& sharedLib);
213  bool checkImplementationLanguage(SharedLibrary* plugin);
214  const char* getImplementationLanguage(SharedLibrary* plugin);
215  Plugin* createCPlugin(SharedLibrary *libHandle);
216  Plugin* getPlugin(const int& i);
217  bool unloadAll();
218  void clearLoadErrors();
219 };
220 
221 }
222 #endif
223