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