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 "dptr.h"
31 #include "global.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  #ifdef Q_OS_WIN32
71  static QString getDllWindowsErrorMessage();
72  #endif
73  private:
74  DPtr<Plugin> d;
75 
76  void unload();
77  };
78 
82  static void deinit();
92  static void init(const QStringList &directories);
100  static PluginLoader *instance();
101 
102  virtual ~PluginLoader();
103 
107  void clearPlugins();
108 
116  EnginePlugin *info(int pluginIndex) const;
117 
121  void initConfig();
122 
128  unsigned int numPlugins() const;
129 
138  int pluginIndexFromName(const QString &name) const;
139 
140  const QList<Plugin *> &plugins() const;
144  const Plugin *plugin(unsigned int index) const;
145 
150  void resetPluginsDirectory(const QString &pluginsDirectory);
151 
155  const Plugin *operator[] (unsigned int index) const;
156 
157 private:
159 
160  static PluginLoader *staticInstance;
161 
165  PluginLoader(unsigned int type, const QStringList &directories);
166 
167  bool filesInDir();
168 };
169 
170 #endif /* __PLUGINLOADER_HPP__ */
void resetPluginsDirectory(const QString &pluginsDirectory)
Resets the plugins directory, clearing the loaded plugins and getting new loaded plugins in the proce...
unsigned int numPlugins() const
Gets the number of loaded plugins.
const Plugin * plugin(unsigned int index) const
Returns the requested plugin or nullptr.
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.
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 nullptr.
Plugin(unsigned int type, QString file)
Inits a plugin.
Definition: dptr.h:54