3 * =============================================================================
5 * Copyright (C) 2004-2007 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.
39 * The Share System also manages the Identity_t data type, although this is internally
40 * implemented with the Handle System.
43 #include <sp_vm_types.h>
49 struct IdentityToken_t;
51 /** Forward declaration from IHandleSys.h */
52 typedef unsigned int HandleType_t;
54 /** Forward declaration from IHandleSys.h */
55 typedef HandleType_t IdentityType_t;
58 * @brief Defines the base functionality required by a shared interface.
64 * @brief Must return an integer defining the interface's version.
66 virtual unsigned int GetInterfaceVersion() =0;
69 * @brief Must return a string defining the interface's unique name.
71 virtual const char *GetInterfaceName() =0;
74 * @brief Must return whether the requested version number is backwards compatible.
75 * Note: This can be overridden for breaking changes or custom versioning.
77 * @param version Version number to compare against.
78 * @return True if compatible, false otherwise.
80 virtual bool IsVersionCompatible(unsigned int version)
82 if (version > GetInterfaceVersion())
92 * @brief Tracks dependencies and fires dependency listeners.
98 * @brief Adds an interface to the global interface system.
100 * @param myself Object adding this interface, in order to track dependencies.
101 * @param iface Interface pointer (must be unique).
102 * @return True on success, false otherwise.
104 virtual bool AddInterface(IExtension *myself, SMInterface *iface) =0;
107 * @brief Requests an interface from the global interface system.
108 * If found, the interface's internal reference count will be increased.
110 * @param iface_name Interface name.
111 * @param iface_vers Interface version to attempt to match.
112 * @param myself Object requesting this interface, in order to track dependencies.
113 * @param pIface Pointer to store the return value in.
115 virtual bool RequestInterface(const char *iface_name,
116 unsigned int iface_vers,
118 SMInterface **pIface) =0;
121 * @brief Adds a list of natives to the global native pool, to be
122 * bound on plugin load.
124 * Adding natives does not bind them to any loaded plugins; the
125 * plugins must be reloaded for new natives to take effect.
127 * @param myself Identity token of parent object.
128 * @param natives Array of natives to add. The last entry in
129 * the array must be filled with NULLs to
130 * terminate the array. The array must be static
131 * as Core will cache the pointer for the
132 * lifetime of the extension.
134 virtual void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives) =0;
137 * @brief Creates a new identity type.
138 * NOTE: Module authors should never need to use this. Due to the current implementation,
139 * there is a hardcoded limit of 15 types. Core uses up a few, so think carefully!
141 * @param name String containing type name. Must not be empty or NULL.
142 * @return A new HandleType_t identifier, or 0 on failure.
144 virtual IdentityType_t CreateIdentType(const char *name) =0;
147 * @brief Finds an identity type by name.
148 * DEFAULT IDENTITY TYPES:
149 * "PLUGIN" - An IPlugin object.
150 * "MODULE" - An IModule object.
151 * "CORE" - An SMGlobalClass or other singleton.
153 * @param name String containing type name to search for.
154 * @return A HandleType_t identifier if found, 0 otherwise.
156 virtual IdentityType_t FindIdentType(const char *name) =0;
159 * @brief Creates a new identity token. This token is guaranteed to be
160 * unique amongst all other open identities.
162 * @param type Identity type.
163 * @param ptr Private data pointer (cannot be NULL).
164 * @return A new IdentityToken_t pointer, or NULL on failure.
166 virtual IdentityToken_t *CreateIdentity(IdentityType_t type, void *ptr) =0;
169 * @brief Destroys an identity type. Note that this will delete any identities
170 * that are under this type.
172 * @param type Identity type.
174 virtual void DestroyIdentType(IdentityType_t type) =0;
177 * @brief Destroys an identity token. Any handles being owned by this token, or
180 * @param identity Identity to remove.
182 virtual void DestroyIdentity(IdentityToken_t *identity) =0;
185 * @brief Requires an extension. This tells SourceMod that without this extension,
186 * your extension should not be loaded. The name should not include the ".dll" or
187 * the ".so" part of the file name.
189 * @param myself IExtension pointer to yourself.
190 * @param filename File of extension to require.
191 * @param require Whether or not this extension is a required dependency.
192 * @param autoload Whether or not to autoload this extension.
194 virtual void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload) =0;
198 #endif //_INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_