core/systems/ExtensionSys.h
author David Anderson <dvander@alliedmods.net>
Sat Jan 27 04:50:33 2007 +0000 (2007-01-27)
changeset 397 d78fcaa24fbb
parent 370 d3a484f98f6d
child 653 ef60870067ff
permissions -rw-r--r--
added autoloading of extensions
     1 /**
     2  * ===============================================================
     3  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     4  * ===============================================================
     5  *
     6  * This file is not open source and may not be copied without explicit
     7  * written permission of AlliedModders LLC.  This file may not be redistributed 
     8  * in whole or significant part.
     9  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    10  *
    11  * Version: $Id$
    12  */
    13 
    14 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
    15 #define _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
    16 
    17 #include <IExtensionSys.h>
    18 #include <ILibrarySys.h>
    19 #include <sh_list.h>
    20 #include <sh_string.h>
    21 #include "sm_globals.h"
    22 #include "ShareSys.h"
    23 #include <ISmmAPI.h>
    24 #include <IPluginSys.h>
    25 #include <IRootConsoleMenu.h>
    26 
    27 using namespace SourceMod;
    28 using namespace SourceHook;
    29 
    30 class CExtension : public IExtension
    31 {
    32 	friend class CExtensionManager;
    33 public:
    34 	CExtension(const char *filename, char *error, size_t maxlen);
    35 	~CExtension();
    36 public: //IExtension
    37 	IExtensionInterface *GetAPI();
    38 	const char *GetFilename();
    39 	IdentityToken_t *GetIdentity();
    40 	bool IsLoaded();
    41 	ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface);
    42 	bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface);
    43 	void FreeDependencyIterator(ITERATOR *iter);
    44 	bool IsRunning(char *error, size_t maxlength);
    45 public:
    46 	void SetError(const char *error);
    47 	void AddDependency(IfaceInfo *pInfo);
    48 	void AddInterface(SMInterface *pInterface);
    49 	void AddPlugin(IPlugin *pPlugin);
    50 	void RemovePlugin(IPlugin *pPlugin);
    51 	void MarkAllLoaded();
    52 private:
    53 	IdentityToken_t *m_pIdentToken;
    54 	IExtensionInterface *m_pAPI;
    55 	String m_File;
    56 	ILibrary *m_pLib;
    57 	String m_Error;
    58 	List<IfaceInfo> m_Deps;
    59 	List<SMInterface *> m_Interfaces;
    60 	List<IPlugin *> m_Plugins;
    61 	List<const sp_nativeinfo_t *> m_Natives;
    62 	PluginId m_PlId;
    63 	unsigned int unload_code;
    64 	bool m_FullyLoaded;
    65 };
    66 
    67 class CExtensionManager : 
    68 	public IExtensionManager,
    69 	public SMGlobalClass,
    70 	public IPluginsListener,
    71 	public IRootConsoleCommand
    72 {
    73 public: //SMGlobalClass
    74 	void OnSourceModAllInitialized();
    75 	void OnSourceModShutdown();
    76 public: //IExtensionManager
    77 	IExtension *LoadExtension(const char *path, 
    78 		ExtensionLifetime lifetime, 
    79 		char *error,
    80 		size_t err_max);
    81 	bool UnloadExtension(IExtension *pExt);
    82 	IExtension *FindExtensionByFile(const char *file);
    83 	IExtension *FindExtensionByName(const char *ext);
    84 public: //IPluginsListener
    85 	void OnPluginDestroyed(IPlugin *plugin);
    86 public: //IRootConsoleCommand
    87 	void OnRootConsoleCommand(const char *cmd, unsigned int argcount);
    88 public:
    89 	IExtension *LoadAutoExtension(const char *path);
    90 	void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
    91 	void AddInterface(IExtension *pOwner, SMInterface *pInterface);
    92 	void BindChildPlugin(IExtension *pParent, IPlugin *pPlugin);
    93 	void AddNatives(IExtension *pOwner, const sp_nativeinfo_t *natives);
    94 	void BindAllNativesToPlugin(IPlugin *pPlugin);
    95 	void MarkAllLoaded();
    96 	void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
    97 	void TryAutoload();
    98 private:
    99 	CExtension *FindByOrder(unsigned int num);
   100 private:
   101 	List<CExtension *> m_Libs;
   102 };
   103 
   104 extern CExtensionManager g_Extensions;
   105 
   106 #endif //_INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_