3 * ===============================================================
4 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC.
6 * ===============================================================
8 * This file is part of the SourceMod/SourcePawn SDK. This file may only be
9 * used or modified under the Terms and Conditions of its License Agreement,
10 * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
11 * works must be licensed under the GNU General Public License (version 2 or
12 * greater). A copy of the GPL is included under public/licenses/GPL.txt.
14 * To view the latest information, see: http://www.sourcemod.net/license.php
19 #ifndef _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
20 #define _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
22 #include <IShareSys.h>
23 #include <ILibrarySys.h>
26 * @file IExtensionSys.h
27 * @brief Defines the interface for loading/unloading/managing extensions.
32 class IExtensionInterface;
33 typedef void * ITERATOR; /**< Generic pointer for dependency iterators */
36 * @brief Encapsulates an IExtensionInterface and its dependencies.
42 * @brief Returns whether or not the extension is properly loaded.
44 virtual bool IsLoaded() =0;
47 * @brief Returns the extension's API interface
49 * @return An IExtensionInterface pointer.
51 virtual IExtensionInterface *GetAPI() =0;
54 * @brief Returns the filename of the extension, relative to the
57 * @return A string containing the extension file name.
59 virtual const char *GetFilename() =0;
62 * @brief Returns the extension's identity token.
64 * @return An IdentityToken_t pointer.
66 virtual IdentityToken_t *GetIdentity() =0;
69 * @brief Retrieves the extension dependency list for this extension.
71 * @param pOwner Optional pointer to store the first interface's owner.
72 * @param pInterface Optional pointer to store the first interface.
73 * @return An ITERATOR pointer for the results, or NULL if no results at all.
75 virtual ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface) =0;
78 * @brief Finds the next dependency in the dependency list.
80 * @param iter Pointer to iterator from FindFirstDependency.
81 * @param pOwner Optional pointer to store the interface's owner.
82 * @param pInterface Optional pointer to store the interface.
83 * @return True if there are more results after this, false otherwise.
85 virtual bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface) =0;
88 * @brief Frees an ITERATOR handle from FindFirstDependency.
90 * @param iter Pointer to iterator to free.
92 virtual void FreeDependencyIterator(ITERATOR *iter) =0;
95 * @brief Queries the extension to see its run state.
97 * @param error Error buffer (may be NULL).
98 * @param maxlength Maximum length of buffer.
99 * @return True if extension is okay, false if not okay.
101 virtual bool IsRunning(char *error, size_t maxlength) =0;
105 * @brief Version code of the IExtensionInterface API itself.
107 #define SMINTERFACE_EXTENSIONAPI_VERSION 1
110 * @brief The interface an extension must expose.
112 class IExtensionInterface
115 /** Returns the interface API version */
116 virtual unsigned int GetExtensionVersion()
118 return SMINTERFACE_EXTENSIONAPI_VERSION;
122 * @brief Called when the extension is loaded.
124 * @param me Pointer back to extension.
125 * @param sys Pointer to interface sharing system of SourceMod.
126 * @param error Error buffer to print back to, if any.
127 * @param err_max Maximum size of error buffer.
128 * @param late If this extension was loaded "late" (i.e. manually).
129 * @return True if load should continue, false otherwise.
131 virtual bool OnExtensionLoad(IExtension *me,
138 * @brief Called when the extension is about to be unloaded.
140 virtual void OnExtensionUnload() =0;
143 * @brief Called when all extensions are loaded (loading cycle is done).
144 * If loaded late, this will be called right after OnExtensionLoad().
146 virtual void OnExtensionsAllLoaded() =0;
149 * @brief Called when your pause state is about to change.
151 * @param pause True if pausing, false if unpausing.
153 virtual void OnExtensionPauseChange(bool pause) =0;
156 * @brief Asks the extension whether it's safe to remove an external interface it's using.
157 * If it's not safe, return false, and the extension will be unloaded afterwards.
158 * NOTE: It is important to also hook NotifyInterfaceDrop() in order to clean up resources.
160 * @param pInterface Pointer to interface being dropped.
161 * @return True to continue, false to unload this extension afterwards.
163 virtual bool QueryInterfaceDrop(SMInterface *pInterface)
169 * @brief Notifies the extension that an external interface it uses is being removed.
171 * @param pInterface Pointer to interface being dropped.
173 virtual void NotifyInterfaceDrop(SMInterface *pInterface)
178 * @brief Return false to tell Core that your extension should be considered unsable.
180 * @param error Error buffer.
181 * @param maxlength Size of error buffer.
182 * @return True on success, false otherwise.
184 virtual bool QueryRunning(char *error, size_t maxlength)
189 virtual bool IsMetamodExtension() =0;
190 virtual const char *GetExtensionName() =0;
191 virtual const char *GetExtensionURL() =0;
192 virtual const char *GetExtensionTag() =0;
193 virtual const char *GetExtensionAuthor() =0;
194 virtual const char *GetExtensionVerString() =0;
195 virtual const char *GetExtensionDescription() =0;
196 virtual const char *GetExtensionDateString() =0;
199 #define SMINTERFACE_EXTENSIONMANAGER_NAME "IExtensionManager"
200 #define SMINTERFACE_EXTENSIONMANAGER_VERSION 1
203 * @brief Not currently used.
205 enum ExtensionLifetime
207 ExtLifetime_Forever, //Extension will never be unloaded automatically
208 ExtLifetime_Map, //Extension will be unloaded at the end of the map
212 * @brief Manages the loading/unloading of extensions.
214 class IExtensionManager : public SMInterface
217 virtual const char *GetInterfaceName()
219 return SMINTERFACE_EXTENSIONMANAGER_NAME;
221 virtual unsigned int GetInterfaceVersion()
223 return SMINTERFACE_EXTENSIONMANAGER_VERSION;
227 * @brief Loads a extension into the extension system.
229 * @param path Path to extension file, relative to the extensions folder.
230 * @param lifetime Lifetime of the extension (currently ignored).
231 * @param error Error buffer.
232 * @param err_max Maximum error buffer length.
233 * @return New IExtension on success, NULL on failure.
235 virtual IExtension *LoadExtension(const char *path,
236 ExtensionLifetime lifetime,
241 * @brief Attempts to unload a module.
243 * @param pExt IExtension pointer.
244 * @return True if successful, false otherwise.
246 virtual bool UnloadExtension(IExtension *pExt) =0;
250 #endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_