1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/ExtensionSys.h Wed Nov 19 02:16:45 2008 -0600
1.3 @@ -0,0 +1,186 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod
1.8 + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
1.9 + * =============================================================================
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify it under
1.12 + * the terms of the GNU General Public License, version 3.0, as published by the
1.13 + * Free Software Foundation.
1.14 + *
1.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 + * details.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License along with
1.21 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.22 + *
1.23 + * As a special exception, AlliedModders LLC gives you permission to link the
1.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
1.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.26 + * by the Valve Corporation. You must obey the GNU General Public License in
1.27 + * all respects for all other code used. Additionally, AlliedModders LLC grants
1.28 + * this exception to all derivative works. AlliedModders LLC defines further
1.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.30 + * or <http://www.sourcemod.net/license.php>.
1.31 + *
1.32 + * Version: $Id$
1.33 + */
1.34 +
1.35 +#ifndef _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
1.36 +#define _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
1.37 +
1.38 +#include <IExtensionSys.h>
1.39 +#include <ILibrarySys.h>
1.40 +#include <sh_list.h>
1.41 +#include <sh_string.h>
1.42 +#include <sm_trie_tpl.h>
1.43 +#include "sm_globals.h"
1.44 +#include "ShareSys.h"
1.45 +#include <ISmmAPI.h>
1.46 +#include <IPluginSys.h>
1.47 +#include <IRootConsoleMenu.h>
1.48 +#include "PluginSys.h"
1.49 +#include "NativeOwner.h"
1.50 +
1.51 +using namespace SourceMod;
1.52 +using namespace SourceHook;
1.53 +
1.54 +class CExtension;
1.55 +
1.56 +struct sm_extnative_t
1.57 +{
1.58 + CExtension *owner;
1.59 + const sp_nativeinfo_t *info;
1.60 +};
1.61 +
1.62 +class CExtension :
1.63 + public IExtension,
1.64 + public CNativeOwner
1.65 +{
1.66 + friend class CExtensionManager;
1.67 +public:
1.68 + virtual ~CExtension();
1.69 +public: //IExtension
1.70 + IExtensionInterface *GetAPI();
1.71 + const char *GetFilename();
1.72 + IdentityToken_t *GetIdentity();
1.73 + ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface);
1.74 + bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface);
1.75 + void FreeDependencyIterator(ITERATOR *iter);
1.76 + bool IsRunning(char *error, size_t maxlength);
1.77 +public:
1.78 + void SetError(const char *error);
1.79 + void AddDependency(const IfaceInfo *pInfo);
1.80 + void AddChildDependent(CExtension *pOther, SMInterface *iface);
1.81 + void AddInterface(SMInterface *pInterface);
1.82 + void AddPlugin(CPlugin *pPlugin);
1.83 + void MarkAllLoaded();
1.84 + void AddLibrary(const char *library);
1.85 +public:
1.86 + virtual bool Load(char *error, size_t maxlength);
1.87 + virtual bool IsLoaded() =0;
1.88 + virtual void Unload() =0;
1.89 +protected:
1.90 + void Initialize(const char *filename, const char *path);
1.91 + bool PerformAPICheck(char *error, size_t maxlength);
1.92 + void CreateIdentity();
1.93 + void DestroyIdentity();
1.94 +protected:
1.95 + IdentityToken_t *m_pIdentToken;
1.96 + IExtensionInterface *m_pAPI;
1.97 + String m_File;
1.98 + String m_Path;
1.99 + String m_Error;
1.100 + List<IfaceInfo> m_Deps; /** Dependencies */
1.101 + List<IfaceInfo> m_ChildDeps; /** Children who might depend on us */
1.102 + List<SMInterface *> m_Interfaces;
1.103 + List<String> m_Libraries;
1.104 + unsigned int unload_code;
1.105 + bool m_bFullyLoaded;
1.106 +};
1.107 +
1.108 +class CLocalExtension : public CExtension
1.109 +{
1.110 +public:
1.111 + CLocalExtension(const char *filename);
1.112 +public:
1.113 + bool Load(char *error, size_t maxlength);
1.114 + bool IsLoaded();
1.115 + void Unload();
1.116 + bool IsExternal();
1.117 +private:
1.118 + PluginId m_PlId;
1.119 + ILibrary *m_pLib;
1.120 +};
1.121 +
1.122 +class CRemoteExtension : public CExtension
1.123 +{
1.124 +public:
1.125 + CRemoteExtension(IExtensionInterface *pAPI, const char *filename, const char *path);
1.126 +public:
1.127 + bool Load(char *error, size_t maxlength);
1.128 + bool IsLoaded();
1.129 + void Unload();
1.130 + bool IsExternal();
1.131 +};
1.132 +
1.133 +class CExtensionManager :
1.134 + public IExtensionManager,
1.135 + public SMGlobalClass,
1.136 + public IPluginsListener,
1.137 + public IRootConsoleCommand
1.138 +{
1.139 +public:
1.140 + CExtensionManager();
1.141 + ~CExtensionManager();
1.142 +public: //SMGlobalClass
1.143 + void OnSourceModAllInitialized();
1.144 + void OnSourceModShutdown();
1.145 +public: //IExtensionManager
1.146 + IExtension *LoadExtension(const char *path,
1.147 + char *error,
1.148 + size_t maxlength);
1.149 + bool UnloadExtension(IExtension *pExt);
1.150 + IExtension *FindExtensionByFile(const char *file);
1.151 + IExtension *FindExtensionByName(const char *ext);
1.152 + IExtension *LoadExternal(IExtensionInterface *pInterface,
1.153 + const char *filepath,
1.154 + const char *filename,
1.155 + char *error,
1.156 + size_t maxlength);
1.157 +public: //IPluginsListener
1.158 + void OnPluginDestroyed(IPlugin *plugin);
1.159 +public: //IRootConsoleCommand
1.160 + void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
1.161 +public:
1.162 + IExtension *LoadAutoExtension(const char *path);
1.163 + void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
1.164 + void AddInterface(IExtension *pOwner, SMInterface *pInterface);
1.165 + void BindChildPlugin(IExtension *pParent, CPlugin *pPlugin);
1.166 + void MarkAllLoaded();
1.167 + void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
1.168 + void TryAutoload();
1.169 + void AddLibrary(IExtension *pSource, const char *library);
1.170 + bool LibraryExists(const char *library);
1.171 + void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
1.172 + void AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface);
1.173 +public:
1.174 + CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
1.175 + void Shutdown();
1.176 + CNativeOwner *GetNativeOwner(IExtension *pExt)
1.177 + {
1.178 + CExtension *p = (CExtension *)pExt;
1.179 + return p;
1.180 + }
1.181 +private:
1.182 + CExtension *FindByOrder(unsigned int num);
1.183 +private:
1.184 + List<CExtension *> m_Libs;
1.185 +};
1.186 +
1.187 +extern CExtensionManager g_Extensions;
1.188 +
1.189 +#endif //_INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_