00001 /** 00002 * vim: set ts=4 : 00003 * ============================================================================= 00004 * SourceMod 00005 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. 00006 * ============================================================================= 00007 * 00008 * This program is free software; you can redistribute it and/or modify it under 00009 * the terms of the GNU General Public License, version 3.0, as published by the 00010 * Free Software Foundation. 00011 * 00012 * This program is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00014 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00015 * details. 00016 * 00017 * You should have received a copy of the GNU General Public License along with 00018 * this program. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 * As a special exception, AlliedModders LLC gives you permission to link the 00021 * code of this program (as well as its derivative works) to "Half-Life 2," the 00022 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software 00023 * by the Valve Corporation. You must obey the GNU General Public License in 00024 * all respects for all other code used. Additionally, AlliedModders LLC grants 00025 * this exception to all derivative works. AlliedModders LLC defines further 00026 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), 00027 * or <http://www.sourcemod.net/license.php>. 00028 * 00029 * Version: $Id$ 00030 */ 00031 00032 #ifndef _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_ 00033 #define _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_ 00034 00035 /** 00036 * @file IShareSys.h 00037 * @brief Defines the Share System, responsible for shared resources and dependencies. 00038 * 00039 * The Share System also manages the Identity_t data type, although this is internally 00040 * implemented with the Handle System. 00041 */ 00042 00043 #include <sp_vm_types.h> 00044 00045 00046 namespace SourceMod 00047 { 00048 class IExtension; 00049 struct IdentityToken_t; 00050 00051 /** Forward declaration from IHandleSys.h */ 00052 typedef unsigned int HandleType_t; 00053 00054 /** Forward declaration from IHandleSys.h */ 00055 typedef HandleType_t IdentityType_t; 00056 00057 /** 00058 * @brief Defines the base functionality required by a shared interface. 00059 */ 00060 class SMInterface 00061 { 00062 public: 00063 /** 00064 * @brief Must return an integer defining the interface's version. 00065 */ 00066 virtual unsigned int GetInterfaceVersion() =0; 00067 00068 /** 00069 * @brief Must return a string defining the interface's unique name. 00070 */ 00071 virtual const char *GetInterfaceName() =0; 00072 00073 /** 00074 * @brief Must return whether the requested version number is backwards compatible. 00075 * Note: This can be overridden for breaking changes or custom versioning. 00076 * 00077 * @param version Version number to compare against. 00078 * @return True if compatible, false otherwise. 00079 */ 00080 virtual bool IsVersionCompatible(unsigned int version) 00081 { 00082 if (version > GetInterfaceVersion()) 00083 { 00084 return false; 00085 } 00086 00087 return true; 00088 } 00089 }; 00090 00091 /** 00092 * @brief Tracks dependencies and fires dependency listeners. 00093 */ 00094 class IShareSys 00095 { 00096 public: 00097 /** 00098 * @brief Adds an interface to the global interface system. 00099 * 00100 * @param myself Object adding this interface, in order to track dependencies. 00101 * @param iface Interface pointer (must be unique). 00102 * @return True on success, false otherwise. 00103 */ 00104 virtual bool AddInterface(IExtension *myself, SMInterface *iface) =0; 00105 00106 /** 00107 * @brief Requests an interface from the global interface system. 00108 * If found, the interface's internal reference count will be increased. 00109 * 00110 * @param iface_name Interface name. 00111 * @param iface_vers Interface version to attempt to match. 00112 * @param myself Object requesting this interface, in order to track dependencies. 00113 * @param pIface Pointer to store the return value in. 00114 */ 00115 virtual bool RequestInterface(const char *iface_name, 00116 unsigned int iface_vers, 00117 IExtension *myself, 00118 SMInterface **pIface) =0; 00119 00120 /** 00121 * @brief Adds a list of natives to the global native pool, to be 00122 * bound on plugin load. 00123 * 00124 * Adding natives does not bind them to any loaded plugins; the 00125 * plugins must be reloaded for new natives to take effect. 00126 * 00127 * @param myself Identity token of parent object. 00128 * @param natives Array of natives to add. The last entry in 00129 * the array must be filled with NULLs to 00130 * terminate the array. The array must be static 00131 * as Core will cache the pointer for the 00132 * lifetime of the extension. 00133 */ 00134 virtual void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives) =0; 00135 00136 /** 00137 * @brief Creates a new identity type. 00138 * NOTE: Module authors should never need to use this. Due to the current implementation, 00139 * there is a hardcoded limit of 15 types. Core uses up a few, so think carefully! 00140 * 00141 * @param name String containing type name. Must not be empty or NULL. 00142 * @return A new HandleType_t identifier, or 0 on failure. 00143 */ 00144 virtual IdentityType_t CreateIdentType(const char *name) =0; 00145 00146 /** 00147 * @brief Finds an identity type by name. 00148 * DEFAULT IDENTITY TYPES: 00149 * "PLUGIN" - An IPlugin object. 00150 * "MODULE" - An IModule object. 00151 * "CORE" - An SMGlobalClass or other singleton. 00152 * 00153 * @param name String containing type name to search for. 00154 * @return A HandleType_t identifier if found, 0 otherwise. 00155 */ 00156 virtual IdentityType_t FindIdentType(const char *name) =0; 00157 00158 /** 00159 * @brief Creates a new identity token. This token is guaranteed to be 00160 * unique amongst all other open identities. 00161 * 00162 * @param type Identity type. 00163 * @param ptr Private data pointer (cannot be NULL). 00164 * @return A new IdentityToken_t pointer, or NULL on failure. 00165 */ 00166 virtual IdentityToken_t *CreateIdentity(IdentityType_t type, void *ptr) =0; 00167 00168 /** 00169 * @brief Destroys an identity type. Note that this will delete any identities 00170 * that are under this type. 00171 * 00172 * @param type Identity type. 00173 */ 00174 virtual void DestroyIdentType(IdentityType_t type) =0; 00175 00176 /** 00177 * @brief Destroys an identity token. Any handles being owned by this token, or 00178 * any handles being 00179 * 00180 * @param identity Identity to remove. 00181 */ 00182 virtual void DestroyIdentity(IdentityToken_t *identity) =0; 00183 00184 /** 00185 * @brief Requires an extension. This tells SourceMod that without this extension, 00186 * your extension should not be loaded. The name should not include the ".dll" or 00187 * the ".so" part of the file name. 00188 * 00189 * @param myself IExtension pointer to yourself. 00190 * @param filename File of extension to require. 00191 * @param require Whether or not this extension is a required dependency. 00192 * @param autoload Whether or not to autoload this extension. 00193 */ 00194 virtual void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload) =0; 00195 00196 /** 00197 * @brief Registers a library name to an extension. 00198 * 00199 * @param myself Extension to register library to. 00200 * @param name Library name. 00201 */ 00202 virtual void RegisterLibrary(IExtension *myself, const char *name) =0; 00203 00204 /** 00205 * @brief Adds natives that will override Core natives when called. 00206 * 00207 * A Core version of each native must exist. If one does not, then 00208 * Core will simply ignore that entry. No more than one override 00209 * can exist on a given native. 00210 * 00211 * Override natives represent a weak coupling. If the extension is 00212 * unloaded, the native will be re-bound to the Core version. If 00213 * the extension is loaded after plugins are loaded, the override 00214 * will not take effect until those plugins are reloaded. 00215 * 00216 * @param myself Identity token of parent object. 00217 * @param natives Array of natives to add. The last entry in 00218 * the array must be filled with NULLs to 00219 * terminate the array. The array must be static 00220 * as Core will cache the pointer for the 00221 * lifetime of the extension. 00222 */ 00223 virtual void OverrideNatives(IExtension *myself, const sp_nativeinfo_t *natives) =0; 00224 }; 00225 } 00226 00227 #endif //_INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
1.5.1