2 * ===============================================================
3 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
4 * ===============================================================
6 * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
7 * or modified under the Terms and Conditions of its License Agreement, which is found
8 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
9 * may change at any time. To view the latest information, see:
10 * http://www.sourcemod.net/license.php
15 #ifndef _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
16 #define _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
18 #include <IShareSys.h>
19 #include <ILibrarySys.h>
22 * @file IExtensionSys.h
23 * @brief Defines the interface for loading/unloading/managing extensions.
28 class IExtensionInterface;
29 typedef void * ITERATOR; /**< Generic pointer for dependency iterators */
32 * @brief Encapsulates an IExtensionInterface and its dependencies.
38 * @brief Returns whether or not the extension is properly loaded.
40 virtual bool IsLoaded() =0;
43 * @brief Returns the extension's API interface
45 * @return An IExtensionInterface pointer.
47 virtual IExtensionInterface *GetAPI() =0;
50 * @brief Returns the filename of the extension, relative to the
53 * @return A string containing the extension file name.
55 virtual const char *GetFilename() =0;
58 * @brief Returns the extension's identity token.
60 * @return An IdentityToken_t pointer.
62 virtual IdentityToken_t *GetIdentity() =0;
65 * @brief Retrieves the extension dependency list for this extension.
67 * @param pOwner Optional pointer to store the first interface's owner.
68 * @param pInterface Optional pointer to store the first interface.
69 * @return An ITERATOR pointer for the results, or NULL if no results at all.
71 virtual ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface) =0;
74 * @brief Finds the next dependency in the dependency list.
76 * @param iter Pointer to iterator from FindFirstDependency.
77 * @param pOwner Optional pointer to store the interface's owner.
78 * @param pInterface Optional pointer to store the interface.
79 * @return True if there are more results after this, false otherwise.
81 virtual bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface) =0;
84 * @brief Frees an ITERATOR handle from FindFirstDependency.
86 * @param iter Pointer to iterator to free.
88 virtual void FreeDependencyIterator(ITERATOR *iter) =0;
91 * @brief Queries the extension to see its run state.
93 * @param error Error buffer (may be NULL).
94 * @param maxlength Maximum length of buffer.
95 * @return True if extension is okay, false if not okay.
97 virtual bool IsRunning(char *error, size_t maxlength) =0;
101 * @brief Version code of the IExtensionInterface API itself.
103 #define SMINTERFACE_EXTENSIONAPI_VERSION 1
106 * @brief The interface an extension must expose.
108 class IExtensionInterface
111 /** Returns the interface API version */
112 virtual unsigned int GetExtensionVersion()
114 return SMINTERFACE_EXTENSIONAPI_VERSION;
118 * @brief Called when the extension is loaded.
120 * @param me Pointer back to extension.
121 * @param sys Pointer to interface sharing system of SourceMod.
122 * @param error Error buffer to print back to, if any.
123 * @param err_max Maximum size of error buffer.
124 * @param late If this extension was loaded "late" (i.e. manually).
125 * @return True if load should continue, false otherwise.
127 virtual bool OnExtensionLoad(IExtension *me,
134 * @brief Called when the extension is about to be unloaded.
136 virtual void OnExtensionUnload() =0;
139 * @brief Called when all extensions are loaded (loading cycle is done).
140 * If loaded late, this will be called right after OnExtensionLoad().
142 virtual void OnExtensionsAllLoaded() =0;
145 * @brief Called when your pause state is about to change.
147 * @param pause True if pausing, false if unpausing.
149 virtual void OnExtensionPauseChange(bool pause) =0;
152 * @brief Asks the extension whether it's safe to remove an external interface it's using.
153 * If it's not safe, return false, and the extension will be unloaded afterwards.
154 * NOTE: It is important to also hook NotifyInterfaceDrop() in order to clean up resources.
156 * @param pInterface Pointer to interface being dropped.
157 * @return True to continue, false to unload this extension afterwards.
159 virtual bool QueryInterfaceDrop(SMInterface *pInterface)
165 * @brief Notifies the extension that an external interface it uses is being removed.
167 * @param pInterface Pointer to interface being dropped.
169 virtual void NotifyInterfaceDrop(SMInterface *pInterface)
174 * @brief Return false to tell Core that your extension should be considered unsable.
176 * @param error Error buffer.
177 * @param maxlength Size of error buffer.
178 * @return True on success, false otherwise.
180 virtual bool QueryRunning(char *error, size_t maxlength)
185 virtual bool IsMetamodExtension() =0;
186 virtual const char *GetExtensionName() =0;
187 virtual const char *GetExtensionURL() =0;
188 virtual const char *GetExtensionTag() =0;
189 virtual const char *GetExtensionAuthor() =0;
190 virtual const char *GetExtensionVerString() =0;
191 virtual const char *GetExtensionDescription() =0;
192 virtual const char *GetExtensionDateString() =0;
195 #define SMINTERFACE_EXTENSIONMANAGER_NAME "IExtensionManager"
196 #define SMINTERFACE_EXTENSIONMANAGER_VERSION 1
199 * @brief Not currently used.
201 enum ExtensionLifetime
203 ExtLifetime_Forever, //Extension will never be unloaded automatically
204 ExtLifetime_Map, //Extension will be unloaded at the end of the map
208 * @brief Manages the loading/unloading of extensions.
210 class IExtensionManager : public SMInterface
213 virtual const char *GetInterfaceName()
215 return SMINTERFACE_EXTENSIONMANAGER_NAME;
217 virtual unsigned int GetInterfaceVersion()
219 return SMINTERFACE_EXTENSIONMANAGER_VERSION;
223 * @brief Loads a extension into the extension system.
225 * @param path Path to extension file, relative to the extensions folder.
226 * @param lifetime Lifetime of the extension (currently ignored).
227 * @param error Error buffer.
228 * @param err_max Maximum error buffer length.
229 * @return New IExtension on success, NULL on failure.
231 virtual IExtension *LoadExtension(const char *path,
232 ExtensionLifetime lifetime,
237 * @brief Attempts to unload a module.
239 * @param pExt IExtension pointer.
240 * @return True if successful, false otherwise.
242 virtual bool UnloadExtension(IExtension *pExt) =0;
246 #endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_