3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
8 * or modified under the Terms and Conditions of its License Agreement, which is found
9 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
10 * may change at any time. To view the latest information, see:
11 * http://www.sourcemod.net/license.php
16 #ifndef _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
17 #define _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
19 #include <IShareSys.h>
20 #include <ILibrarySys.h>
23 * @file IExtensionSys.h
24 * @brief Defines the interface for loading/unloading/managing extensions.
29 class IExtensionInterface;
30 typedef void * ITERATOR; /**< Generic pointer for dependency iterators */
33 * @brief Encapsulates an IExtensionInterface and its dependencies.
39 * @brief Returns whether or not the extension is properly loaded.
41 virtual bool IsLoaded() =0;
44 * @brief Returns the extension's API interface
46 * @return An IExtensionInterface pointer.
48 virtual IExtensionInterface *GetAPI() =0;
51 * @brief Returns the filename of the extension, relative to the
54 * @return A string containing the extension file name.
56 virtual const char *GetFilename() =0;
59 * @brief Returns the extension's identity token.
61 * @return An IdentityToken_t pointer.
63 virtual IdentityToken_t *GetIdentity() =0;
66 * @brief Retrieves the extension dependency list for this extension.
68 * @param pOwner Optional pointer to store the first interface's owner.
69 * @param pInterface Optional pointer to store the first interface.
70 * @return An ITERATOR pointer for the results, or NULL if no results at all.
72 virtual ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface) =0;
75 * @brief Finds the next dependency in the dependency list.
77 * @param iter Pointer to iterator from FindFirstDependency.
78 * @param pOwner Optional pointer to store the interface's owner.
79 * @param pInterface Optional pointer to store the interface.
80 * @return True if there are more results after this, false otherwise.
82 virtual bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface) =0;
85 * @brief Frees an ITERATOR handle from FindFirstDependency.
87 * @param iter Pointer to iterator to free.
89 virtual void FreeDependencyIterator(ITERATOR *iter) =0;
92 * @brief Queries the extension to see its run state.
94 * @param error Error buffer (may be NULL).
95 * @param maxlength Maximum length of buffer.
96 * @return True if extension is okay, false if not okay.
98 virtual bool IsRunning(char *error, size_t maxlength) =0;
102 * @brief Version code of the IExtensionInterface API itself.
104 #define SMINTERFACE_EXTENSIONAPI_VERSION 1
107 * @brief The interface an extension must expose.
109 class IExtensionInterface
112 /** Returns the interface API version */
113 virtual unsigned int GetExtensionVersion()
115 return SMINTERFACE_EXTENSIONAPI_VERSION;
119 * @brief Called when the extension is loaded.
121 * @param me Pointer back to extension.
122 * @param sys Pointer to interface sharing system of SourceMod.
123 * @param error Error buffer to print back to, if any.
124 * @param err_max Maximum size of error buffer.
125 * @param late If this extension was loaded "late" (i.e. manually).
126 * @return True if load should continue, false otherwise.
128 virtual bool OnExtensionLoad(IExtension *me,
135 * @brief Called when the extension is about to be unloaded.
137 virtual void OnExtensionUnload() =0;
140 * @brief Called when all extensions are loaded (loading cycle is done).
141 * If loaded late, this will be called right after OnExtensionLoad().
143 virtual void OnExtensionsAllLoaded() =0;
146 * @brief Called when your pause state is about to change.
148 * @param pause True if pausing, false if unpausing.
150 virtual void OnExtensionPauseChange(bool pause) =0;
153 * @brief Asks the extension whether it's safe to remove an external interface it's using.
154 * If it's not safe, return false, and the extension will be unloaded afterwards.
155 * NOTE: It is important to also hook NotifyInterfaceDrop() in order to clean up resources.
157 * @param pInterface Pointer to interface being dropped.
158 * @return True to continue, false to unload this extension afterwards.
160 virtual bool QueryInterfaceDrop(SMInterface *pInterface)
166 * @brief Notifies the extension that an external interface it uses is being removed.
168 * @param pInterface Pointer to interface being dropped.
170 virtual void NotifyInterfaceDrop(SMInterface *pInterface)
175 * @brief Return false to tell Core that your extension should be considered unsable.
177 * @param error Error buffer.
178 * @param maxlength Size of error buffer.
179 * @return True on success, false otherwise.
181 virtual bool QueryRunning(char *error, size_t maxlength)
186 virtual bool IsMetamodExtension() =0;
187 virtual const char *GetExtensionName() =0;
188 virtual const char *GetExtensionURL() =0;
189 virtual const char *GetExtensionTag() =0;
190 virtual const char *GetExtensionAuthor() =0;
191 virtual const char *GetExtensionVerString() =0;
192 virtual const char *GetExtensionDescription() =0;
193 virtual const char *GetExtensionDateString() =0;
196 #define SMINTERFACE_EXTENSIONMANAGER_NAME "IExtensionManager"
197 #define SMINTERFACE_EXTENSIONMANAGER_VERSION 1
200 * @brief Not currently used.
202 enum ExtensionLifetime
204 ExtLifetime_Forever, //Extension will never be unloaded automatically
205 ExtLifetime_Map, //Extension will be unloaded at the end of the map
209 * @brief Manages the loading/unloading of extensions.
211 class IExtensionManager : public SMInterface
214 virtual const char *GetInterfaceName()
216 return SMINTERFACE_EXTENSIONMANAGER_NAME;
218 virtual unsigned int GetInterfaceVersion()
220 return SMINTERFACE_EXTENSIONMANAGER_VERSION;
224 * @brief Loads a extension into the extension system.
226 * @param path Path to extension file, relative to the extensions folder.
227 * @param lifetime Lifetime of the extension (currently ignored).
228 * @param error Error buffer.
229 * @param err_max Maximum error buffer length.
230 * @return New IExtension on success, NULL on failure.
232 virtual IExtension *LoadExtension(const char *path,
233 ExtensionLifetime lifetime,
238 * @brief Attempts to unload a module.
240 * @param pExt IExtension pointer.
241 * @return True if successful, false otherwise.
243 virtual bool UnloadExtension(IExtension *pExt) =0;
247 #endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_