pluginloader.h
1 //------------------------------------------------------------------------------
2 // pluginloader.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2011 Braden "Blzut3" Obrzut <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 
24 #ifndef __PLUGINLOADER_H__
25 #define __PLUGINLOADER_H__
26 
27 #include <QList>
28 #include <QString>
29 
30 #include "global.h"
31 #include "dptr.h"
32 
33 #define gPlugins (PluginLoader::instance())
34 
35 class EnginePlugin;
36 
38 {
39  public:
44  class Plugin
45  {
46  public:
56  Plugin(unsigned int type, QString file);
57  virtual ~Plugin();
58 
62  void *function(const char* func) const;
63  void initConfig();
64  bool isValid() const;
68  EnginePlugin *info() const;
69 
70  private:
71  DPtr<Plugin> d;
72 
73  void unload();
74  };
75 
79  static void deinit();
89  static void init(const QStringList &directories);
97  static PluginLoader *instance();
98 
99  virtual ~PluginLoader();
100 
104  void clearPlugins();
105 
113  EnginePlugin *info(int pluginIndex) const;
114 
118  void initConfig();
119 
125  const unsigned int numPlugins() const;
126 
135  int pluginIndexFromName(const QString& name) const;
136 
137  const QList<Plugin*> &plugins() const;
141  const Plugin* plugin(unsigned int index) const;
142 
147  void resetPluginsDirectory(const QString& pluginsDirectory);
148 
152  const Plugin* operator[] (unsigned int index) const;
153 
154  private:
156 
157  static PluginLoader *staticInstance;
158 
162  PluginLoader(unsigned int type, const QStringList &directories);
163 
164  bool filesInDir();
165 };
166 
167 #endif /* __PLUGINLOADER_HPP__ */
void resetPluginsDirectory(const QString &pluginsDirectory)
Resets the plugins directory, clearing the loaded plugins and getting new loaded plugins in the proce...
const Plugin * plugin(unsigned int index) const
Returns the requested plugin or NULL.
void clearPlugins()
Clears the plugins list.
int pluginIndexFromName(const QString &name) const
Looks for a plugin which name equals to parameter.
static void deinit()
Destroys the init() instance.
static void init(const QStringList &directories)
Attempts to load plugins from given set of directories.
const unsigned int numPlugins() const
Gets the number of loaded plugins.
static PluginLoader * instance()
Accesses instance of the class after init().
EnginePlugin * info() const
Main plugin interface.
const Plugin * operator[](unsigned int index) const
Returns the requested plugin or NULL.
Plugin(unsigned int type, QString file)
Inits a plugin.
Definition: dptr.h:54