BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
pluginManager.h
Go to the documentation of this file.
1 #ifndef BALL_PLUGIN_PLUGINMANAGER_H
2 #define BALL_PLUGIN_PLUGINMANAGER_H
3 
4 #ifndef BALL_COMMON_GLOBAL_H
5 # include <BALL/COMMON/global.h>
6 #endif
7 
8 #ifndef BALL_DATATYPE_STRING_H
9 # include <BALL/DATATYPE/string.h>
10 #endif
11 
12 #include <QtCore/QString>
13 #include <QtCore/QStringList>
14 #include <QtCore/QHash>
15 #include <QtCore/QMutex>
16 #include <QtCore/QReadWriteLock>
17 
18 #include <boost/shared_ptr.hpp>
19 
20 #include <list>
21 #include <map>
22 
23 class QPluginLoader;
24 class QObject;
25 
26 namespace BALL
27 {
28  class BALLPlugin;
29  class PluginHandler;
30 
39  {
40  public:
41 
42  virtual ~PluginManager();
43 
49  static PluginManager& instance();
50 
59  bool addPluginDirectory(const QString& dir);
60 
68  bool removePluginDirectory(const QString& dir);
69 
72  std::vector<QString> getPluginDirectories() const;
73 
82  BALLPlugin* loadPlugin(const QString& plugin_name);
83 
89  bool unloadPlugin(const QString& plugin);
90 
100  QObject* getPluginInstance(const QString& plugin);
101 
111  QObject* getPluginInstance(int pos);
112 
116  bool startPlugin(int plugin);
117 
121  bool startPlugin(const QString& plugin);
122 
132  bool startPlugin(BALLPlugin* plugin);
133 
137  bool stopPlugin(int plugin);
138 
142  bool stopPlugin(const QString& plugin);
143 
153  bool stopPlugin(BALLPlugin* plugin);
154 
157  void unloadAllPlugins();
158 
162  int getPluginCount() const;
163 
168  void registerHandler(PluginHandler* h);
169 
178  void registerHandler(boost::shared_ptr<PluginHandler> h);
179 
198  bool unregisterHandler(PluginHandler* h);
199 
200  // needed for storing this classes' preferences
201  virtual bool getPluginDirectories(String& value) const;
202  virtual bool setPluginDirectories(const String&);
203 
204  virtual QString getAutoActivatePlugins() const;
205  virtual bool setAutoActivatePlugins(const QString&);
206 
207  void autoActivatePlugin(const QString& str);
208  void doNotAutoActivatePlugin(const QString& str);
209 
210  protected:
211  static const char* BETWEEN_PLUGINDIR_SEPERATOR;
212 
213  typedef std::map<QString, vector<BALLPlugin*> > PluginDirMap;
214 
215  PluginManager();
217  PluginManager& operator=(const PluginManager&);
218 
219  bool unloadDirectoryPlugins_(PluginDirMap::iterator it);
221 
222  QHash<QString, QPluginLoader*> loaders_;
223  std::list<PluginHandler*> handlers_;
224  std::list<boost::shared_ptr<PluginHandler> > shared_handlers_;
225 
227 
228  static boost::shared_ptr<PluginManager> manager_;
229 
230  //This mutex is used in the creation of the singleton
231  static QMutex mutex_;
232  //This mutex guards the handlers_ list
233  mutable QReadWriteLock handler_mutex_;
234  //This mutex guards the loaders_ list
235  mutable QReadWriteLock loader_mutex_;
236  };
237 }
238 
239 #endif //BALL_PLUGIN_PLUGINMANAGER_H
QHash< QString, QPluginLoader * > loaders_
QStringList autoactivate_plugins_
BALL_EXTERN_VARIABLE const double h
Definition: constants.h:102
static QMutex mutex_
QReadWriteLock handler_mutex_
static const char * BETWEEN_PLUGINDIR_SEPERATOR
QReadWriteLock loader_mutex_
PluginDirMap loaded_plugin_dirs_
std::list< boost::shared_ptr< PluginHandler > > shared_handlers_
std::list< PluginHandler * > handlers_
#define BALL_EXPORT
Definition: COMMON/global.h:50
std::map< QString, vector< BALLPlugin * > > PluginDirMap
static boost::shared_ptr< PluginManager > manager_