From c63d26e1c52ab602bca80b8f5f7cf796e8dd86b3 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 5 Nov 2006 00:29:44 +0000 Subject: [PATCH] initial import of the first four core interfaces --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40145 --- core/interfaces/ILibrarySys.h | 114 ++++++++++++++++++++++++++++ core/interfaces/IModuleSys.h | 92 ++++++++++++++++++++++ core/interfaces/IPluginSys.h | 59 ++++++++++++++ core/interfaces/IShareSys.h | 135 +++++++++++++++++++++++++++++++++ core/mm_api.cpp | 28 +++---- core/mm_api.h | 4 +- core/msvc8/sourcemod_mm.vcproj | 18 +++++ core/sm_version.h | 4 +- 8 files changed, 436 insertions(+), 18 deletions(-) create mode 100644 core/interfaces/ILibrarySys.h create mode 100644 core/interfaces/IModuleSys.h create mode 100644 core/interfaces/IPluginSys.h create mode 100644 core/interfaces/IShareSys.h diff --git a/core/interfaces/ILibrarySys.h b/core/interfaces/ILibrarySys.h new file mode 100644 index 00000000..18a32d81 --- /dev/null +++ b/core/interfaces/ILibrarySys.h @@ -0,0 +1,114 @@ +#ifndef _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_ +#define _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_ + +#include + +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_ diff --git a/core/interfaces/IModuleSys.h b/core/interfaces/IModuleSys.h new file mode 100644 index 00000000..6b4eabe4 --- /dev/null +++ b/core/interfaces/IModuleSys.h @@ -0,0 +1,92 @@ +#ifndef _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_ +#define _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_ + +#include +#include + +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_ diff --git a/core/interfaces/IPluginSys.h b/core/interfaces/IPluginSys.h new file mode 100644 index 00000000..446a7975 --- /dev/null +++ b/core/interfaces/IPluginSys.h @@ -0,0 +1,59 @@ +#ifndef _INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_ +#define _INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_ + +#include + +#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_ diff --git a/core/interfaces/IShareSys.h b/core/interfaces/IShareSys.h new file mode 100644 index 00000000..7e08f72c --- /dev/null +++ b/core/interfaces/IShareSys.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_ diff --git a/core/mm_api.cpp b/core/mm_api.cpp index 296e5c41..82db205b 100644 --- a/core/mm_api.cpp +++ b/core/mm_api.cpp @@ -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"; } diff --git a/core/mm_api.h b/core/mm_api.h index af3a829c..5b230f39 100644 --- a/core/mm_api.h +++ b/core/mm_api.h @@ -3,7 +3,7 @@ #include -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(); diff --git a/core/msvc8/sourcemod_mm.vcproj b/core/msvc8/sourcemod_mm.vcproj index d55bb6c0..ace96064 100644 --- a/core/msvc8/sourcemod_mm.vcproj +++ b/core/msvc8/sourcemod_mm.vcproj @@ -40,6 +40,7 @@ + + + + + + + + diff --git a/core/sm_version.h b/core/sm_version.h index 6986a5bd..91b35912 100644 --- a/core/sm_version.h +++ b/core/sm_version.h @@ -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