Control: Change controls to use new callback infrastrucure.
[gemrb.git] / gemrb / core / PluginMgr.h
blobff0d88cf7792ae4bac76dd9725402dd2e78aeb59
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 /**
22 * @file PluginMgr.h
23 * Declares PluginMgr, loader for GemRB plugins
24 * @author The GemRB Project
27 #ifndef PLUGINMGR_H
28 #define PLUGINMGR_H
30 #include "SClassID.h" // For PluginID
31 #include "exports.h"
32 #include "globals.h"
33 #include "iless.h"
34 #include "win32def.h"
36 #include "ResourceDesc.h"
38 #include <cstring>
39 #include <list>
40 #include <map>
41 #include <vector>
43 #ifdef WIN32
44 typedef HINSTANCE LibHandle;
45 #else
46 typedef void *LibHandle;
47 #endif
49 class Plugin;
50 class Resource;
51 class TypeID;
53 /**
54 * @class PluginMgr
55 * Class for loading GemRB plugins from shared libraries or DLLs.
56 * It goes over all appropriately named files in PluginPath directory
57 * and tries to load them one after another.
60 class GEM_EXPORT PluginMgr {
61 public:
62 typedef Resource* (*ResourceFunc)(DataStream*);
63 typedef Plugin* (*PluginFunc)();
64 public:
65 /** Return global instance of PluginMgr */
66 static PluginMgr* Get();
67 void LoadPlugins(char* pluginpath);
68 private:
69 PluginMgr();
70 public: // HACK: MSVC6 is buggy.
71 ~PluginMgr(void);
72 private:
73 struct PluginDesc {
74 LibHandle handle;
75 PluginID ID;
76 const char *Description;
77 bool (*Register)(PluginMgr*);
79 std::map< PluginID, PluginDesc> libs;
80 std::map< SClass_ID, PluginFunc> plugins;
81 std::map< const TypeID*, std::vector<ResourceDesc> > resources;
82 /** Array of initializer functions */
83 std::vector<void (*)(void)> intializerFunctions;
84 /** Array of cleanup functions */
85 std::vector<void (*)(void)> cleanupFunctions;
86 typedef std::map<const char*, PluginFunc, iless> driver_map;
87 std::map<const TypeID*, driver_map> drivers;
88 public:
89 /** Return names of all *.so or *.dll files in the given directory */
90 bool FindFiles( char* path, std::list< char* > &files);
91 bool IsAvailable(SClass_ID plugintype) const;
92 Plugin* GetPlugin(SClass_ID plugintype) const;
94 size_t GetPluginCount() const { return plugins.size(); }
96 /**
97 * Register class plugin.
99 * @param[in] id ID used to access plugin.
100 * @param[in] create Function to create instance of plugin.
102 bool RegisterPlugin(SClass_ID id, PluginFunc create);
104 * Register resource.
106 * @param[in] type Base class for resource.
107 * @param[in] create Function to create resource from a stream.
108 * @param[in] ext Extension used for resource files.
109 * @param[in] keyType \iespecific Type identifier used in key/biff files.
111 void RegisterResource(const TypeID* type, ResourceFunc create, const char *ext, ieWord keyType = 0);
113 const std::vector<ResourceDesc>& GetResourceDesc(const TypeID*);
116 * Registers a static intializer.
118 * @param[in] init Function to call on startup.
120 void RegisterInitializer(void (*init)(void));
122 * Registers a static cleanup.
124 * @param[in] cleanup Function to call on shutdown.
126 void RegisterCleanup(void (*cleanup)(void));
128 /** Run intializer functions. */
129 void RunInitializers() const;
130 /** Run cleanup functions */
131 void RunCleanup() const;
134 * Registers a driver plugin
136 * @param[in] type Base class for driver.
137 * @param[in] name Name of driver.
138 * @param[in] create Function to create instance of plugin.
140 bool RegisterDriver(const TypeID* type, const char* name, PluginFunc create);
143 * Gets driver of specified type.
145 * @param[in] type Base class for driver.
146 * @param[in] name Name of driver.
148 * Tries to get driver associated to name, or falls back to a random one.
150 Plugin* GetDriver(const TypeID* type, const char* name);
153 #endif