3 * ================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
33 #ifndef _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
34 #define _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
38 * @brief Defines the Share System, responsible for shared resources and dependencies.
40 * The Share System also manages the Identity_t data type, although this is internally
41 * implemented with the Handle System.
44 #include <sp_vm_types.h>
50 struct IdentityToken_t;
52 /** Forward declaration from IHandleSys.h */
53 typedef unsigned int HandleType_t;
55 /** Forward declaration from IHandleSys.h */
56 typedef HandleType_t IdentityType_t;
59 * @brief Defines the base functionality required by a shared interface.
65 * @brief Must return an integer defining the interface's version.
67 virtual unsigned int GetInterfaceVersion() =0;
70 * @brief Must return a string defining the interface's unique name.
72 virtual const char *GetInterfaceName() =0;
75 * @brief Must return whether the requested version number is backwards compatible.
76 * Note: This can be overridden for breaking changes or custom versioning.
78 * @param version Version number to compare against.
79 * @return True if compatible, false otherwise.
81 virtual bool IsVersionCompatible(unsigned int version)
83 if (version > GetInterfaceVersion())
93 * @brief Tracks dependencies and fires dependency listeners.
99 * @brief Adds an interface to the global interface system.
101 * @param myself Object adding this interface, in order to track dependencies.
102 * @param iface Interface pointer (must be unique).
103 * @return True on success, false otherwise.
105 virtual bool AddInterface(IExtension *myself, SMInterface *iface) =0;
108 * @brief Requests an interface from the global interface system.
109 * If found, the interface's internal reference count will be increased.
111 * @param iface_name Interface name.
112 * @param iface_vers Interface version to attempt to match.
113 * @param myself Object requesting this interface, in order to track dependencies.
114 * @param pIface Pointer to store the return value in.
116 virtual bool RequestInterface(const char *iface_name,
117 unsigned int iface_vers,
119 SMInterface **pIface) =0;
122 * @brief Adds a list of natives to the global native pool, to be bound on plugin load.
123 * NOTE: Adding natives currently does not bind them to any loaded plugins.
124 * You must manually bind late natives.
126 * @param myself Identity token of parent object.
127 * @param natives Array of natives to add. The last entry must have NULL members.
129 virtual void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives) =0;
132 * @brief Creates a new identity type.
133 * NOTE: Module authors should never need to use this. Due to the current implementation,
134 * there is a hardcoded limit of 15 types. Core uses up a few, so think carefully!
136 * @param name String containing type name. Must not be empty or NULL.
137 * @return A new HandleType_t identifier, or 0 on failure.
139 virtual IdentityType_t CreateIdentType(const char *name) =0;
142 * @brief Finds an identity type by name.
143 * DEFAULT IDENTITY TYPES:
144 * "PLUGIN" - An IPlugin object.
145 * "MODULE" - An IModule object.
146 * "CORE" - An SMGlobalClass or other singleton.
148 * @param name String containing type name to search for.
149 * @return A HandleType_t identifier if found, 0 otherwise.
151 virtual IdentityType_t FindIdentType(const char *name) =0;
154 * @brief Creates a new identity token. This token is guaranteed to be
155 * unique amongst all other open identities.
157 * @param type Identity type.
158 * @param ptr Private data pointer (cannot be NULL).
159 * @return A new IdentityToken_t pointer, or NULL on failure.
161 virtual IdentityToken_t *CreateIdentity(IdentityType_t type, void *ptr) =0;
164 * @brief Destroys an identity type. Note that this will delete any identities
165 * that are under this type.
167 * @param type Identity type.
169 virtual void DestroyIdentType(IdentityType_t type) =0;
172 * @brief Destroys an identity token. Any handles being owned by this token, or
175 * @param identity Identity to remove.
177 virtual void DestroyIdentity(IdentityToken_t *identity) =0;
180 * @brief Requires an extension. This tells SourceMod that without this extension,
181 * your extension should not be loaded. The name should not include the ".dll" or
182 * the ".so" part of the file name.
184 * @param myself IExtension pointer to yourself.
185 * @param filename File of extension to require.
186 * @param require Whether or not this extension is a required dependency.
187 * @param autoload Whether or not to autoload this extension.
189 virtual void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload) =0;
193 #endif //_INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_