3 * ======================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC and authors.
7 * ======================================================
9 * This software is provided 'as-is', without any express or implied warranty.
10 * In no event will the authors be held liable for any damages arising from
11 * the use of this software.
13 * Permission is granted to anyone to use this software for any purpose,
14 * including commercial applications, and to alter it and redistribute it
15 * freely, subject to the following restrictions:
17 * 1. The origin of this software must not be misrepresented; you must not
18 * claim that you wrote the original software. If you use this software in a
19 * product, an acknowledgment in the product documentation would be
20 * appreciated but is not required.
21 * 2. Altered source versions must be plainly marked as such, and must not be
22 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
28 #ifndef _INCLUDE_CPLUGIN_H
29 #define _INCLUDE_CPLUGIN_H
32 * @brief Implementation of Plugin API and Management routines
36 #include <interface.h>
40 #include <sh_string.h>
41 #include <IPluginManager.h>
42 #include <ISmmPluginExt.h>
43 #include "metamod_oslink.h"
46 * History of plugin versions: (M=min, C=current)
47 * 1: Initial interface
48 * 2: Added GetLogTag()
49 * 3: Moved GetApiVersion() to top (2005-04-16)
50 * 4: Added AllPluginsLoaded() callback (2005-04-18)
51 * 5: Bumped version for SourceHook V4 (2005-05-01)
52 * 6: Added functions for console printing (2005-05-26)
53 * 7: Changed template libraries (2005-08-11)
54 * New loading structure mechanism
55 * New SourceHook version
56 * 8: New SourceHook version (2005-12-23)
57 * New ISmmAPI additions
58 * 9: New ISmmPluginManager additions
59 * 10: Added VSP listen functions to ISmmAPI and IMetamodListener (2007-02-09)
60 * 11: New SourceHook version v4.5 (May, 2007)
62 * 13: Breaking of API for next SH version and other API changes
63 * MC 14: ABI stability reached for 1.6.0 changes
66 #define PLAPI_MIN_VERSION 14
70 SourceHook::String alias;
71 SourceHook::String value;
74 * @brief Implements Plugin Manager API
76 class CPluginManager : public ISmmPluginManager
80 * @brief Internal structure for holding plugin data
88 SourceHook::String m_File;
93 SourceHook::List<ConCommandBase *> m_Cvars;
94 SourceHook::List<ConCommandBase *> m_Cmds;
95 SourceHook::List<IMetamodListener *> m_Events;
96 METAMOD_FN_UNLOAD m_UnloadFn;
103 PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen);
104 bool Unload(PluginId id, bool force, char *error, size_t maxlen);
105 bool Pause(PluginId id, char *error, size_t maxlen);
106 bool Unpause(PluginId id, char *error, size_t maxlen);
108 void SetAlias(const char *alias, const char *value);
110 bool Query(PluginId id, const char **file, Pl_Status *status, PluginId *source);
111 bool QueryRunning(PluginId id, char *error, size_t maxlength);
112 bool QueryHandle(PluginId id, void **handle);
114 void AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
115 void AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
116 void RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
117 void RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
120 * @brief Finds a plugin by Id
122 * @param id Id of plugin
123 * @return CPlugin on success, NULL otherwise
125 CPlugin *FindById(PluginId id);
127 CPlugin *FindByAPI(ISmmPlugin *api);
130 * @brief Attempts to reload a failed plugin
132 * @param id Id of plugin
133 * @param error Error message buffer
134 * @param len Maximum length of buffer
135 * @return True on success, false otherwise
137 bool Retry(PluginId id, char *error, size_t len);
139 int GetPluginCount();
140 const char *GetStatusText(CPlugin *pl);
143 const char *LookupAlias(const char *alias);
144 SourceHook::List<CNameAlias *>::iterator _alias_begin();
145 SourceHook::List<CNameAlias *>::iterator _alias_end();
148 SourceHook::List<CPluginManager::CPlugin *>::iterator _begin();
149 SourceHook::List<CPluginManager::CPlugin *>::iterator _end();
151 //These are identical internal functions for the wrappers above.
152 CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen);
153 bool _Unload(CPlugin *pl, bool force, char *error, size_t maxlen);
154 bool _Pause(CPlugin *pl, char *error, size_t maxlen);
155 bool _Unpause(CPlugin *pl, char *error, size_t maxlen);
156 void UnregAllConCmds(CPlugin *pl);
159 SourceHook::List<CPlugin *> m_Plugins;
160 SourceHook::List<CNameAlias *> m_Aliases;
164 typedef SourceHook::List<CPluginManager::CPlugin *>::iterator PluginIter;
166 /** @brief Singleton for plugin manager */
167 extern CPluginManager g_PluginMngr;
169 #endif //_INCLUDE_CPLUGIN_H