core/interfaces/IPluginSys.h
changeset 159 43c471413f70
parent 140 2c25d4131b38
child 172 d8a8186eccbf
     1.1 --- a/core/interfaces/IPluginSys.h	Wed Nov 08 06:25:25 2006 +0000
     1.2 +++ b/core/interfaces/IPluginSys.h	Wed Nov 08 06:30:20 2006 +0000
     1.3 @@ -2,12 +2,50 @@
     1.4  #define _INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
     1.5  
     1.6  #include <IShareSys.h>
     1.7 +#include <sp_vm_context.h>
     1.8  
     1.9  #define SMINTERFACE_PLUGINMANAGER_NAME		"IPluginManager"
    1.10  #define SMINTERFACE_PLUGINMANAGER_VERSION	1
    1.11  
    1.12  namespace SourceMod
    1.13  {
    1.14 +	/** 
    1.15 +	 * @brief Encapsulates plugin public information.
    1.16 +	 */
    1.17 +	typedef struct sm_plugininfo_s
    1.18 +	{
    1.19 +		const char *name;
    1.20 +		const char *author;
    1.21 +		const char *description;
    1.22 +		const char *version;
    1.23 +		const char *url;
    1.24 +	} sm_plugininfo_t;
    1.25 +
    1.26 +	/**
    1.27 +	 * @brief Describes the usability status of a plugin.
    1.28 +	 */
    1.29 +	enum PluginStatus
    1.30 +	{
    1.31 +		Plugin_Running=0,		/* Plugin is running */
    1.32 +		Plugin_Paused,			/* Plugin is paused */
    1.33 +		Plugin_Stopped,			/* Plugin is paused for map changes, too */
    1.34 +		Plugin_Error,			/* Plugin has a blocking error */
    1.35 +		Plugin_BadLoad,			/* Plugin failed to load */
    1.36 +	};
    1.37 +
    1.38 +	/**
    1.39 +	 * @brief Describes the object lifetime of a plugin.
    1.40 +	 */
    1.41 +	enum PluginLifetime
    1.42 +	{
    1.43 +		PluginLifetime_Forever,			/* Plugin will never be unloaded */
    1.44 +		PluginLifetime_Map				/* Plugin will be unloaded at mapchange */
    1.45 +	};
    1.46 +
    1.47 +
    1.48 +	/**
    1.49 +	 * @brief Encapsulates a run-time plugin as maintained by SourceMod.
    1.50 +	 */
    1.51  	class IPlugin : public IUnloadableParent
    1.52  	{
    1.53  	public:
    1.54 @@ -15,14 +53,108 @@
    1.55  		{
    1.56  			return ParentType_Module;
    1.57  		}
    1.58 +	public:
    1.59 +		/**
    1.60 +		 * @brief Returns the lifetime of a plugin.
    1.61 +		 */
    1.62 +		virtual PluginLifetime GetLifetime() =0;
    1.63 +
    1.64 +		/**
    1.65 +		 * @brief Returns the current API context being used in the plugin.
    1.66 +		 *
    1.67 +		 * @return	Pointer to an IPluginContext, or NULL if not loaded.
    1.68 +		 */
    1.69 +		virtual SourcePawn::IPluginContext *GetBaseContext() =0;
    1.70 +
    1.71 +		/**
    1.72 +		 * @brief Returns the context structure being used in the plugin.
    1.73 +		 *
    1.74 +		 * @brief	Pointer to an sp_context_t, or NULL if not loaded.
    1.75 +		 */
    1.76 +		virtual sp_context_t *GetContext() =0;
    1.77 +
    1.78 +		/**
    1.79 +		 * @brief Returns information about the plugin.
    1.80 +		 *
    1.81 +		 * @brief	Pointer to an sm_plugininfo_t, or NULL if not loaded.
    1.82 +		 */
    1.83 +		virtual sm_plugininfo_t *GetPublicInfo() =0;
    1.84 +
    1.85 +		/**
    1.86 +		 * @brief Returns the plugin filename (relative to plugins dir).
    1.87 +		 */
    1.88 +		virtual const char *GetFilename() =0;
    1.89 +
    1.90 +		/**
    1.91 +		 * @brief Returns true if a plugin is in debug mode, false otherwise.
    1.92 +		 */
    1.93 +		virtual bool IsDebugging() =0;
    1.94 +
    1.95 +		/**
    1.96 +		 * @brief Returns the plugin status.
    1.97 +		 */
    1.98 +		virtual PluginStatus GetStatus() =0;
    1.99 +		
   1.100 +		/**
   1.101 +		 * @brief Sets whether the plugin is paused or not.
   1.102 +		 *
   1.103 +		 * @return			True on successful pause, false otherwise.
   1.104 +		 */
   1.105 +		virtual bool SetPauseState(bool paused) =0;
   1.106 +
   1.107 +		/**
   1.108 +		 * @brief Locks or unlocks the plugin from being updated on mapchange.
   1.109 +		 */
   1.110 +		virtual void SetLockForUpdates(bool lock_status) =0;
   1.111 +
   1.112 +		/**
   1.113 +		 * @brief Returns whether the plugin is locked from being updated on mapchange.
   1.114 +		 */
   1.115 +		virtual bool GetLockForUpdates() =0;
   1.116 +
   1.117 +		/**
   1.118 +		 * @brief Returns the unique serial number of a plugin.
   1.119 +		 */
   1.120 +		virtual unsigned int GetSerial() =0;
   1.121  	};
   1.122  
   1.123 -	enum PluginLifetime
   1.124 +
   1.125 +	/**
   1.126 +	 * @brief Iterates over a list of plugins.
   1.127 +	 */
   1.128 +	class IPluginIterator
   1.129  	{
   1.130 -		PluginLifetime_Forever,
   1.131 -		PluginLifetime_Map
   1.132 +	public:
   1.133 +		virtual void ~IPluginIterator()
   1.134 +		{
   1.135 +		};
   1.136 +	public:
   1.137 +		/**
   1.138 +		 * @brief Returns true if there are more plugins in the iterator.
   1.139 +		 */
   1.140 +		virtual bool MorePlugins() =0;
   1.141 +
   1.142 +		/**
   1.143 +		 * @brief Returns the plugin at the current iterator position.
   1.144 +		 */
   1.145 +		virtual IPlugin *GetPlugin() =0;
   1.146 +
   1.147 +		/**
   1.148 +		 * @brief Advances to the next plugin in the iterator.
   1.149 +		 */
   1.150 +		virtual void NextPlugin() =0;
   1.151 +
   1.152 +		/**
   1.153 +		 * @brief Destroys the iterator object.
   1.154 +		 * Note: You may use 'delete' in lieu of this function.
   1.155 +		 */
   1.156 +		virtual void Release() =0;
   1.157  	};
   1.158  
   1.159 +
   1.160 +	/**
   1.161 +	 * @brief Manages the runtime loading and unloading of plugins.
   1.162 +	 */
   1.163  	class IPluginManager : public SMInterface
   1.164  	{
   1.165  	public:
   1.166 @@ -40,7 +172,6 @@
   1.167  		 * @brief Attempts to load a plugin.
   1.168  		 *
   1.169  		 * @param path		Path and filename of plugin, relative to plugins folder.
   1.170 -		 * @param extended	Whether or not the plugin is a static plugin or optional plugin.
   1.171  		 * @param debug		Whether or not to default the plugin into debug mode.
   1.172  		 * @param lifetime	Lifetime of the plugin.
   1.173  		 * @param error		Buffer to hold any error message.
   1.174 @@ -48,11 +179,40 @@
   1.175  		 * @return			A new plugin pointer on success, false otherwise.
   1.176  		 */
   1.177  		virtual IPlugin *LoadPlugin(const char *path, 
   1.178 -									bool extended, 
   1.179  									bool debug,
   1.180  									PluginLifetime lifetime,
   1.181  									char error[],
   1.182  									size_t err_max) =0;
   1.183 +
   1.184 +		/**
   1.185 +		 * @brief Attempts to unload a plugin.
   1.186 +		 *
   1.187 +		 * @param			Pointer to the plugin handle.
   1.188 +		 * @return			True on success, false otherwise.
   1.189 +		 */
   1.190 +		virtual bool UnloadPlugin(IPlugin *plugin) =0;
   1.191 +
   1.192 +		/**
   1.193 +		 * @brief Finds a plugin by its context.
   1.194 +		 * Note: This function should be considered O(1).
   1.195 +		 *
   1.196 +		 * @param			Pointer to an sp_context_t.
   1.197 +		 * @return			Pointer to a matching IPlugin, or NULL if none found.
   1.198 +		 */
   1.199 +		virtual IPlugin *FindPluginByContext(const sp_context_t *ctx) =0;
   1.200 +
   1.201 +		/**
   1.202 +		 * @brief Returns the number of plugins (both failed and loaded).
   1.203 +		 *
   1.204 +		 * @return			The number of internally cached plugins.
   1.205 +		 */
   1.206 +		virtual unsigned int GetPluginCount() =0;
   1.207 +
   1.208 +		/**
   1.209 +		 * @brief Returns a pointer that can be used to iterate through plugins.
   1.210 +		 * Note: This pointer must be freed using EITHER delete OR IPluginIterator::Release().
   1.211 +		 */
   1.212 +		virtual IPluginIterator *GetPluginIterator() =0;
   1.213  	};
   1.214  };
   1.215