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:
David Anderson 2006-11-05 00:29:44 +00:00
parent 936ed6ded5
commit c63d26e1c5
8 changed files with 436 additions and 18 deletions

View File

@ -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_

View File

@ -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_

View File

@ -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_

135
core/interfaces/IShareSys.h Normal file
View File

@ -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_

View File

@ -2,72 +2,72 @@
#include "mm_api.h"
#include "sm_version.h"
SourceMod g_SourceMod;
SourceMod_Core g_SourceMod;
PLUGIN_EXPOSE(SourceMod, g_SourceMod);
bool SourceMod::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
PLUGIN_SAVEVARS();
return true;
}
bool SourceMod::Unload(char *error, size_t maxlen)
bool SourceMod_Core::Unload(char *error, size_t maxlen)
{
return true;
}
bool SourceMod::Pause(char *error, size_t maxlen)
bool SourceMod_Core::Pause(char *error, size_t maxlen)
{
return true;
}
bool SourceMod::Unpause(char *error, size_t maxlen)
bool SourceMod_Core::Unpause(char *error, size_t maxlen)
{
return true;
}
void SourceMod::AllPluginsLoaded()
void SourceMod_Core::AllPluginsLoaded()
{
}
const char *SourceMod::GetAuthor()
const char *SourceMod_Core::GetAuthor()
{
return "AlliedModders, LLC";
}
const char *SourceMod::GetName()
const char *SourceMod_Core::GetName()
{
return "SourceMod";
}
const char *SourceMod::GetDescription()
const char *SourceMod_Core::GetDescription()
{
return "Extensible administration and scripting system";
}
const char *SourceMod::GetURL()
const char *SourceMod_Core::GetURL()
{
return "http://www.sourcemod.net/";
}
const char *SourceMod::GetLicense()
const char *SourceMod_Core::GetLicense()
{
return "See LICENSE.txt";
}
const char *SourceMod::GetVersion()
const char *SourceMod_Core::GetVersion()
{
return SOURCEMOD_VERSION;
}
const char *SourceMod::GetDate()
const char *SourceMod_Core::GetDate()
{
return __DATE__;
}
const char *SourceMod::GetLogTag()
const char *SourceMod_Core::GetLogTag()
{
return "SRCMOD";
}

View File

@ -3,7 +3,7 @@
#include <ISmmPlugin.h>
class SourceMod : public ISmmPlugin
class SourceMod_Core : public ISmmPlugin
{
public:
bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late);
@ -22,7 +22,7 @@ public:
const char *GetLogTag();
};
extern SourceMod g_SourceMod;
extern SourceMod_Core g_SourceMod;
PLUGIN_GLOBALVARS();

View File

@ -40,6 +40,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\interfaces"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -116,6 +117,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\interfaces"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
@ -204,6 +206,22 @@
<Filter
Name="Interfaces"
>
<File
RelativePath="..\interfaces\ILibrarySys.h"
>
</File>
<File
RelativePath="..\interfaces\IModuleSys.h"
>
</File>
<File
RelativePath="..\interfaces\IPluginMngr.h"
>
</File>
<File
RelativePath="..\interfaces\IShareSys.h"
>
</File>
</Filter>
</Files>
<Globals>

View File

@ -1,8 +1,8 @@
#ifndef _INCLUDE_SOURCEMOD_VERSION_H_
#define _INCLUDE_SOURCEMOD_VERSION_H_
#define SOURCEMOD_VERSION "1.0.0.0"
#define SOURCEMOD_V_MAJOR 1
#define SOURCEMOD_VERSION "0.0.0.0"
#define SOURCEMOD_V_MAJOR 0
#define SOURCEMOD_V_MINOR 0
#define SOURCEMOD_V_REV 0
#define SOURCEMOD_V_BUILD 0