sourcemm/CPlugin.h
author Scott Ehlert <ds@alliedmods.net>
Sun May 22 04:33:58 2005 +0000 (2005-05-22)
changeset 66 ddefc8bfb9fa
parent 51 7985801b5b42
child 67 1753f7a9b2f2
permissions -rw-r--r--
Added macro so that ConCommands created with the SDK's CON_COMMAND and CON_COMMAND_F macros can be properly registered and unregisterd
     1 /* ======== SourceMM ========
     2 * Copyright (C) 2004-2005 Metamod:Source Development Team
     3 * No warranties of any kind
     4 *
     5 * License: zlib/libpng
     6 *
     7 * Author(s): David "BAILOPAN" Anderson
     8 * ============================
     9 */
    10 
    11 #ifndef _INCLUDE_CPLUGIN_H
    12 #define _INCLUDE_CPLUGIN_H
    13 
    14 /**
    15  * @brief Implementation of Plugin API and Management routines
    16  * @file CPlugin.cpp
    17  */
    18 
    19 #include <list>
    20 #include <string>
    21 #include "IPluginManager.h"
    22 #include "oslink.h"
    23 
    24 /**
    25  * History of plugin versions: (M=min, C=current)
    26  *    1: Initial interface
    27  *    2: Added GetLogTag()
    28  *    3: Moved GetApiVersion() to top  (2005-04-16)
    29  *    4: Added AllPluginsLoaded() callback (2005-04-18)
    30  * MC 5: Bumped version for SourceHook V4 (2005-05-01)
    31  */
    32 
    33 #define PLAPI_MIN_VERSION	5
    34 
    35 namespace SourceMM
    36 {
    37 	/**
    38 	 * @brief Implements Plugin Manager API
    39 	 */
    40 	class CPluginManager : public ISmmPluginManager
    41 	{	
    42 	public:
    43 		/**
    44 		 * @brief Internal structure for holding plugin data
    45 		 */
    46 		class CPlugin
    47 		{
    48 		public:
    49 			CPlugin();
    50 		public:
    51 			PluginId m_Id;
    52 			std::string m_File;
    53 			Pl_Status m_Status;
    54 			PluginId m_Source;
    55 			ISmmPlugin *m_API;
    56 			HINSTANCE m_Lib;
    57 			factories fac_list;
    58 		};
    59 	public:
    60 		CPluginManager();
    61 		~CPluginManager();
    62 		void SetAllLoaded();
    63 	public:
    64 		PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen);
    65 		bool Unload(PluginId id, bool force, char *error, size_t maxlen);
    66 		bool Pause(PluginId id, char *error, size_t maxlen);
    67 		bool Unpause(PluginId id, char *error, size_t maxlen);
    68 		bool UnloadAll();
    69 	public:
    70 		bool Query(PluginId id, const char *&file, factories *&list, Pl_Status &status, PluginId &source);
    71 
    72 		/**
    73 		 * @brief Finds a plugin by Id
    74 		 *
    75 		 * @param id Id of plugin
    76 		 * @return CPlugin on success, NULL otherwise
    77 		 */
    78 		CPlugin *FindById(PluginId id);
    79 
    80 		/**
    81 		 * @brief Attempts to reload a failed plugin
    82 		 *
    83 		 * @param id Id of plugin
    84 		 * @param error Error message buffer
    85 		 * @param len Maximum length of buffer
    86 		 * @return True on success, false otherwise
    87 		 */
    88 		bool Retry(PluginId id, char *error, size_t len);
    89 
    90 		//Internal iterators
    91 		std::list<SourceMM::CPluginManager::CPlugin *>::iterator _begin();
    92 		std::list<SourceMM::CPluginManager::CPlugin *>::iterator _end();
    93 	private:
    94 		//These are identical internal functions for the wrappers above.
    95 		CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen);
    96 		bool _Unload(CPlugin *pl, bool force, char *error, size_t maxlen);
    97 		bool _Pause(CPlugin *pl, char *error, size_t maxlen);
    98 		bool _Unpause(CPlugin *pl, char *error, size_t maxlen);
    99 	private:
   100 		PluginId m_LastId;
   101 		std::list<CPlugin *> m_Plugins;
   102 		bool m_AllLoaded;
   103 	};
   104 };
   105 
   106 typedef std::list<SourceMM::CPluginManager::CPlugin *>::iterator PluginIter;
   107 
   108 /** @brief Singleton for plugin manager */
   109 extern SourceMM::CPluginManager g_PluginMngr;
   110 
   111 #endif //_INCLUDE_CPLUGIN_H