public/IPluginSys.h
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/public/IPluginSys.h	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,352 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod
     1.8 - * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     1.9 - * =============================================================================
    1.10 - *
    1.11 - * This program is free software; you can redistribute it and/or modify it under
    1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 - * Free Software Foundation.
    1.14 - * 
    1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 - * details.
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License along with
    1.21 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 - *
    1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 - * or <http://www.sourcemod.net/license.php>.
    1.31 - *
    1.32 - * Version: $Id$
    1.33 - */
    1.34 -
    1.35 -#ifndef _INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
    1.36 -#define _INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
    1.37 -
    1.38 -/**
    1.39 - * @file IPluginSys.h
    1.40 - * @brief Defines the interface for the Plugin System, which manages loaded plugins.
    1.41 - */
    1.42 -
    1.43 -#include <IShareSys.h>
    1.44 -#include <sp_vm_api.h>
    1.45 -
    1.46 -#define SMINTERFACE_PLUGINSYSTEM_NAME		"IPluginManager"
    1.47 -#define SMINTERFACE_PLUGINSYSTEM_VERSION	2
    1.48 -
    1.49 -/** Context user slot 3 is used Core for holding an IPluginContext pointer. */
    1.50 -#define SM_CONTEXTVAR_USER		3
    1.51 -
    1.52 -namespace SourceMod
    1.53 -{
    1.54 -	class IPlugin;
    1.55 -
    1.56 -	/** 
    1.57 -	 * @brief Encapsulates plugin public information exposed through "myinfo."
    1.58 -	 */
    1.59 -	typedef struct sm_plugininfo_s
    1.60 -	{
    1.61 -		const char *name;			/**< Plugin name */
    1.62 -		const char *author;			/**< Plugin author */
    1.63 -		const char *description;	/**< Plugin description */
    1.64 -		const char *version;		/**< Plugin version string */
    1.65 -		const char *url;			/**< Plugin URL */
    1.66 -	} sm_plugininfo_t;
    1.67 -
    1.68 -
    1.69 -	/**
    1.70 -	 * @brief Describes the usability status of a plugin.
    1.71 -	 */
    1.72 -	enum PluginStatus
    1.73 -	{
    1.74 -		Plugin_Running=0,		/**< Plugin is running */
    1.75 -		/* All states below are unexecutable */
    1.76 -		Plugin_Paused,			/**< Plugin is loaded but paused */
    1.77 -		Plugin_Error,			/**< Plugin is loaded but errored/locked */
    1.78 -		/* All states below do not have all natives */
    1.79 -		Plugin_Loaded,			/**< Plugin has passed loading and can be finalized */
    1.80 -		Plugin_Failed,			/**< Plugin has a fatal failure */
    1.81 -		Plugin_Created,			/**< Plugin is created but not initialized */
    1.82 -		Plugin_Uncompiled,		/**< Plugin is not yet compiled by the JIT */
    1.83 -		Plugin_BadLoad,			/**< Plugin failed to load */
    1.84 -	};
    1.85 -
    1.86 -
    1.87 -	/**
    1.88 -	 * @brief Describes the object lifetime of a plugin.
    1.89 -	 */
    1.90 -	enum PluginType
    1.91 -	{
    1.92 -		PluginType_Private,			/**< Plugin is privately managed and receives no forwards */
    1.93 -		PluginType_MapUpdated,		/**< Plugin will never be unloaded unless for updates on mapchange */
    1.94 -		PluginType_MapOnly,			/**< Plugin will be removed at mapchange */
    1.95 -		PluginType_Global,			/**< Plugin will never be unloaded or updated */
    1.96 -	};
    1.97 -
    1.98 -	/**
    1.99 -	 * @brief Encapsulates a run-time plugin as maintained by SourceMod.
   1.100 -	 */
   1.101 -	class IPlugin
   1.102 -	{
   1.103 -	public:
   1.104 -		/** Virtual destructor */
   1.105 -		virtual ~IPlugin()
   1.106 -		{
   1.107 -		}
   1.108 -
   1.109 -		/**
   1.110 -		 * @brief Returns the lifetime of a plugin.
   1.111 -		 */
   1.112 -		virtual PluginType GetType() =0;
   1.113 -
   1.114 -		/**
   1.115 -		 * @brief Returns the current API context being used in the plugin.
   1.116 -		 *
   1.117 -		 * @return	Pointer to an IPluginContext, or NULL if not loaded.
   1.118 -		 */
   1.119 -		virtual SourcePawn::IPluginContext *GetBaseContext() =0;
   1.120 -
   1.121 -		/**
   1.122 -		 * @brief Returns the context structure being used in the plugin.
   1.123 -		 *
   1.124 -		 * @return	Pointer to an sp_context_t, or NULL if not loaded.
   1.125 -		 */
   1.126 -		virtual sp_context_t *GetContext() =0;
   1.127 -
   1.128 -		/**
   1.129 -		 * @brief Returns the plugin file structure.
   1.130 -		 *
   1.131 -		 * @return	Pointer to an sp_plugin_t, or NULL if not loaded.
   1.132 -		 */
   1.133 -		virtual const sp_plugin_t *GetPluginStructure() =0;
   1.134 -
   1.135 -		/**
   1.136 -		 * @brief Returns information about the plugin by reference.
   1.137 -		 *
   1.138 -		 * @return			Pointer to a sm_plugininfo_t object, NULL if plugin is not loaded.
   1.139 -		 */
   1.140 -		virtual const sm_plugininfo_t *GetPublicInfo() =0;
   1.141 -
   1.142 -		/**
   1.143 -		 * @brief Returns the plugin filename (relative to plugins dir).
   1.144 -		 */
   1.145 -		virtual const char *GetFilename() =0;
   1.146 -
   1.147 -		/**
   1.148 -		 * @brief Returns true if a plugin is in debug mode, false otherwise.
   1.149 -		 */
   1.150 -		virtual bool IsDebugging() =0;
   1.151 -
   1.152 -		/**
   1.153 -		 * @brief Returns the plugin status.
   1.154 -		 */
   1.155 -		virtual PluginStatus GetStatus() =0;
   1.156 -		
   1.157 -		/**
   1.158 -		 * @brief Sets whether the plugin is paused or not.
   1.159 -		 *
   1.160 -		 * @return			True on successful state change, false otherwise.
   1.161 -		 */
   1.162 -		virtual bool SetPauseState(bool paused) =0;
   1.163 -
   1.164 -		/**
   1.165 -		 * @brief Returns the unique serial number of a plugin.
   1.166 -		 */
   1.167 -		virtual unsigned int GetSerial() =0;
   1.168 -
   1.169 -		/**
   1.170 -		 * @brief Returns a plugin's identity token.
   1.171 -		 */
   1.172 -		virtual IdentityToken_t *GetIdentity() =0;
   1.173 -
   1.174 -		/**
   1.175 -		 * @brief Sets a property on this plugin.  This is used for per-plugin
   1.176 -		 * data from extensions or other parts of core.  The property's value must 
   1.177 -		 * be manually destructed when the plugin is destroyed.
   1.178 -		 *
   1.179 -		 * @param prop		String containing name of the property.
   1.180 -		 * @param ptr		Generic pointer to set.
   1.181 -		 * @return			True on success, false if the property is already set.
   1.182 -		 */
   1.183 -		virtual bool SetProperty(const char *prop, void *ptr) =0;
   1.184 -
   1.185 -		/**
   1.186 -		 * @brief Gets a property from a plugin.
   1.187 -		 *
   1.188 -		 * @param prop		String containing the property's name.
   1.189 -		 * @param ptr		Optional pointer to the generic pointer.
   1.190 -		 * @param remove	Optional boolean value; if true, property is removed
   1.191 -		 *					(so it can be set again).
   1.192 -		 * @return			True if the property existed, false otherwise.
   1.193 -		 */
   1.194 -		virtual bool GetProperty(const char *prop, void **ptr, bool remove=false) =0;
   1.195 -	};
   1.196 -
   1.197 -
   1.198 -	/**
   1.199 -	 * @brief Iterates over a list of plugins.
   1.200 -	 */
   1.201 -	class IPluginIterator
   1.202 -	{
   1.203 -	public:
   1.204 -		/** Virtual destructor */
   1.205 -		virtual ~IPluginIterator()
   1.206 -		{
   1.207 -		};
   1.208 -	public:
   1.209 -		/**
   1.210 -		 * @brief Returns true if there are more plugins in the iterator.
   1.211 -		 */
   1.212 -		virtual bool MorePlugins() =0;
   1.213 -
   1.214 -		/**
   1.215 -		 * @brief Returns the plugin at the current iterator position.
   1.216 -		 */
   1.217 -		virtual IPlugin *GetPlugin() =0;
   1.218 -
   1.219 -		/**
   1.220 -		 * @brief Advances to the next plugin in the iterator.
   1.221 -		 */
   1.222 -		virtual void NextPlugin() =0;
   1.223 -
   1.224 -		/**
   1.225 -		 * @brief Destroys the iterator object.
   1.226 -		 * Note: You may use 'delete' in lieu of this function.
   1.227 -		 */
   1.228 -		virtual void Release() =0;
   1.229 -	};
   1.230 -
   1.231 -	/**
   1.232 -	 * @brief Listens for plugin-oriented events.
   1.233 -	 */
   1.234 -	class IPluginsListener
   1.235 -	{
   1.236 -	public:
   1.237 -		/**
   1.238 -		 * @brief Called when a plugin is created/mapped into memory.
   1.239 -		 */
   1.240 -		virtual void OnPluginCreated(IPlugin *plugin)
   1.241 -		{
   1.242 -		}
   1.243 -
   1.244 -		/**
   1.245 -		 * @brief Called when a plugin is fully loaded successfully.
   1.246 -		 */
   1.247 -		virtual void OnPluginLoaded(IPlugin *plugin)
   1.248 -		{
   1.249 -		}
   1.250 -
   1.251 -		/**
   1.252 -		* @brief Called when a plugin is paused or unpaused.
   1.253 -		*/
   1.254 -		virtual void OnPluginPauseChange(IPlugin *plugin, bool paused)
   1.255 -		{
   1.256 -		}
   1.257 -
   1.258 -		/**
   1.259 -		 * @brief Called when a plugin is unloaded (only if fully loaded).
   1.260 -		 */
   1.261 -		virtual void OnPluginUnloaded(IPlugin *plugin)
   1.262 -		{
   1.263 -		}
   1.264 -
   1.265 -		/**
   1.266 -		 * @brief Called when a plugin is destroyed.
   1.267 -		 * NOTE: Always called if Created, even if load failed.
   1.268 -		 */
   1.269 -		virtual void OnPluginDestroyed(IPlugin *plugin)
   1.270 -		{
   1.271 -		}
   1.272 -	};
   1.273 -
   1.274 -
   1.275 -	/**
   1.276 -	 * @brief Manages the runtime loading and unloading of plugins.
   1.277 -	 */
   1.278 -	class IPluginManager : public SMInterface
   1.279 -	{
   1.280 -	public:
   1.281 -		virtual const char *GetInterfaceName()
   1.282 -		{
   1.283 -			return SMINTERFACE_PLUGINSYSTEM_NAME;
   1.284 -		}
   1.285 -
   1.286 -		virtual unsigned int GetInterfaceVersion()
   1.287 -		{
   1.288 -			return SMINTERFACE_PLUGINSYSTEM_VERSION;
   1.289 -		}
   1.290 -	public:
   1.291 -		/**
   1.292 -		 * @brief Attempts to load a plugin.
   1.293 -		 *
   1.294 -		 * @param path		Path and filename of plugin, relative to plugins folder.
   1.295 -		 * @param debug		Whether or not to default the plugin into debug mode.
   1.296 -		 * @param type		Lifetime of the plugin.
   1.297 -		 * @param error		Buffer to hold any error message.
   1.298 -		 * @param maxlength	Maximum length of error message buffer.
   1.299 -		 * @param wasloaded	Stores if the plugin is already loaded.
   1.300 -		 * @return			A new plugin pointer on success, false otherwise.
   1.301 -		 */
   1.302 -		virtual IPlugin *LoadPlugin(const char *path, 
   1.303 -									bool debug,
   1.304 -									PluginType type,
   1.305 -									char error[],
   1.306 -									size_t maxlength,
   1.307 -									bool *wasloaded) =0;
   1.308 -
   1.309 -		/**
   1.310 -		 * @brief Attempts to unload a plugin.
   1.311 -		 *
   1.312 -		 * @param plugin	Pointer to the plugin handle.
   1.313 -		 * @return			True on success, false otherwise.
   1.314 -		 */
   1.315 -		virtual bool UnloadPlugin(IPlugin *plugin) =0;
   1.316 -
   1.317 -		/**
   1.318 -		 * @brief Finds a plugin by its context.
   1.319 -		 * Note: This function should be considered O(1).
   1.320 -		 *
   1.321 -		 * @param ctx		Pointer to an sp_context_t.
   1.322 -		 * @return			Pointer to a matching IPlugin, or NULL if none found.
   1.323 -		 */
   1.324 -		virtual IPlugin *FindPluginByContext(const sp_context_t *ctx) =0;
   1.325 -
   1.326 -		/**
   1.327 -		 * @brief Returns the number of plugins (both failed and loaded).
   1.328 -		 *
   1.329 -		 * @return			The number of internally cached plugins.
   1.330 -		 */
   1.331 -		virtual unsigned int GetPluginCount() =0;
   1.332 -
   1.333 -		/**
   1.334 -		 * @brief Returns a pointer that can be used to iterate through plugins.
   1.335 -		 * Note: This pointer must be freed using EITHER delete OR IPluginIterator::Release().
   1.336 -		 */
   1.337 -		virtual IPluginIterator *GetPluginIterator() =0;
   1.338 -
   1.339 -		/** 
   1.340 -		 * @brief Adds a plugin manager listener.
   1.341 -		 *
   1.342 -		 * @param listener	Pointer to a listener.
   1.343 -		 */
   1.344 -		virtual void AddPluginsListener(IPluginsListener *listener) =0;
   1.345 -
   1.346 -		/**
   1.347 -		 * @brief Removes a plugin listener.
   1.348 -		 * 
   1.349 -		 * @param listener	Pointer to a listener.
   1.350 -		 */
   1.351 -		virtual void RemovePluginsListener(IPluginsListener *listener) =0;
   1.352 -	};
   1.353 -}
   1.354 -
   1.355 -#endif //_INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_