core/systems/ExtensionSys.h
author David Anderson <dvander@alliedmods.net>
Wed Jan 17 03:01:38 2007 +0000 (2007-01-17)
changeset 304 fa485d2f25ed
parent 298 07f6b2fe8468
child 305 59ef1afbe958
permissions -rw-r--r--
Added extension loading/unloading
Extended SDK for interface sharing
Completed Metamod extension support
     1 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
     2 #define _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
     3 
     4 #include <IExtensionSys.h>
     5 #include <ILibrarySys.h>
     6 #include <sh_list.h>
     7 #include <sh_string.h>
     8 #include "sm_globals.h"
     9 #include "ShareSys.h"
    10 #include <ISmmAPI.h>
    11 
    12 using namespace SourceMod;
    13 using namespace SourceHook;
    14 
    15 class CExtension : public IExtension
    16 {
    17 	friend class CExtensionManager;
    18 public:
    19 	CExtension(const char *filename, char *error, size_t maxlen);
    20 	~CExtension();
    21 public: //IExtension
    22 	IExtensionInterface *GetAPI();
    23 	const char *GetFilename();
    24 	IdentityToken_t *GetIdentity();
    25 	bool IsLoaded();
    26 	ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface);
    27 	bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface);
    28 	void FreeDependencyIterator(ITERATOR *iter);
    29 public:
    30 	void SetError(const char *error);
    31 	void AddDependency(IfaceInfo *pInfo);
    32 	void AddInterface(SMInterface *pInterface);
    33 private:
    34 	IdentityToken_t *m_pIdentToken;
    35 	IExtensionInterface *m_pAPI;
    36 	String m_File;
    37 	ILibrary *m_pLib;
    38 	String m_Error;
    39 	List<IfaceInfo> m_Deps;
    40 	List<SMInterface *> m_Interfaces;
    41 	PluginId m_PlId;
    42 };
    43 
    44 class CExtensionManager : 
    45 	public IExtensionManager,
    46 	public SMGlobalClass
    47 {
    48 public: //SMGlobalClass
    49 	void OnSourceModAllInitialized();
    50 	void OnSourceModShutdown();
    51 public: //IExtensionManager
    52 	IExtension *LoadExtension(const char *path, 
    53 		ExtensionLifetime lifetime, 
    54 		char *error,
    55 		size_t err_max);
    56 	bool UnloadExtension(IExtension *pExt);
    57 	IExtension *FindExtensionByFile(const char *file);
    58 	IExtension *FindExtensionByName(const char *ext);
    59 public:
    60 	IExtension *LoadAutoExtension(const char *path);
    61 	void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
    62 	void AddInterface(IExtension *pOwner, SMInterface *pInterface);
    63 private:
    64 	List<CExtension *> m_Libs;
    65 };
    66 
    67 extern CExtensionManager g_Extensions;
    68 
    69 #endif //_INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_