src/core/plugins/pluginloader.h
00001 //------------------------------------------------------------------------------
00002 // pluginloader.h
00003 //------------------------------------------------------------------------------
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018 // 02110-1301, USA.
00019 //
00020 //------------------------------------------------------------------------------
00021 // Copyright (C) 2011 "Blzut3" <admin@maniacsvault.net>
00022 //------------------------------------------------------------------------------ 
00023 
00024 #ifndef __PLUGINLOADER_H__
00025 #define __PLUGINLOADER_H__
00026 
00027 #include <QList>
00028 #include <QString>
00029 
00030 #include "global.h"
00031 
00032 #ifdef Q_OS_WIN32
00033 #include <windows.h>
00034 
00035 #ifdef _MSC_VER
00036 #pragma warning(disable: 4251)
00037 #endif
00038 
00039 #endif
00040 
00041 class EnginePlugin;
00042 
00043 class MAIN_EXPORT PluginLoader
00044 {
00045         public:
00050                 class MAIN_EXPORT Plugin
00051                 {
00052                         public:
00057                                 Plugin(unsigned int type, QString file);
00058                                 ~Plugin();
00059 
00063                                 void    *function(const char* func) const;
00064 
00065                                 void    initConfig();
00066 
00067                                 bool    isValid() const { return library != NULL; }
00068 
00069                                 const EnginePlugin      *info;
00070 
00071                         private:
00072                                 void    unload();
00073 
00074                                 QString file;
00075 
00076                 #ifdef Q_OS_WIN32
00077                                 HMODULE         library;
00078                 #else
00079                                 void            *library;
00080                 #endif
00081                 };
00082 
00087                 PluginLoader(unsigned int type, const QStringList &baseDirectories, const char* directory, int directoryLength=-1);
00088                 ~PluginLoader();
00089 
00093                 void clearPlugins();
00094 
00098                 void initConfig();
00099 
00103                 const unsigned int numPlugins() const;
00104 
00111                 int pluginIndexFromName(const QString& name) const;
00112 
00116                 void resetPluginsDirectory(const QString& pluginsDirectory);
00117 
00121                 const Plugin* operator[] (unsigned int index) const;
00122 
00123         private:
00124                 bool    filesInDir();
00125 
00126                 unsigned int            type;
00127                 QString                         pluginsDirectory;
00128                 QList<Plugin *>         pluginsList;
00129 };
00130 
00131 #endif /* __PLUGINLOADER_HPP__ */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator