core/interfaces/IModuleSys.h
changeset 140 2c25d4131b38
child 211 4c77142eaf36
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/interfaces/IModuleSys.h	Sun Nov 05 00:29:44 2006 +0000
     1.3 @@ -0,0 +1,92 @@
     1.4 +#ifndef _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
     1.5 +#define _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
     1.6 +
     1.7 +#include <IShareSys.h>
     1.8 +#include <ILibrarySys.h>
     1.9 +
    1.10 +namespace SourceMod
    1.11 +{
    1.12 +	class IModuleInterface;
    1.13 +
    1.14 +	class IModule : public IUnloadableParent
    1.15 +	{
    1.16 +	public:
    1.17 +		virtual UnloadableParentType GetParentType()
    1.18 +		{
    1.19 +			return ParentType_Module;
    1.20 +		}
    1.21 +	public:
    1.22 +		virtual IModuleInterface *GetModuleInfo() =0;
    1.23 +		virtual const char *GetFilename() =0;
    1.24 +	};
    1.25 +
    1.26 +	class IModuleInterface
    1.27 +	{
    1.28 +	public:
    1.29 +		/**
    1.30 +		 * @brief Called when the module is loaded.
    1.31 +		 * 
    1.32 +		 * @param me		Pointer back to module.
    1.33 +		 * @param sys		Pointer to interface sharing system of SourceMod.
    1.34 +		 * @param error		Error buffer to print back to, if any.
    1.35 +		 * @param err_max	Maximum size of error buffer.
    1.36 +		 * @param late		If this module was loaded "late" (i.e. manually).
    1.37 +		 * @return			True if load should continue, false otherwise.
    1.38 +		 */
    1.39 +		virtual bool OnModuleLoad(IModule *me, IShareSys *sys, char *error, size_t err_max, bool late) =0;
    1.40 +
    1.41 +		/**
    1.42 +		 * @brief Called when the module is unloaded.
    1.43 +		 *
    1.44 +		 * @param force		True if this unload will be forced.
    1.45 +		 * @param error		Error message buffer.
    1.46 +		 * @param err_max	Maximum siez of error buffer.
    1.47 +		 * @return			True on success, false to request no unload.
    1.48 +		 */
    1.49 +		virtual bool OnModuleUnload(bool force, char *error, size_t err_max) =0;
    1.50 +
    1.51 +		/**
    1.52 +		 * @brief Called when your pause state is about to change.
    1.53 +		 * 
    1.54 +		 * @param pause		True if pausing, false if unpausing.
    1.55 +		 */
    1.56 +		virtual void OnPauseChange(bool pause) =0;
    1.57 +
    1.58 +	public:
    1.59 +		virtual const char *GetModuleName() =0;
    1.60 +		virtual const char *GetModuleVersion() =0;
    1.61 +		virtual const char *GetModuleURL() =0;
    1.62 +		virtual const char *GetModuleTags() =0;
    1.63 +		virtual const char *GetModuleAuthor() =0;
    1.64 +	};
    1.65 +
    1.66 +	#define SMINTERFACE_MODULEMANAGER_NAME		"IModuleManager"
    1.67 +	#define SMINTERFACE_MODULEMANAGER_VERSION		1
    1.68 +
    1.69 +	enum ModuleLifetime
    1.70 +	{
    1.71 +		ModuleLifetime_Forever,				//Module will never be unloaded automatically
    1.72 +		ModuleLifetime_Map,					//Module will be unloaded at the end of the map
    1.73 +		ModuleLifetime_Dependent,			//Module will be unloaded once its dependencies are gone
    1.74 +	};
    1.75 +
    1.76 +	class IModuleManager : public SMInterface
    1.77 +	{
    1.78 +	public:
    1.79 +		/**
    1.80 +		 * @brief Loads a module into the module system.
    1.81 +		 *
    1.82 +		 * @param path		Path to module file, relative to the modules folder.
    1.83 +		 * @param lifetime	Lifetime of the module.
    1.84 +		 * @param error		Error buffer.
    1.85 +		 * @param err_max	Maximum error buffer length.
    1.86 +		 * @return			New IModule on success, NULL on failure.
    1.87 +		 */
    1.88 +		virtual IModule *LoadModule(const char *path, 
    1.89 +									ModuleLifetime lifetime, 
    1.90 +									char *error,
    1.91 +									size_t err_max);
    1.92 +	};
    1.93 +};
    1.94 +
    1.95 +#endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_