1 /* ======== SourceMM ========
2 * Copyright (C) 2004-2006 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): David "BAILOPAN" Anderson
8 * ============================
11 #ifndef _INCLUDE_CPLUGIN_H
12 #define _INCLUDE_CPLUGIN_H
15 * @brief Implementation of Plugin API and Management routines
19 #include <interface.h>
22 #include "IPluginManager.h"
25 #include "sh_string.h"
28 * History of plugin versions: (M=min, C=current)
29 * 1: Initial interface
30 * 2: Added GetLogTag()
31 * 3: Moved GetApiVersion() to top (2005-04-16)
32 * 4: Added AllPluginsLoaded() callback (2005-04-18)
33 * 5: Bumped version for SourceHook V4 (2005-05-01)
34 * 6: Added functions for console printing (2005-05-26)
35 * M 7: Changed template libraries (2005-08-11)
36 * New loading structure mechanism
37 * New SourceHook version
38 * C 8: New SourceHook version (2005-12-23)
39 * New ISmmAPI additions
42 #define PLAPI_MIN_VERSION 7
48 SourceHook::String alias;
49 SourceHook::String value;
52 * @brief Implements Plugin Manager API
54 class CPluginManager : public ISmmPluginManager
58 * @brief Internal structure for holding plugin data
66 SourceHook::String m_File;
71 SourceHook::List<ConCommandBase *> m_Cvars;
72 SourceHook::List<ConCommandBase *> m_Cmds;
73 SourceHook::List<IMetamodListener *> m_Events;
80 PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen);
81 bool Unload(PluginId id, bool force, char *error, size_t maxlen);
82 bool Pause(PluginId id, char *error, size_t maxlen);
83 bool Unpause(PluginId id, char *error, size_t maxlen);
85 void SetAlias(const char *alias, const char *value);
87 bool Query(PluginId id, const char *&file, Pl_Status &status, PluginId &source);
88 bool QueryRunning(PluginId id, char *error, size_t maxlength);
90 void AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
91 void AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
92 void RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
93 void RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
96 * @brief Finds a plugin by Id
98 * @param id Id of plugin
99 * @return CPlugin on success, NULL otherwise
101 CPlugin *FindById(PluginId id);
103 CPlugin *FindByAPI(ISmmPlugin *api);
106 * @brief Attempts to reload a failed plugin
108 * @param id Id of plugin
109 * @param error Error message buffer
110 * @param len Maximum length of buffer
111 * @return True on success, false otherwise
113 bool Retry(PluginId id, char *error, size_t len);
116 const char *LookupAlias(const char *alias);
117 SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_begin();
118 SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_end();
121 SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _begin();
122 SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _end();
124 //These are identical internal functions for the wrappers above.
125 CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen);
126 bool _Unload(CPlugin *pl, bool force, char *error, size_t maxlen);
127 bool _Pause(CPlugin *pl, char *error, size_t maxlen);
128 bool _Unpause(CPlugin *pl, char *error, size_t maxlen);
129 void UnregAllConCmds(CPlugin *pl);
132 SourceHook::List<CPlugin *> m_Plugins;
133 SourceHook::List<CNameAlias *> m_Aliases;
138 typedef SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator PluginIter;
140 /** @brief Singleton for plugin manager */
141 extern SourceMM::CPluginManager g_PluginMngr;
143 #endif //_INCLUDE_CPLUGIN_H