pluginManager.h

Go to the documentation of this file.
00001 #ifndef BALL_PLUGIN_PLUGINMANAGER_H
00002 #define BALL_PLUGIN_PLUGINMANAGER_H
00003 
00004 #ifndef BALL_CONCEPT_PREFERENCESOBJECT_H
00005 # include <BALL/CONCEPT/preferencesObject.h>
00006 #endif
00007 
00008 #include <QtCore/QString>
00009 #include <QtCore/QHash>
00010 #include <QtCore/QMutex>
00011 #include <QtCore/QReadWriteLock>
00012 
00013 #include <boost/shared_ptr.hpp>
00014 
00015 #include <list>
00016 #include <map>
00017 
00018 class QPluginLoader;
00019 class QObject;
00020 
00021 namespace BALL
00022 {
00023   class BALLPlugin;
00024   class PluginHandler;
00025 
00033   class BALL_EXPORT PluginManager
00034     : public PreferencesObject
00035   {
00036     
00037     public: 
00038 
00039       virtual ~PluginManager();
00040 
00046       static PluginManager& instance();
00047 
00054       void addPluginDirectory(const QString& dir, bool autoactivate = false);
00055       
00062       bool removePluginDirectory(const QString& dir);
00063 
00066       vector<QString> getPluginDirectories() const;
00067 
00076       BALLPlugin* loadPlugin(const QString& plugin_name);
00077 
00083       bool unloadPlugin(const QString& plugin);
00084 
00094       QObject* getPluginInstance(const QString& plugin);
00095 
00105       QObject* getPluginInstance(int pos);
00106 
00110       bool startPlugin(int plugin);
00111 
00115       bool startPlugin(const QString& plugin);
00116 
00126       bool startPlugin(BALLPlugin* plugin);
00127 
00131       bool stopPlugin(int plugin);
00132 
00136       bool stopPlugin(const QString& plugin);
00137 
00147       bool stopPlugin(BALLPlugin* plugin);
00148 
00151       void unloadAllPlugins();
00152 
00156       int getPluginCount() const;
00157 
00162       void registerHandler(PluginHandler* h);
00163   
00164       // needed for storing this classes' preferences
00165       virtual bool getValue(String&) const;
00166       virtual bool setValue(const String&);
00167 
00168     protected: 
00169       static const char* BETWEEN_PLUGINDIR_SEPERATOR;
00170 
00171       PluginManager();
00172       PluginManager(const PluginManager&);
00173       const PluginManager& operator=(const PluginManager&);
00174 
00175       std::map<QString, vector<BALLPlugin*> > loaded_plugin_dirs_;
00176       
00177       QHash<QString, QPluginLoader*> loaders_;
00178       std::list<PluginHandler*> handlers_;
00179 
00180       static boost::shared_ptr<PluginManager> manager_;
00181 
00182       //This mutex is used in the creation of the singleton
00183       static QMutex mutex_;
00184       //This mutex guards the handlers_ list
00185       mutable QReadWriteLock handler_mutex_;
00186       //This mutex guards the loaders_ list
00187       mutable QReadWriteLock loader_mutex_;
00188   };
00189 }
00190 
00191 #endif //BALL_PLUGIN_PLUGINMANAGER_H
00192