SourceMod SDK  1.7
IExtensionSys.h
Go to the documentation of this file.
1 
32 #ifndef _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
33 #define _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
34 
35 #include <IShareSys.h>
36 #include <ILibrarySys.h>
37 
43 struct edict_t;
44 
45 namespace SourceMod
46 {
47  class IExtensionInterface;
48  typedef void * ITERATOR;
53  class IExtension
54  {
55  public:
59  virtual bool IsLoaded() =0;
60 
66  virtual IExtensionInterface *GetAPI() =0;
67 
76  virtual const char *GetFilename() =0;
77 
83  virtual IdentityToken_t *GetIdentity() =0;
84 
92  virtual ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface) =0;
93 
102  virtual bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface) =0;
103 
109  virtual void FreeDependencyIterator(ITERATOR *iter) =0;
110 
118  virtual bool IsRunning(char *error, size_t maxlength) =0;
119 
127  virtual bool IsExternal() =0;
128  };
129 
140  #define SMINTERFACE_EXTENSIONAPI_VERSION 8
141 
146  {
147  public:
149  virtual unsigned int GetExtensionVersion()
150  {
152  }
153  public:
164  virtual bool OnExtensionLoad(IExtension *me,
165  IShareSys *sys,
166  char *error,
167  size_t maxlength,
168  bool late) =0;
169 
173  virtual void OnExtensionUnload() =0;
174 
179  virtual void OnExtensionsAllLoaded() =0;
180 
186  virtual void OnExtensionPauseChange(bool pause) =0;
187 
204  virtual bool QueryInterfaceDrop(SMInterface *pInterface)
205  {
206  return false;
207  }
208 
217  virtual void NotifyInterfaceDrop(SMInterface *pInterface)
218  {
219  }
220 
228  virtual bool QueryRunning(char *error, size_t maxlength)
229  {
230  return true;
231  }
232  public:
241  virtual bool IsMetamodExtension() =0;
242 
248  virtual const char *GetExtensionName() =0;
249 
255  virtual const char *GetExtensionURL() =0;
256 
262  virtual const char *GetExtensionTag() =0;
263 
269  virtual const char *GetExtensionAuthor() =0;
270 
287  virtual const char *GetExtensionVerString() =0;
288 
299  virtual const char *GetExtensionDescription() =0;
300 
306  virtual const char *GetExtensionDateString() =0;
307 
315  virtual void OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
316  {
317  }
318 
326  virtual void OnDependenciesDropped()
327  {
328  }
329 
335  virtual void OnCoreMapEnd()
336  {
337  }
338  };
339 
343  #define SOURCEMOD_INTERFACE_EXTENSIONS "SM_ExtensionManager"
344 
356  #define SOURCEMOD_NOTICE_EXTENSIONS "SM_ExtensionsAttachable"
357 
358  #define SMINTERFACE_EXTENSIONMANAGER_NAME "IExtensionManager"
359  #define SMINTERFACE_EXTENSIONMANAGER_VERSION 2
360 
365  {
366  public:
367  virtual const char *GetInterfaceName()
368  {
369  return SMINTERFACE_EXTENSIONMANAGER_NAME;
370  }
371  virtual unsigned int GetInterfaceVersion()
372  {
373  return SMINTERFACE_EXTENSIONMANAGER_VERSION;
374  }
375  virtual bool IsVersionCompatible(unsigned int version)
376  {
377  if (version < 2)
378  {
379  return false;
380  }
381  return SMInterface::IsVersionCompatible(version);
382  }
383  public:
395  virtual IExtension *LoadExtension(const char *path,
396  char *error,
397  size_t maxlength) =0;
398 
423  virtual IExtension *LoadExternal(IExtensionInterface *pInterface,
424  const char *filepath,
425  const char *filename,
426  char *error,
427  size_t maxlength) =0;
428 
436  virtual bool UnloadExtension(IExtension *pExt) =0;
437  };
438 
439  #define SM_IFACEPAIR(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
440 
441  #define SM_FIND_IFACE_OR_FAIL(prefix, variable, errbuf, errsize) \
442  if (!sharesys->RequestInterface(SM_IFACEPAIR(prefix), myself, (SMInterface **)&variable)) \
443  { \
444  if (errbuf) \
445  { \
446  size_t len = snprintf(errbuf, \
447  errsize, \
448  "Could not find interface: %s (version: %d)", \
449  SM_IFACEPAIR(prefix)); \
450  if (len >= errsize) \
451  { \
452  errbuf[errsize - 1] = '\0'; \
453  } \
454  } \
455  return false; \
456  }
457 
458  #define SM_FIND_IFACE(prefix, variable) \
459  sharesys->RequestInterface(SM_IFACEPAIR(prefix), myself, (SMInterface **)&variable);
460 }
461 
462 #endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
463 
virtual void OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
Called on server activation before plugins receive the OnServerLoad forward.
Definition: IExtensionSys.h:315
virtual const char * GetExtensionName()=0
Must return a string containing the extension's short name.
The interface an extension must expose.
Definition: IExtensionSys.h:145
virtual bool IsVersionCompatible(unsigned int version)
Must return whether the requested version number is backwards compatible. Note: This can be overridde...
Definition: IExtensionSys.h:375
virtual void OnExtensionsAllLoaded()=0
Called when all extensions are loaded (loading cycle is done). If loaded late, this will be called ri...
virtual const char * GetExtensionURL()=0
Must return a string containing the extension's URL.
virtual const char * GetInterfaceName()
Must return a string defining the interface's unique name.
Definition: IExtensionSys.h:367
virtual void OnExtensionUnload()=0
Called when the extension is about to be unloaded.
virtual bool UnloadExtension(IExtension *pExt)=0
Attempts to unload an extension. External extensions must call this before unloading.
virtual const char * GetFilename()=0
Returns the filename of the extension, relative to the extension folder. If the extension is an "exte...
virtual const char * GetExtensionVerString()=0
Must return a string containing version information.
virtual unsigned int GetInterfaceVersion()
Must return an integer defining the interface's version.
Definition: IExtensionSys.h:371
virtual bool QueryInterfaceDrop(SMInterface *pInterface)
Asks the extension whether it's safe to remove an external interface it's using. If it's not safe...
Definition: IExtensionSys.h:204
virtual const char * GetExtensionDescription()=0
Must return a string containing description text.
Tracks dependencies and fires dependency listeners.
Definition: IShareSys.h:126
virtual unsigned int GetExtensionVersion()
Definition: IExtensionSys.h:149
Defines the Share System, responsible for shared resources and dependencies.
virtual bool IsLoaded()=0
Returns whether or not the extension is properly loaded.
virtual bool IsExternal()=0
Returns whether the extension is local (from the extensions folder), or is from an external source (s...
virtual void NotifyInterfaceDrop(SMInterface *pInterface)
Notifies the extension that an external interface it uses is being removed.
Definition: IExtensionSys.h:217
Defines the base functionality required by a shared interface.
Definition: IShareSys.h:92
virtual bool IsRunning(char *error, size_t maxlength)=0
Queries the extension to see its run state.
virtual const char * GetExtensionTag()=0
Must return a string containing a short identifier tag.
virtual void FreeDependencyIterator(ITERATOR *iter)=0
Frees an ITERATOR handle from FindFirstDependency.
virtual bool QueryRunning(char *error, size_t maxlength)
Return false to tell Core that your extension should be considered unusable.
Definition: IExtensionSys.h:228
virtual const char * GetExtensionAuthor()=0
Must return a string containing a short author identifier.
virtual IExtension * LoadExternal(IExtensionInterface *pInterface, const char *filepath, const char *filename, char *error, size_t maxlength)=0
Loads an extension into the extension system, directly, as an external extension. ...
virtual IExtension * LoadExtension(const char *path, char *error, size_t maxlength)=0
Loads a extension into the extension system.
virtual IExtensionInterface * GetAPI()=0
Returns the extension's API interface.
virtual void OnCoreMapEnd()
Called on level shutdown.
Definition: IExtensionSys.h:335
Manages the loading/unloading of extensions.
Definition: IExtensionSys.h:364
virtual const char * GetExtensionDateString()=0
Must return a string containing the compilation date.
virtual bool IsVersionCompatible(unsigned int version)
Must return whether the requested version number is backwards compatible. Note: This can be overridde...
Definition: IShareSys.h:112
Definition: IAdminSystem.h:63
virtual bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface)=0
Finds the next dependency in the dependency list.
virtual void OnExtensionPauseChange(bool pause)=0
Called when your pause state is about to change.
virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late)=0
Called when the extension is loaded.
Encapsulates an IExtensionInterface and its dependencies.
Definition: IExtensionSys.h:53
virtual ITERATOR * FindFirstDependency(IExtension **pOwner, SMInterface **pInterface)=0
Retrieves the extension dependency list for this extension.
virtual IdentityToken_t * GetIdentity()=0
Returns the extension's identity token.
#define SMINTERFACE_EXTENSIONAPI_VERSION
Version code of the IExtensionInterface API itself.
Definition: IExtensionSys.h:140
Defines platform-dependent operations, such as opening libraries and files.
virtual bool IsMetamodExtension()=0
For extensions loaded through SourceMod, this should return true if the extension needs to attach to ...
virtual void OnDependenciesDropped()
Called once all dependencies have been unloaded. This is called AFTER OnExtensionUnload(), but before the extension library has been unloaded. It can be used as an alternate unload hook for cases where having no dependent plugins would make shutdown much simplier.
Definition: IExtensionSys.h:326