1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core-1.4/CPlugin.h Fri Nov 14 04:25:40 2008 -0600
1.3 @@ -0,0 +1,157 @@
1.4 +/* ======== SourceMM ========
1.5 +* Copyright (C) 2004-2008 Metamod:Source Development Team
1.6 +* No warranties of any kind
1.7 +*
1.8 +* License: zlib/libpng
1.9 +*
1.10 +* Author(s): David "BAILOPAN" Anderson
1.11 +* ============================
1.12 +*/
1.13 +
1.14 +#ifndef _INCLUDE_CPLUGIN_H
1.15 +#define _INCLUDE_CPLUGIN_H
1.16 +
1.17 +/**
1.18 + * @brief Implementation of Plugin API and Management routines
1.19 + * @file CPlugin.cpp
1.20 + */
1.21 +
1.22 +#include <interface.h>
1.23 +#include <eiface.h>
1.24 +#include "convar_smm.h"
1.25 +#include "IPluginManager.h"
1.26 +#include "oslink.h"
1.27 +#include "sh_list.h"
1.28 +#include "sh_string.h"
1.29 +
1.30 +/**
1.31 + * History of plugin versions: (M=min, C=current)
1.32 + * 1: Initial interface
1.33 + * 2: Added GetLogTag()
1.34 + * 3: Moved GetApiVersion() to top (2005-04-16)
1.35 + * 4: Added AllPluginsLoaded() callback (2005-04-18)
1.36 + * 5: Bumped version for SourceHook V4 (2005-05-01)
1.37 + * 6: Added functions for console printing (2005-05-26)
1.38 + * M 7: Changed template libraries (2005-08-11)
1.39 + * New loading structure mechanism
1.40 + * New SourceHook version
1.41 + * 8: New SourceHook version (2005-12-23)
1.42 + * New ISmmAPI additions
1.43 + * 9: New ISmmPluginManager additions
1.44 + * C 10: Added VSP listen functions to ISmmAPI and IMetamodListener (2007-02-09)
1.45 + */
1.46 +
1.47 +#define PLAPI_MIN_VERSION 7
1.48 +
1.49 +namespace SourceMM
1.50 +{
1.51 + struct CNameAlias
1.52 + {
1.53 + SourceHook::String alias;
1.54 + SourceHook::String value;
1.55 + };
1.56 +
1.57 + struct CPluginEventHandler
1.58 + {
1.59 + bool got_vsp;
1.60 + IMetamodListener *event;
1.61 + };
1.62 +
1.63 + /**
1.64 + * @brief Implements Plugin Manager API
1.65 + */
1.66 + class CPluginManager : public ISmmPluginManager
1.67 + {
1.68 + public:
1.69 + /**
1.70 + * @brief Internal structure for holding plugin data
1.71 + */
1.72 + class CPlugin
1.73 + {
1.74 + public:
1.75 + CPlugin();
1.76 + public:
1.77 + PluginId m_Id;
1.78 + SourceHook::String m_File;
1.79 + Pl_Status m_Status;
1.80 + PluginId m_Source;
1.81 + ISmmPlugin *m_API;
1.82 + HINSTANCE m_Lib;
1.83 + SourceHook::List<ConCommandBase *> m_Cvars;
1.84 + SourceHook::List<ConCommandBase *> m_Cmds;
1.85 + SourceHook::List<CPluginEventHandler> m_Events;
1.86 + };
1.87 + public:
1.88 + CPluginManager();
1.89 + ~CPluginManager();
1.90 + void SetAllLoaded();
1.91 + public:
1.92 + PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen);
1.93 + bool Unload(PluginId id, bool force, char *error, size_t maxlen);
1.94 + bool Pause(PluginId id, char *error, size_t maxlen);
1.95 + bool Unpause(PluginId id, char *error, size_t maxlen);
1.96 + bool UnloadAll();
1.97 + void SetAlias(const char *alias, const char *value);
1.98 + public:
1.99 + bool Query(PluginId id, const char *&file, Pl_Status &status, PluginId &source);
1.100 + bool QueryRunning(PluginId id, char *error, size_t maxlength);
1.101 + bool QueryHandle(PluginId id, void *&handle);
1.102 +
1.103 + void AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
1.104 + void AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
1.105 + void RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
1.106 + void RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
1.107 +
1.108 + /**
1.109 + * @brief Finds a plugin by Id
1.110 + *
1.111 + * @param id Id of plugin
1.112 + * @return CPlugin on success, NULL otherwise
1.113 + */
1.114 + CPlugin *FindById(PluginId id);
1.115 +
1.116 + CPlugin *FindByAPI(ISmmPlugin *api);
1.117 +
1.118 + /**
1.119 + * @brief Attempts to reload a failed plugin
1.120 + *
1.121 + * @param id Id of plugin
1.122 + * @param error Error message buffer
1.123 + * @param len Maximum length of buffer
1.124 + * @return True on success, false otherwise
1.125 + */
1.126 + bool Retry(PluginId id, char *error, size_t len);
1.127 +
1.128 + //get alias info
1.129 + const char *LookupAlias(const char *alias);
1.130 + SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_begin();
1.131 + SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_end();
1.132 +
1.133 + //Internal iterators
1.134 + SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _begin();
1.135 + SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _end();
1.136 +
1.137 + void SetVSPAsLoaded();
1.138 + unsigned int GetPluginCount();
1.139 + const char *GetStatusText(CPlugin *pl);
1.140 + private:
1.141 + //These are identical internal functions for the wrappers above.
1.142 + CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen);
1.143 + bool _Unload(CPlugin *pl, bool force, char *error, size_t maxlen);
1.144 + bool _Pause(CPlugin *pl, char *error, size_t maxlen);
1.145 + bool _Unpause(CPlugin *pl, char *error, size_t maxlen);
1.146 + void UnregAllConCmds(CPlugin *pl);
1.147 + private:
1.148 + PluginId m_LastId;
1.149 + SourceHook::List<CPlugin *> m_Plugins;
1.150 + SourceHook::List<CNameAlias *> m_Aliases;
1.151 + bool m_AllLoaded;
1.152 + };
1.153 +};
1.154 +
1.155 +typedef SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator PluginIter;
1.156 +
1.157 +/** @brief Singleton for plugin manager */
1.158 +extern SourceMM::CPluginManager g_PluginMngr;
1.159 +
1.160 +#endif //_INCLUDE_CPLUGIN_H