public/IShareSys.h
author David Anderson <dvander@alliedmods.net>
Fri Aug 10 05:59:03 2007 +0000 (2007-08-10)
changeset 1300 2c6b22445149
parent 1226 478550a4d5ec
child 1330 ab94316bb52b
permissions -rw-r--r--
fixed per-group command overrides not working
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * ================================================================
     7  *
     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.
    11  * 
    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.
    16  *
    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/>.
    19  *
    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>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #ifndef _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
    34 #define _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
    35 
    36 /**
    37  * @file IShareSys.h
    38  * @brief Defines the Share System, responsible for shared resources and dependencies.
    39  *
    40  *  The Share System also manages the Identity_t data type, although this is internally
    41  * implemented with the Handle System.
    42  */
    43 
    44 #include <sp_vm_types.h>
    45 
    46 
    47 namespace SourceMod
    48 {
    49 	class IExtension;
    50 	struct IdentityToken_t;
    51 
    52 	/** Forward declaration from IHandleSys.h */
    53 	typedef unsigned int		HandleType_t;
    54 
    55 	/** Forward declaration from IHandleSys.h */
    56 	typedef HandleType_t		IdentityType_t;
    57 
    58 	/**
    59 	 * @brief Defines the base functionality required by a shared interface.
    60 	 */
    61 	class SMInterface
    62 	{
    63 	public:
    64 		/**
    65 		 * @brief Must return an integer defining the interface's version.
    66 		 */
    67 		virtual unsigned int GetInterfaceVersion() =0;
    68 
    69 		/**
    70 		 * @brief Must return a string defining the interface's unique name.
    71 		 */
    72 		virtual const char *GetInterfaceName() =0;
    73 
    74 		/**
    75 		 * @brief Must return whether the requested version number is backwards compatible.
    76 		 * Note: This can be overridden for breaking changes or custom versioning.
    77 		 * 
    78 		 * @param version		Version number to compare against.
    79 		 * @return				True if compatible, false otherwise.
    80 		 */
    81 		virtual bool IsVersionCompatible(unsigned int version)
    82 		{
    83 			if (version > GetInterfaceVersion())
    84 			{
    85 				return false;
    86 			}
    87 
    88 			return true;
    89 		}
    90 	};
    91 
    92 	/**
    93 	 * @brief Tracks dependencies and fires dependency listeners.
    94 	 */
    95 	class IShareSys
    96 	{
    97 	public:
    98 		/**
    99 		 * @brief Adds an interface to the global interface system.
   100 		 *
   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.
   104 		 */
   105 		virtual bool AddInterface(IExtension *myself, SMInterface *iface) =0;
   106 
   107 		/**
   108 		 * @brief Requests an interface from the global interface system.
   109 		 * If found, the interface's internal reference count will be increased.
   110 		 *
   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.
   115 		 */
   116 		virtual bool RequestInterface(const char *iface_name, 
   117 										unsigned int iface_vers,
   118 										IExtension *myself,
   119 										SMInterface **pIface) =0;
   120 
   121 		/**
   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.
   125 		 * 
   126 		 * @param myself		Identity token of parent object.
   127 		 * @param natives		Array of natives to add.  The last entry must have NULL members.
   128 		 */
   129 		virtual void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives) =0;
   130 
   131 		/**
   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!
   135 		 *
   136 		 * @param name			String containing type name.  Must not be empty or NULL.
   137 		 * @return				A new HandleType_t identifier, or 0 on failure.
   138 		 */
   139 		virtual IdentityType_t CreateIdentType(const char *name) =0;
   140 
   141 		/**
   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.
   147 		 * 
   148 		 * @param name			String containing type name to search for.
   149 		 * @return				A HandleType_t identifier if found, 0 otherwise.
   150 		 */
   151 		virtual IdentityType_t FindIdentType(const char *name) =0;
   152 
   153 		/**
   154 		 * @brief Creates a new identity token.  This token is guaranteed to be 
   155 		 * unique amongst all other open identities.
   156 		 *
   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.
   160 		 */
   161 		virtual IdentityToken_t *CreateIdentity(IdentityType_t type, void *ptr) =0;
   162 
   163 		/** 
   164 		 * @brief Destroys an identity type.  Note that this will delete any identities
   165 		 * that are under this type.  
   166 		 *
   167 		 * @param type			Identity type.
   168 		 */
   169 		virtual void DestroyIdentType(IdentityType_t type) =0;
   170 
   171 		/**
   172 		 * @brief Destroys an identity token.  Any handles being owned by this token, or
   173 		 * any handles being 
   174 		 *
   175 		 * @param identity		Identity to remove.
   176 		 */
   177 		virtual void DestroyIdentity(IdentityToken_t *identity) =0;
   178 
   179 		/**
   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.
   183 		 *
   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.
   188 		 */
   189 		virtual void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload) =0;
   190 	};
   191 }
   192 
   193 #endif //_INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_