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.
23 * Declares PluginMgr, loader for GemRB plugins
24 * @author The GemRB Project
30 #include "SClassID.h" // For PluginID
36 #include "ResourceDesc.h"
44 typedef HINSTANCE LibHandle
;
46 typedef void *LibHandle
;
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
{
62 typedef Resource
* (*ResourceFunc
)(DataStream
*);
63 typedef Plugin
* (*PluginFunc
)();
65 /** Return global instance of PluginMgr */
66 static PluginMgr
* Get();
67 void LoadPlugins(char* pluginpath
);
70 public: // HACK: MSVC6 is buggy.
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
;
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(); }
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
);
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
);