public/IShareSys.h
author Phong Dang <teame06@gmail.com>
Sun Jul 29 19:20:42 2007 +0000 (2007-07-29)
changeset 1211 990912ee1e1e
parent 868 bdbf922e246f
child 1226 478550a4d5ec
permissions -rw-r--r--
Added amb<536> requested for using sm_kick without putting quotes around reason.
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
     5  * All rights reserved.
     6  * ===============================================================
     7  *
     8  *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be 
     9  * used or modified under the Terms and Conditions of its License Agreement, 
    10  * which is found in public/licenses/LICENSE.txt.  As of this notice, derivative 
    11  * works must be licensed under the GNU General Public License (version 2 or 
    12  * greater).  A copy of the GPL is included under public/licenses/GPL.txt.
    13  * 
    14  * To view the latest information, see: http://www.sourcemod.net/license.php
    15  *
    16  * Version: $Id$
    17  */
    18 
    19 #ifndef _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
    20 #define _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
    21 
    22 /**
    23  * @file IShareSys.h
    24  * @brief Defines the Share System, responsible for shared resources and dependencies.
    25  *
    26  *  The Share System also manages the Identity_t data type, although this is internally
    27  * implemented with the Handle System.
    28  */
    29 
    30 #include <sp_vm_types.h>
    31 
    32 
    33 namespace SourceMod
    34 {
    35 	class IExtension;
    36 	struct IdentityToken_t;
    37 
    38 	/** Forward declaration from IHandleSys.h */
    39 	typedef unsigned int		HandleType_t;
    40 
    41 	/** Forward declaration from IHandleSys.h */
    42 	typedef HandleType_t		IdentityType_t;
    43 
    44 	/**
    45 	 * @brief Defines the base functionality required by a shared interface.
    46 	 */
    47 	class SMInterface
    48 	{
    49 	public:
    50 		/**
    51 		 * @brief Must return an integer defining the interface's version.
    52 		 */
    53 		virtual unsigned int GetInterfaceVersion() =0;
    54 
    55 		/**
    56 		 * @brief Must return a string defining the interface's unique name.
    57 		 */
    58 		virtual const char *GetInterfaceName() =0;
    59 
    60 		/**
    61 		 * @brief Must return whether the requested version number is backwards compatible.
    62 		 * Note: This can be overridden for breaking changes or custom versioning.
    63 		 * 
    64 		 * @param version		Version number to compare against.
    65 		 * @return				True if compatible, false otherwise.
    66 		 */
    67 		virtual bool IsVersionCompatible(unsigned int version)
    68 		{
    69 			if (version > GetInterfaceVersion())
    70 			{
    71 				return false;
    72 			}
    73 
    74 			return true;
    75 		}
    76 	};
    77 
    78 	/**
    79 	 * @brief Tracks dependencies and fires dependency listeners.
    80 	 */
    81 	class IShareSys
    82 	{
    83 	public:
    84 		/**
    85 		 * @brief Adds an interface to the global interface system.
    86 		 *
    87 		 * @param myself		Object adding this interface, in order to track dependencies.
    88 		 * @param iface			Interface pointer (must be unique).
    89 		 * @return				True on success, false otherwise.
    90 		 */
    91 		virtual bool AddInterface(IExtension *myself, SMInterface *iface) =0;
    92 
    93 		/**
    94 		 * @brief Requests an interface from the global interface system.
    95 		 * If found, the interface's internal reference count will be increased.
    96 		 *
    97 		 * @param iface_name	Interface name.
    98 		 * @param iface_vers	Interface version to attempt to match.
    99 		 * @param myself		Object requesting this interface, in order to track dependencies.
   100 		 * @param pIface		Pointer to store the return value in.
   101 		 */
   102 		virtual bool RequestInterface(const char *iface_name, 
   103 										unsigned int iface_vers,
   104 										IExtension *myself,
   105 										SMInterface **pIface) =0;
   106 
   107 		/**
   108 		 * @brief Adds a list of natives to the global native pool, to be bound on plugin load.
   109 		 * NOTE: Adding natives currently does not bind them to any loaded plugins.
   110 		 * You must manually bind late natives.
   111 		 * 
   112 		 * @param myself		Identity token of parent object.
   113 		 * @param natives		Array of natives to add.  The last entry must have NULL members.
   114 		 */
   115 		virtual void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives) =0;
   116 
   117 		/**
   118 		 * @brief Creates a new identity type.
   119 		 * NOTE: Module authors should never need to use this.  Due to the current implementation,
   120 		 * there is a hardcoded limit of 15 types.  Core uses up a few, so think carefully!
   121 		 *
   122 		 * @param name			String containing type name.  Must not be empty or NULL.
   123 		 * @return				A new HandleType_t identifier, or 0 on failure.
   124 		 */
   125 		virtual IdentityType_t CreateIdentType(const char *name) =0;
   126 
   127 		/**
   128 		 * @brief Finds an identity type by name.
   129 		 * DEFAULT IDENTITY TYPES:
   130 		 *  "PLUGIN"	- An IPlugin object.
   131 		 *  "MODULE"	- An IModule object.
   132 		 *  "CORE"		- An SMGlobalClass or other singleton.
   133 		 * 
   134 		 * @param name			String containing type name to search for.
   135 		 * @return				A HandleType_t identifier if found, 0 otherwise.
   136 		 */
   137 		virtual IdentityType_t FindIdentType(const char *name) =0;
   138 
   139 		/**
   140 		 * @brief Creates a new identity token.  This token is guaranteed to be 
   141 		 * unique amongst all other open identities.
   142 		 *
   143 		 * @param type			Identity type.
   144 		 * @param ptr			Private data pointer (cannot be NULL).
   145 		 * @return				A new IdentityToken_t pointer, or NULL on failure.
   146 		 */
   147 		virtual IdentityToken_t *CreateIdentity(IdentityType_t type, void *ptr) =0;
   148 
   149 		/** 
   150 		 * @brief Destroys an identity type.  Note that this will delete any identities
   151 		 * that are under this type.  
   152 		 *
   153 		 * @param type			Identity type.
   154 		 */
   155 		virtual void DestroyIdentType(IdentityType_t type) =0;
   156 
   157 		/**
   158 		 * @brief Destroys an identity token.  Any handles being owned by this token, or
   159 		 * any handles being 
   160 		 *
   161 		 * @param identity		Identity to remove.
   162 		 */
   163 		virtual void DestroyIdentity(IdentityToken_t *identity) =0;
   164 
   165 		/**
   166 		 * @brief Requires an extension.  This tells SourceMod that without this extension,
   167 		 * your extension should not be loaded.  The name should not include the ".dll" or
   168 		 * the ".so" part of the file name.
   169 		 *
   170 		 * @param myself		IExtension pointer to yourself.
   171 		 * @param filename		File of extension to require.
   172 		 * @param require		Whether or not this extension is a required dependency.
   173 		 * @param autoload		Whether or not to autoload this extension.
   174 		 */
   175 		virtual void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload) =0;
   176 	};
   177 }
   178 
   179 #endif //_INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_