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 <QMap>
29 #include <QString>
30 
31 #include "dptr.h"
32 #include "global.h"
33 
34 #define gPlugins (PluginLoader::instance())
35 
36 class EnginePlugin;
37 
39 {
40 public:
45  class Plugin
46  {
47  public:
57  Plugin(unsigned int type, QString file);
58  virtual ~Plugin();
59 
63  void *function(const char *func) const;
64  void initConfig();
65  bool isValid() const;
69  EnginePlugin *info() const;
70 
71  private:
72  DPtr<Plugin> d;
73 
74  void unload();
75  };
76 
80  static void deinit();
97  static void init(const QStringList &directories,
98  const QMap<QString, bool> &pluginsEnabled);
106  static PluginLoader *instance();
107 
108  virtual ~PluginLoader();
109 
113  void clearPlugins();
114 
122  EnginePlugin *info(int pluginIndex) const;
123 
127  void initConfig();
128 
134  unsigned int numPlugins() const;
135 
144  int pluginIndexFromName(const QString &name) const;
145 
146  const QList<Plugin *> &plugins() const;
150  const Plugin *plugin(unsigned int index) const;
151 
156  void resetPluginsDirectory(const QString &pluginsDirectory);
157 
161  const Plugin *operator[] (unsigned int index) const;
162 
163 private:
165 
166  static PluginLoader *staticInstance;
167 
168  PluginLoader(unsigned int type, const QStringList &directories,
169  const QMap<QString, bool> &pluginsEnabled);
170 
171  bool filesInDir();
172 };
173 
174 #endif /* __PLUGINLOADER_HPP__ */