3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
33 #define _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
37 * @brief Defines the Share System, responsible for shared resources and dependencies.
40 #include <sp_vm_types.h>
46 struct IdentityToken_t;
48 /** Forward declaration from IHandleSys.h */
49 typedef unsigned int HandleType_t;
51 /** Forward declaration from IHandleSys.h */
52 typedef HandleType_t IdentityType_t;
55 * @brief Types of features.
59 FeatureType_Native, /**< Native functions for plugins. */
60 FeatureType_Capability /**< Named capabilities. */
64 * @brief Feature presence status codes.
68 FeatureStatus_Available = 0, /**< Feature is available for use. */
69 FeatureStatus_Unavailable, /**< Feature is unavailable, but known. */
70 FeatureStatus_Unknown /**< Feature is not known. */
74 * @brief Provides a capability feature.
76 class IFeatureProvider
80 * @brief Must return whether a capability is present.
82 * @param type Feature type (FeatureType_Capability right now).
83 * @param name Feature name.
84 * @return Feature status code.
86 virtual FeatureStatus GetFeatureStatus(FeatureType type, const char *name) = 0;
90 * @brief Defines the base functionality required by a shared interface.
96 * @brief Must return an integer defining the interface's version.
98 virtual unsigned int GetInterfaceVersion() =0;
101 * @brief Must return a string defining the interface's unique name.
103 virtual const char *GetInterfaceName() =0;
106 * @brief Must return whether the requested version number is backwards compatible.
107 * Note: This can be overridden for breaking changes or custom versioning.
109 * @param version Version number to compare against.
110 * @return True if compatible, false otherwise.
112 virtual bool IsVersionCompatible(unsigned int version)
114 if (version > GetInterfaceVersion())
124 * @brief Tracks dependencies and fires dependency listeners.
130 * @brief Adds an interface to the global interface system.
132 * @param myself Object adding this interface, in order to track dependencies.
133 * @param iface Interface pointer (must be unique).
134 * @return True on success, false otherwise.
136 virtual bool AddInterface(IExtension *myself, SMInterface *iface) =0;
139 * @brief Requests an interface from the global interface system.
140 * If found, the interface's internal reference count will be increased.
142 * @param iface_name Interface name.
143 * @param iface_vers Interface version to attempt to match.
144 * @param myself Object requesting this interface, in order to track dependencies.
145 * @param pIface Pointer to store the return value in.
147 virtual bool RequestInterface(const char *iface_name,
148 unsigned int iface_vers,
150 SMInterface **pIface) =0;
153 * @brief Adds a list of natives to the global native pool, to be
154 * bound on plugin load.
156 * Adding natives does not bind them to any loaded plugins; the
157 * plugins must be reloaded for new natives to take effect.
159 * @param myself Identity token of parent object.
160 * @param natives Array of natives to add. The last entry in
161 * the array must be filled with NULLs to
162 * terminate the array. The array must be static
163 * as Core will cache the pointer for the
164 * lifetime of the extension.
166 virtual void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives) =0;
169 * @brief Creates a new identity type.
170 * NOTE: Module authors should never need to use this. Due to the current implementation,
171 * there is a hardcoded limit of 15 types. Core uses up a few, so think carefully!
173 * @param name String containing type name. Must not be empty or NULL.
174 * @return A new HandleType_t identifier, or 0 on failure.
176 virtual IdentityType_t CreateIdentType(const char *name) =0;
179 * @brief Finds an identity type by name.
180 * DEFAULT IDENTITY TYPES:
181 * "PLUGIN" - An IPlugin object.
182 * "MODULE" - An IModule object.
183 * "CORE" - An SMGlobalClass or other singleton.
185 * @param name String containing type name to search for.
186 * @return A HandleType_t identifier if found, 0 otherwise.
188 virtual IdentityType_t FindIdentType(const char *name) =0;
191 * @brief Creates a new identity token. This token is guaranteed to be
192 * unique amongst all other open identities.
194 * @param type Identity type.
195 * @param ptr Private data pointer (cannot be NULL).
196 * @return A new IdentityToken_t pointer, or NULL on failure.
198 virtual IdentityToken_t *CreateIdentity(IdentityType_t type, void *ptr) =0;
201 * @brief Destroys an identity type. Note that this will delete any identities
202 * that are under this type.
204 * @param type Identity type.
206 virtual void DestroyIdentType(IdentityType_t type) =0;
209 * @brief Destroys an identity token. Any handles being owned by this token, or
212 * @param identity Identity to remove.
214 virtual void DestroyIdentity(IdentityToken_t *identity) =0;
217 * @brief Requires an extension. This tells SourceMod that without this extension,
218 * your extension should not be loaded. The name should not include the ".dll" or
219 * the ".so" part of the file name.
221 * @param myself IExtension pointer to yourself.
222 * @param filename File of extension to require.
223 * @param require Whether or not this extension is a required dependency.
224 * @param autoload Whether or not to autoload this extension.
226 virtual void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload) =0;
229 * @brief Registers a library name to an extension.
231 * @param myself Extension to register library to.
232 * @param name Library name.
234 virtual void RegisterLibrary(IExtension *myself, const char *name) =0;
237 * @brief Adds natives that will override Core natives when called.
239 * A Core version of each native must exist. If one does not, then
240 * Core will simply ignore that entry. No more than one override
241 * can exist on a given native.
243 * Override natives represent a weak coupling. If the extension is
244 * unloaded, the native will be re-bound to the Core version. If
245 * the extension is loaded after plugins are loaded, the override
246 * will not take effect until those plugins are reloaded.
248 * @param myself Identity token of parent object.
249 * @param natives Array of natives to add. The last entry in
250 * the array must be filled with NULLs to
251 * terminate the array. The array must be static
252 * as Core will cache the pointer for the
253 * lifetime of the extension.
255 virtual void OverrideNatives(IExtension *myself, const sp_nativeinfo_t *natives) =0;
258 * @brief Adds a capability provider. Feature providers are used by
259 * plugins to determine if a feature exists at runtime. This is
260 * distinctly different from checking for a native, because natives
261 * may be backed by underlying functionality which is not available.
263 * @param myself Extension.
264 * @param provider Feature provider implementation.
265 * @param name Capibility name.
267 virtual void AddCapabilityProvider(IExtension *myself,
268 IFeatureProvider *provider,
269 const char *name) =0;
272 * @brief Drops a previously added cap provider.
274 * @param myself Extension.
275 * @param provider Feature provider implementation.
276 * @param name Capibility name.
278 virtual void DropCapabilityProvider(IExtension *myself,
279 IFeatureProvider *provider,
280 const char *name) =0;
284 #endif //_INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_