3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
33 #define _INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_
35 #include <IExtensionSys.h>
36 #include <ILibrarySys.h>
38 #include <sh_string.h>
39 #include <sm_trie_tpl.h>
40 #include "sm_globals.h"
43 #include <IPluginSys.h>
44 #include <IRootConsoleMenu.h>
45 #include "PluginSys.h"
47 using namespace SourceMod;
48 using namespace SourceHook;
55 const sp_nativeinfo_t *info;
58 class CExtension : public IExtension
60 friend class CExtensionManager;
62 CExtension(const char *filename, char *error, size_t maxlen);
65 IExtensionInterface *GetAPI();
66 const char *GetFilename();
67 IdentityToken_t *GetIdentity();
69 ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface);
70 bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface);
71 void FreeDependencyIterator(ITERATOR *iter);
72 bool IsRunning(char *error, size_t maxlength);
74 void SetError(const char *error);
75 void AddDependency(IfaceInfo *pInfo);
76 void AddChildDependent(CExtension *pOther, SMInterface *iface);
77 void AddInterface(SMInterface *pInterface);
78 void AddPlugin(IPlugin *pPlugin);
79 void RemovePlugin(IPlugin *pPlugin);
82 bool Load(char *error, size_t maxlength);
84 IdentityToken_t *m_pIdentToken;
85 IExtensionInterface *m_pAPI;
90 List<IfaceInfo> m_Deps; /** Dependencies */
91 List<IfaceInfo> m_ChildDeps; /** Children who might depend on us */
92 List<SMInterface *> m_Interfaces;
93 List<IPlugin *> m_Plugins;
94 List<const sp_nativeinfo_t *> m_Natives;
95 List<WeakNative> m_WeakNatives;
97 unsigned int unload_code;
101 class CExtensionManager :
102 public IExtensionManager,
103 public SMGlobalClass,
104 public IPluginsListener,
105 public IRootConsoleCommand
109 ~CExtensionManager();
110 public: //SMGlobalClass
111 void OnSourceModAllInitialized();
112 void OnSourceModShutdown();
113 public: //IExtensionManager
114 IExtension *LoadExtension(const char *path,
115 ExtensionLifetime lifetime,
118 bool UnloadExtension(IExtension *pExt);
119 IExtension *FindExtensionByFile(const char *file);
120 IExtension *FindExtensionByName(const char *ext);
121 public: //IPluginsListener
122 void OnPluginDestroyed(IPlugin *plugin);
123 public: //IRootConsoleCommand
124 void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
126 IExtension *LoadAutoExtension(const char *path);
127 void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
128 void AddInterface(IExtension *pOwner, SMInterface *pInterface);
129 void BindChildPlugin(IExtension *pParent, IPlugin *pPlugin);
130 void AddNatives(IExtension *pOwner, const sp_nativeinfo_t *natives);
131 void BindAllNativesToPlugin(IPlugin *pPlugin);
132 void MarkAllLoaded();
133 void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
136 CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
139 CExtension *FindByOrder(unsigned int num);
141 List<CExtension *> m_Libs;
142 KTrie<sm_extnative_t> m_ExtNatives;
145 extern CExtensionManager g_Extensions;
147 #endif //_INCLUDE_SOURCEMOD_EXTENSION_SYSTEM_H_