SourceMod SDK  1.7
IPluginSys.h
Go to the documentation of this file.
1 
32 #ifndef _INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
33 #define _INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
34 
40 #include <IShareSys.h>
41 #include <IHandleSys.h>
42 #include <sp_vm_api.h>
43 
44 #define SMINTERFACE_PLUGINSYSTEM_NAME "IPluginManager"
45 #define SMINTERFACE_PLUGINSYSTEM_VERSION 5
46 
48 #define SM_CONTEXTVAR_USER 3
49 
50 namespace SourceMod
51 {
52  class IPlugin;
53 
57  typedef struct sm_plugininfo_s
58  {
59  const char *name;
60  const char *author;
61  const char *description;
62  const char *version;
63  const char *url;
65 
66 
70  enum PluginStatus
71  {
72  Plugin_Running=0,
73  /* All states below are unexecutable */
74  Plugin_Paused,
75  Plugin_Error,
76  /* All states below do not have all natives */
77  Plugin_Loaded,
78  Plugin_Failed,
79  Plugin_Created,
80  Plugin_Uncompiled,
81  Plugin_BadLoad,
82  };
83 
84 
88  enum PluginType
89  {
90  PluginType_Private,
91  PluginType_MapUpdated,
92  PluginType_MapOnly,
93  PluginType_Global,
94  };
95 
96  class IPhraseCollection;
97 
101  class IPlugin
102  {
103  public:
105  virtual ~IPlugin()
106  {
107  }
108 
112  virtual PluginType GetType() =0;
113 
119  virtual SourcePawn::IPluginContext *GetBaseContext() =0;
120 
126  virtual sp_context_t *GetContext() =0;
127 
133  virtual void *GetPluginStructure() =0;
134 
140  virtual const sm_plugininfo_t *GetPublicInfo() =0;
141 
145  virtual const char *GetFilename() =0;
146 
150  virtual bool IsDebugging() =0;
151 
155  virtual PluginStatus GetStatus() =0;
156 
162  virtual bool SetPauseState(bool paused) =0;
163 
167  virtual unsigned int GetSerial() =0;
168 
172  virtual IdentityToken_t *GetIdentity() =0;
173 
183  virtual bool SetProperty(const char *prop, void *ptr) =0;
184 
194  virtual bool GetProperty(const char *prop, void **ptr, bool remove=false) =0;
195 
201  virtual SourcePawn::IPluginRuntime *GetRuntime() =0;
202 
208  virtual IPhraseCollection *GetPhrases() =0;
209 
215  virtual Handle_t GetMyHandle() =0;
216  };
217 
218 
223  {
224  public:
227  {
228  };
229  public:
233  virtual bool MorePlugins() =0;
234 
238  virtual IPlugin *GetPlugin() =0;
239 
243  virtual void NextPlugin() =0;
244 
249  virtual void Release() =0;
250  };
251 
256  {
257  public:
261  virtual void OnPluginCreated(IPlugin *plugin)
262  {
263  }
264 
268  virtual void OnPluginLoaded(IPlugin *plugin)
269  {
270  }
271 
275  virtual void OnPluginPauseChange(IPlugin *plugin, bool paused)
276  {
277  }
278 
282  virtual void OnPluginUnloaded(IPlugin *plugin)
283  {
284  }
285 
290  virtual void OnPluginDestroyed(IPlugin *plugin)
291  {
292  }
293  };
294 
295 
300  {
301  public:
302  virtual const char *GetInterfaceName()
303  {
304  return SMINTERFACE_PLUGINSYSTEM_NAME;
305  }
306 
307  virtual unsigned int GetInterfaceVersion()
308  {
309  return SMINTERFACE_PLUGINSYSTEM_VERSION;
310  }
311  public:
323  virtual IPlugin *LoadPlugin(const char *path,
324  bool debug,
325  PluginType type,
326  char error[],
327  size_t maxlength,
328  bool *wasloaded) =0;
329 
336  virtual bool UnloadPlugin(IPlugin *plugin) =0;
337 
345  virtual IPlugin *FindPluginByContext(const sp_context_t *ctx) =0;
346 
352  virtual unsigned int GetPluginCount() =0;
353 
358  virtual IPluginIterator *GetPluginIterator() =0;
359 
365  virtual void AddPluginsListener(IPluginsListener *listener) =0;
366 
372  virtual void RemovePluginsListener(IPluginsListener *listener) =0;
373 
381  virtual IPlugin *PluginFromHandle(Handle_t handle, HandleError *err) =0;
382  };
383 }
384 
385 #endif //_INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
386 
virtual IPluginIterator * GetPluginIterator()=0
Returns a pointer that can be used to iterate through plugins. Note: This pointer must be freed using...
virtual IPlugin * GetPlugin()=0
Returns the plugin at the current iterator position.
virtual unsigned int GetSerial()=0
Returns the unique serial number of a plugin.
virtual unsigned int GetPluginCount()=0
Returns the number of plugins (both failed and loaded).
Defines the interface for creating, reading, and removing Handles.
virtual const char * GetFilename()=0
Returns the plugin filename (relative to plugins dir).
const char * name
Definition: IPluginSys.h:59
virtual IPhraseCollection * GetPhrases()=0
Returns the plugin's phrase collection.
virtual void OnPluginLoaded(IPlugin *plugin)
Called when a plugin is fully loaded successfully.
Definition: IPluginSys.h:268
virtual PluginStatus GetStatus()=0
Returns the plugin status.
Defines the Share System, responsible for shared resources and dependencies.
virtual unsigned int GetInterfaceVersion()
Must return an integer defining the interface's version.
Definition: IPluginSys.h:307
virtual SourcePawn::IPluginRuntime * GetRuntime()=0
Returns the runtime representing this plugin.
virtual ~IPlugin()
Definition: IPluginSys.h:105
virtual bool SetProperty(const char *prop, void *ptr)=0
Sets a property on this plugin. This is used for per-plugin data from extensions or other parts of co...
virtual void * GetPluginStructure()=0
Deprecated, returns NULL.
virtual IPlugin * FindPluginByContext(const sp_context_t *ctx)=0
Finds a plugin by its context. Note: This function should be considered O(1).
Defines the base functionality required by a shared interface.
Definition: IShareSys.h:92
virtual bool UnloadPlugin(IPlugin *plugin)=0
Attempts to unload a plugin.
virtual void OnPluginCreated(IPlugin *plugin)
Called when a plugin is created/mapped into memory.
Definition: IPluginSys.h:261
Iterates over a list of plugins.
Definition: IPluginSys.h:222
virtual void OnPluginPauseChange(IPlugin *plugin, bool paused)
Called when a plugin is paused or unpaused.
Definition: IPluginSys.h:275
const char * author
Definition: IPluginSys.h:60
virtual IdentityToken_t * GetIdentity()=0
Returns a plugin's identity token.
virtual IPlugin * PluginFromHandle(Handle_t handle, HandleError *err)=0
Converts a Handle to an IPlugin if possible.
virtual bool MorePlugins()=0
Returns true if there are more plugins in the iterator.
virtual void AddPluginsListener(IPluginsListener *listener)=0
Adds a plugin manager listener.
virtual const char * GetInterfaceName()
Must return a string defining the interface's unique name.
Definition: IPluginSys.h:302
Manages the runtime loading and unloading of plugins.
Definition: IPluginSys.h:299
virtual void OnPluginDestroyed(IPlugin *plugin)
Called when a plugin is destroyed. NOTE: Always called if Created, even if load failed.
Definition: IPluginSys.h:290
virtual const sm_plugininfo_t * GetPublicInfo()=0
Returns information about the plugin by reference.
Encapsulates a run-time plugin as maintained by SourceMod.
Definition: IPluginSys.h:101
Definition: ITranslator.h:121
virtual IPlugin * LoadPlugin(const char *path, bool debug, PluginType type, char error[], size_t maxlength, bool *wasloaded)=0
Attempts to load a plugin.
virtual sp_context_t * GetContext()=0
Deprecated, returns NULL.
virtual void Release()=0
Destroys the iterator object. Note: You may use 'delete' in lieu of this function.
const char * url
Definition: IPluginSys.h:63
virtual bool GetProperty(const char *prop, void **ptr, bool remove=false)=0
Gets a property from a plugin.
virtual SourcePawn::IPluginContext * GetBaseContext()=0
Returns the IPluginRuntime::GetDefaultContext() value.
virtual void RemovePluginsListener(IPluginsListener *listener)=0
Removes a plugin listener.
Listens for plugin-oriented events.
Definition: IPluginSys.h:255
Definition: IAdminSystem.h:63
const char * description
Definition: IPluginSys.h:61
Encapsulates plugin public information exposed through "myinfo.".
Definition: IPluginSys.h:57
const char * version
Definition: IPluginSys.h:62
virtual PluginType GetType()=0
Returns the lifetime of a plugin.
virtual void OnPluginUnloaded(IPlugin *plugin)
Called when a plugin is unloaded (only if fully loaded).
Definition: IPluginSys.h:282
virtual void NextPlugin()=0
Advances to the next plugin in the iterator.
virtual Handle_t GetMyHandle()=0
Returns a plugin's handle.
virtual bool IsDebugging()=0
Returns true if a plugin is in debug mode, false otherwise.
virtual bool SetPauseState(bool paused)=0
Sets whether the plugin is paused or not.
virtual ~IPluginIterator()
Definition: IPluginSys.h:226