initial import of the first four core interfaces
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40145
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
|
||||
#define _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
|
||||
|
||||
#include <IShareSys.h>
|
||||
|
||||
namespace SourceMod
|
||||
{
|
||||
#define SMINTERFACE_LIBRARYSYS_NAME "ILibrarySys"
|
||||
#define SMINTERFACE_LIBRARYSYS_VERSION 1
|
||||
|
||||
class ILibrary
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Closes dynamic library and invalidates pointer.
|
||||
*/
|
||||
virtual void CloseLibrary() =0;
|
||||
|
||||
/**
|
||||
* @brief Retrieves a symbol pointer from the dynamic library.
|
||||
*
|
||||
* @param symname Symbol name.
|
||||
* @return Symbol pointer, NULL if not found.
|
||||
*/
|
||||
virtual void *GetSymbolAddress(const char *symname) =0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Directory browsing abstraction.
|
||||
*/
|
||||
class IDirectory
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Returns true if there are more files to read, false otherwise.
|
||||
*/
|
||||
virtual bool MoreFiles() =0;
|
||||
|
||||
/**
|
||||
* @brief Advances to the next entry in the stream.
|
||||
*/
|
||||
virtual void NextEntry() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the name of the current entry.
|
||||
*/
|
||||
virtual const char *GetEntryName() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns whether the current entry is a directory.
|
||||
*/
|
||||
virtual bool IsEntryDirectory() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns whether the current entry is a file.
|
||||
*/
|
||||
virtual bool IsEntryFile() =0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Contains various operating system specific code.
|
||||
*/
|
||||
class ILibrarySys : public SMInterface
|
||||
{
|
||||
public:
|
||||
virtual const char *GetInterfaceName()
|
||||
{
|
||||
return SMINTERFACE_LIBRARYSYS_NAME;
|
||||
}
|
||||
virtual unsigned int GetInterfaceVersion()
|
||||
{
|
||||
return SMINTERFACE_LIBRARYSYS_VERSION;
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief Opens a dynamic library file.
|
||||
*
|
||||
* @param path Path to library file (.dll/.so).
|
||||
* @param error Buffer for any error message (may be NULL).
|
||||
* @param err_max Maximum length of error buffer.
|
||||
* @return Pointer to an ILibrary, NULL if failed.
|
||||
*/
|
||||
virtual ILibrary *OpenLibrary(const char *path, char *error, size_t err_max) =0;
|
||||
|
||||
/**
|
||||
* @brief Opens a directory for reading.
|
||||
*
|
||||
* @param path Path to directory.
|
||||
* @param error Buffer for any error message (may be NULL).
|
||||
* @param err_max Maximum length of error buffer.
|
||||
* @return Pointer to an IDirectory, NULL if failed.
|
||||
*/
|
||||
virtual IDirectory *OpenDirectory(const char *path, char *error, size_t err_max) =0;
|
||||
|
||||
/**
|
||||
* @brief Closes a directory and frees its handle.
|
||||
*
|
||||
* @param dir Pointer to IDirectory.
|
||||
*/
|
||||
virtual void CloseDirectory(IDirectory *dir) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the path is a normal file.
|
||||
*/
|
||||
virtual bool IsPathFile(const char *path) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the path is a normal directory.
|
||||
*/
|
||||
virtual bool IsPathDirectory(const char *path) =0;
|
||||
};
|
||||
};
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
|
||||
@@ -0,0 +1,92 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
|
||||
#define _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
|
||||
|
||||
#include <IShareSys.h>
|
||||
#include <ILibrarySys.h>
|
||||
|
||||
namespace SourceMod
|
||||
{
|
||||
class IModuleInterface;
|
||||
|
||||
class IModule : public IUnloadableParent
|
||||
{
|
||||
public:
|
||||
virtual UnloadableParentType GetParentType()
|
||||
{
|
||||
return ParentType_Module;
|
||||
}
|
||||
public:
|
||||
virtual IModuleInterface *GetModuleInfo() =0;
|
||||
virtual const char *GetFilename() =0;
|
||||
};
|
||||
|
||||
class IModuleInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Called when the module is loaded.
|
||||
*
|
||||
* @param me Pointer back to module.
|
||||
* @param sys Pointer to interface sharing system of SourceMod.
|
||||
* @param error Error buffer to print back to, if any.
|
||||
* @param err_max Maximum size of error buffer.
|
||||
* @param late If this module was loaded "late" (i.e. manually).
|
||||
* @return True if load should continue, false otherwise.
|
||||
*/
|
||||
virtual bool OnModuleLoad(IModule *me, IShareSys *sys, char *error, size_t err_max, bool late) =0;
|
||||
|
||||
/**
|
||||
* @brief Called when the module is unloaded.
|
||||
*
|
||||
* @param force True if this unload will be forced.
|
||||
* @param error Error message buffer.
|
||||
* @param err_max Maximum siez of error buffer.
|
||||
* @return True on success, false to request no unload.
|
||||
*/
|
||||
virtual bool OnModuleUnload(bool force, char *error, size_t err_max) =0;
|
||||
|
||||
/**
|
||||
* @brief Called when your pause state is about to change.
|
||||
*
|
||||
* @param pause True if pausing, false if unpausing.
|
||||
*/
|
||||
virtual void OnPauseChange(bool pause) =0;
|
||||
|
||||
public:
|
||||
virtual const char *GetModuleName() =0;
|
||||
virtual const char *GetModuleVersion() =0;
|
||||
virtual const char *GetModuleURL() =0;
|
||||
virtual const char *GetModuleTags() =0;
|
||||
virtual const char *GetModuleAuthor() =0;
|
||||
};
|
||||
|
||||
#define SMINTERFACE_MODULEMANAGER_NAME "IModuleManager"
|
||||
#define SMINTERFACE_MODULEMANAGER_VERSION 1
|
||||
|
||||
enum ModuleLifetime
|
||||
{
|
||||
ModuleLifetime_Forever, //Module will never be unloaded automatically
|
||||
ModuleLifetime_Map, //Module will be unloaded at the end of the map
|
||||
ModuleLifetime_Dependent, //Module will be unloaded once its dependencies are gone
|
||||
};
|
||||
|
||||
class IModuleManager : public SMInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Loads a module into the module system.
|
||||
*
|
||||
* @param path Path to module file, relative to the modules folder.
|
||||
* @param lifetime Lifetime of the module.
|
||||
* @param error Error buffer.
|
||||
* @param err_max Maximum error buffer length.
|
||||
* @return New IModule on success, NULL on failure.
|
||||
*/
|
||||
virtual IModule *LoadModule(const char *path,
|
||||
ModuleLifetime lifetime,
|
||||
char *error,
|
||||
size_t err_max);
|
||||
};
|
||||
};
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
|
||||
@@ -0,0 +1,59 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
|
||||
#define _INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
|
||||
|
||||
#include <IShareSys.h>
|
||||
|
||||
#define SMINTERFACE_PLUGINMANAGER_NAME "IPluginManager"
|
||||
#define SMINTERFACE_PLUGINMANAGER_VERSION 1
|
||||
|
||||
namespace SourceMod
|
||||
{
|
||||
class IPlugin : public IUnloadableParent
|
||||
{
|
||||
public:
|
||||
UnloadableParentType GetParentType()
|
||||
{
|
||||
return ParentType_Module;
|
||||
}
|
||||
};
|
||||
|
||||
enum PluginLifetime
|
||||
{
|
||||
PluginLifetime_Forever,
|
||||
PluginLifetime_Map
|
||||
};
|
||||
|
||||
class IPluginManager : public SMInterface
|
||||
{
|
||||
public:
|
||||
virtual const char *GetInterfaceName()
|
||||
{
|
||||
return SMINTERFACE_PLUGINMANAGER_NAME;
|
||||
}
|
||||
|
||||
virtual unsigned int GetInterfaceVersion()
|
||||
{
|
||||
return SMINTERFACE_PLUGINMANAGER_VERSION;
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief Attempts to load a plugin.
|
||||
*
|
||||
* @param path Path and filename of plugin, relative to plugins folder.
|
||||
* @param extended Whether or not the plugin is a static plugin or optional plugin.
|
||||
* @param debug Whether or not to default the plugin into debug mode.
|
||||
* @param lifetime Lifetime of the plugin.
|
||||
* @param error Buffer to hold any error message.
|
||||
* @param err_max Maximum length of error message buffer.
|
||||
* @return A new plugin pointer on success, false otherwise.
|
||||
*/
|
||||
virtual IPlugin *LoadPlugin(const char *path,
|
||||
bool extended,
|
||||
bool debug,
|
||||
PluginLifetime lifetime,
|
||||
char error[],
|
||||
size_t err_max) =0;
|
||||
};
|
||||
};
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
|
||||
@@ -0,0 +1,135 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
|
||||
#define _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
|
||||
|
||||
namespace SourceMod
|
||||
{
|
||||
/**
|
||||
* @brief Defines the base functionality required by a shared interface.
|
||||
*/
|
||||
class SMInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Must return an integer defining the interface's version.
|
||||
*/
|
||||
virtual unsigned int GetInterfaceVersion() =0;
|
||||
|
||||
/**
|
||||
* @brief Must return a string defining the interface's unique name.
|
||||
*/
|
||||
virtual const char *GetInterfaceName() =0;
|
||||
|
||||
/**
|
||||
* @brief Must return whether the requested version number is backwards comaptible.
|
||||
* Note: This can be overridden for breaking changes or custom versioning.
|
||||
*
|
||||
* @param version Version number to compare against.
|
||||
* @return True if compatible, false otherwise.
|
||||
*/
|
||||
virtual bool IsVersionCompatible(unsigned int version)
|
||||
{
|
||||
if (version > GetInterfaceVersion())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
enum UnloadableParentType
|
||||
{
|
||||
ParentType_Module,
|
||||
ParentType_Plugin
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Denotes a top-level unloadable object.
|
||||
*/
|
||||
class IUnloadableParent
|
||||
{
|
||||
public:
|
||||
virtual UnloadableParentType GetParentType() =0;
|
||||
|
||||
virtual void *GetParentToken() =0;
|
||||
|
||||
/**
|
||||
* @brief Called when an interface this object has requested is removed.
|
||||
*
|
||||
* @param pIface Interface being removed.
|
||||
*/
|
||||
virtual void OnInterfaceUnlink(SMInterface *pIface) =0;
|
||||
protected:
|
||||
void *m_parent_token;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Listens for unlinked objects.
|
||||
*/
|
||||
class IUnlinkListener
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Called when a parent object is unloaded.
|
||||
*
|
||||
* @param parent The parent object which is dying.
|
||||
*/
|
||||
virtual void OnParentUnlink(IUnloadableParent *parent)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Tracks dependencies and fires dependency listeners.
|
||||
*/
|
||||
class IShareSys
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Adds an interface to the global interface system
|
||||
*
|
||||
* @param iface Interface pointer (must be unique).
|
||||
* @param parent Parent unloadable token given to the module/interface.
|
||||
*/
|
||||
virtual bool AddInterface(SMInterface *iface, IUnloadableParent *parent) =0;
|
||||
|
||||
/**
|
||||
* @brief Requests an interface from the global interface system.
|
||||
* If found, the interface's internal reference count will be increased.
|
||||
*
|
||||
* @param iface_name Interface name.
|
||||
* @param iface_vers Interface version to attempt to match.
|
||||
* @param me Object requesting this interface, in order to track dependencies.
|
||||
* @param pIface Pointer to store the return value in.
|
||||
*/
|
||||
virtual bool RequestInterface(const char *iface_name,
|
||||
unsigned int iface_vers,
|
||||
IUnloadableParent *me,
|
||||
void **pIface) =0;
|
||||
|
||||
/**
|
||||
* @brief Unloads an interface.
|
||||
*
|
||||
* @param iface Interface pointer.
|
||||
* @param parent Security token, trivial measure to prevent accidental unloads.
|
||||
* This token must match the one used with AddInterface().
|
||||
*/
|
||||
virtual void RemoveInterface(SMInterface *iface, IUnloadableParent *parent) =0;
|
||||
|
||||
/**
|
||||
* @brief Adds an unlink listener.
|
||||
*
|
||||
* @param pListener Listener pointer.
|
||||
*/
|
||||
virtual void AddUnlinkListener(IUnlinkListener *pListener) =0;
|
||||
|
||||
/**
|
||||
* @brief Removes an unlink listener.
|
||||
*
|
||||
* @param pListener Listener pointer.
|
||||
*/
|
||||
virtual void RemoveUnlinkListener(IUnlinkListener *pListener) =0;
|
||||
};
|
||||
};
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
|
||||
Reference in New Issue
Block a user