BALL  1.4.1
 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_CONCEPT_PREFERENCESOBJECT_H
6 #endif
7 
8 #include <QtCore/QString>
9 #include <QtCore/QHash>
10 #include <QtCore/QMutex>
11 #include <QtCore/QReadWriteLock>
12 
13 #include <boost/shared_ptr.hpp>
14 
15 #include <list>
16 #include <map>
17 
18 class QPluginLoader;
19 class QObject;
20 
21 namespace BALL
22 {
23  class BALLPlugin;
24  class PluginHandler;
25 
34  : public PreferencesObject
35  {
36 
37  public:
38 
39  virtual ~PluginManager();
40 
46  static PluginManager& instance();
47 
54  void addPluginDirectory(const QString& dir, bool autoactivate = false);
55 
62  bool removePluginDirectory(const QString& dir);
63 
66  vector<QString> getPluginDirectories() const;
67 
76  BALLPlugin* loadPlugin(const QString& plugin_name);
77 
83  bool unloadPlugin(const QString& plugin);
84 
94  QObject* getPluginInstance(const QString& plugin);
95 
105  QObject* getPluginInstance(int pos);
106 
110  bool startPlugin(int plugin);
111 
115  bool startPlugin(const QString& plugin);
116 
126  bool startPlugin(BALLPlugin* plugin);
127 
131  bool stopPlugin(int plugin);
132 
136  bool stopPlugin(const QString& plugin);
137 
147  bool stopPlugin(BALLPlugin* plugin);
148 
151  void unloadAllPlugins();
152 
156  int getPluginCount() const;
157 
162  void registerHandler(PluginHandler* h);
163 
164  // needed for storing this classes' preferences
165  virtual bool getValue(String&) const;
166  virtual bool setValue(const String&);
167 
168  protected:
169  static const char* BETWEEN_PLUGINDIR_SEPERATOR;
170 
171  PluginManager();
173  const PluginManager& operator=(const PluginManager&);
174 
175  std::map<QString, vector<BALLPlugin*> > loaded_plugin_dirs_;
176 
177  QHash<QString, QPluginLoader*> loaders_;
178  std::list<PluginHandler*> handlers_;
179 
180  static boost::shared_ptr<PluginManager> manager_;
181 
182  //This mutex is used in the creation of the singleton
183  static QMutex mutex_;
184  //This mutex guards the handlers_ list
185  mutable QReadWriteLock handler_mutex_;
186  //This mutex guards the loaders_ list
187  mutable QReadWriteLock loader_mutex_;
188  };
189 }
190 
191 #endif //BALL_PLUGIN_PLUGINMANAGER_H
192