core/interfaces/IShareSys.h
changeset 140 2c25d4131b38
child 211 4c77142eaf36
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/interfaces/IShareSys.h	Sun Nov 05 00:29:44 2006 +0000
     1.3 @@ -0,0 +1,135 @@
     1.4 +#ifndef _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
     1.5 +#define _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
     1.6 +
     1.7 +namespace SourceMod
     1.8 +{
     1.9 +	/**
    1.10 +	 * @brief Defines the base functionality required by a shared interface.
    1.11 +	 */
    1.12 +	class SMInterface
    1.13 +	{
    1.14 +	public:
    1.15 +		/**
    1.16 +		 * @brief Must return an integer defining the interface's version.
    1.17 +		 */
    1.18 +		virtual unsigned int GetInterfaceVersion() =0;
    1.19 +
    1.20 +		/**
    1.21 +		 * @brief Must return a string defining the interface's unique name.
    1.22 +		 */
    1.23 +		virtual const char *GetInterfaceName() =0;
    1.24 +
    1.25 +		/**
    1.26 +		 * @brief Must return whether the requested version number is backwards comaptible.
    1.27 +		 * Note: This can be overridden for breaking changes or custom versioning.
    1.28 +		 * 
    1.29 +		 * @param version		Version number to compare against.
    1.30 +		 * @return				True if compatible, false otherwise.
    1.31 +		 */
    1.32 +		virtual bool IsVersionCompatible(unsigned int version)
    1.33 +		{
    1.34 +			if (version > GetInterfaceVersion())
    1.35 +			{
    1.36 +				return false;
    1.37 +			}
    1.38 +
    1.39 +			return true;
    1.40 +		}
    1.41 +	};
    1.42 +
    1.43 +	enum UnloadableParentType
    1.44 +	{
    1.45 +		ParentType_Module,
    1.46 +		ParentType_Plugin
    1.47 +	};
    1.48 +
    1.49 +	/**
    1.50 +	 * @brief Denotes a top-level unloadable object.
    1.51 +	 */
    1.52 +	class IUnloadableParent
    1.53 +	{
    1.54 +	public:
    1.55 +		virtual UnloadableParentType GetParentType() =0;
    1.56 +
    1.57 +		virtual void *GetParentToken() =0;
    1.58 +	
    1.59 +		/**
    1.60 +		 * @brief Called when an interface this object has requested is removed.
    1.61 +		 *
    1.62 +		 * @param pIface		Interface being removed.
    1.63 +		 */
    1.64 +		virtual void OnInterfaceUnlink(SMInterface *pIface) =0;
    1.65 +	protected:
    1.66 +		void *m_parent_token;
    1.67 +	};
    1.68 +
    1.69 +	/**
    1.70 +	 * @brief Listens for unlinked objects.
    1.71 +	 */
    1.72 +	class IUnlinkListener
    1.73 +	{
    1.74 +	public:
    1.75 +		/**
    1.76 +		 * @brief Called when a parent object is unloaded.
    1.77 +		 *
    1.78 +		 * @param parent		The parent object which is dying.
    1.79 +		 */
    1.80 +		virtual void OnParentUnlink(IUnloadableParent *parent)
    1.81 +		{
    1.82 +		}
    1.83 +	};
    1.84 +
    1.85 +	/**
    1.86 +	 * @brief Tracks dependencies and fires dependency listeners.
    1.87 +	 */
    1.88 +	class IShareSys
    1.89 +	{
    1.90 +	public:
    1.91 +		/**
    1.92 +		 * @brief Adds an interface to the global interface system
    1.93 +		 *
    1.94 +		 * @param iface			Interface pointer (must be unique).
    1.95 +		 * @param parent		Parent unloadable token given to the module/interface.
    1.96 +		 */
    1.97 +		virtual bool AddInterface(SMInterface *iface, IUnloadableParent *parent) =0;
    1.98 +
    1.99 +		/**
   1.100 +		 * @brief Requests an interface from the global interface system.
   1.101 +		 * If found, the interface's internal reference count will be increased.
   1.102 +		 *
   1.103 +		 * @param iface_name	Interface name.
   1.104 +		 * @param iface_vers	Interface version to attempt to match.
   1.105 +		 * @param me			Object requesting this interface, in order to track dependencies.
   1.106 +		 * @param pIface		Pointer to store the return value in.
   1.107 +		 */
   1.108 +		virtual bool RequestInterface(const char *iface_name, 
   1.109 +										unsigned int iface_vers, 
   1.110 +										IUnloadableParent *me,
   1.111 +										void **pIface) =0;
   1.112 +
   1.113 +		/**
   1.114 +		 * @brief Unloads an interface.
   1.115 +		 *
   1.116 +		 * @param iface			Interface pointer.
   1.117 +		 * @param parent		Security token, trivial measure to prevent accidental unloads.
   1.118 +		 *                      This token must match the one used with AddInterface().
   1.119 +		 */
   1.120 +		virtual void RemoveInterface(SMInterface *iface, IUnloadableParent *parent) =0;
   1.121 +
   1.122 +		/**
   1.123 +		 * @brief Adds an unlink listener.
   1.124 +		 *
   1.125 +		 * @param pListener		Listener pointer.
   1.126 +		 */
   1.127 +		virtual void AddUnlinkListener(IUnlinkListener *pListener) =0;
   1.128 +
   1.129 +		/**
   1.130 +		 * @brief Removes an unlink listener.
   1.131 +		 *
   1.132 +		 * @param pListener		Listener pointer.
   1.133 +		 */
   1.134 +		virtual void RemoveUnlinkListener(IUnlinkListener *pListener) =0;
   1.135 +	};
   1.136 +};
   1.137 +
   1.138 +#endif //_INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_