core/interfaces/ILibrarySys.h
author David Anderson <dvander@alliedmods.net>
Sat Nov 11 11:10:24 2006 +0000 (2006-11-11)
changeset 177 d29ade52d953
parent 148 a0626ab9710b
child 210 de70433605a0
permissions -rw-r--r--
Fleshed out forward system and extensively documented its design considerations
Implemented and did basic tests on new IPluginFunction type
Split function types into a separate file
     1 #ifndef _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
     2 #define _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
     3 
     4 #include <IShareSys.h>
     5 
     6 namespace SourceMod
     7 {
     8 	#define SMINTERFACE_LIBRARYSYS_NAME		"ILibrarySys"
     9 	#define SMINTERFACE_LIBRARYSYS_VERSION	1
    10 
    11 	class ILibrary
    12 	{
    13 	public:
    14 		virtual ~ILibrary()
    15 		{
    16 			/* Calling delete will call CloseLibrary! */
    17 		};
    18 	public:
    19 		/**
    20 		 * @brief Closes dynamic library and invalidates pointer.
    21 		 */
    22 		virtual void CloseLibrary() =0;
    23 
    24 		/**
    25 		 * @brief Retrieves a symbol pointer from the dynamic library.
    26 		 *
    27 		 * @param symname	Symbol name.
    28 		 * @return			Symbol pointer, NULL if not found.
    29 		 */
    30 		virtual void *GetSymbolAddress(const char *symname) =0;
    31 	};
    32 
    33 	/**
    34 	 * @brief Directory browsing abstraction.
    35 	 */
    36 	class IDirectory
    37 	{
    38 	public:
    39 		virtual ~IDirectory()
    40 		{
    41 		}
    42 	public:
    43 		/**
    44 		 * @brief Returns true if there are more files to read, false otherwise.
    45 		 */
    46 		virtual bool MoreFiles() =0;
    47 
    48 		/**
    49 		 * @brief Advances to the next entry in the stream.
    50 		 */
    51 		virtual void NextEntry() =0;
    52 
    53 		/**
    54 		 * @brief Returns the name of the current entry.
    55 		 */
    56 		virtual const char *GetEntryName() =0;
    57 
    58 		/**
    59 		 * @brief Returns whether the current entry is a directory.
    60 		 */
    61 		virtual bool IsEntryDirectory() =0;
    62 
    63 		/**
    64 		 * @brief Returns whether the current entry is a file.
    65 		 */
    66 		virtual bool IsEntryFile() =0;
    67 	};
    68 
    69 	/**
    70 	 * @brief Contains various operating system specific code.
    71 	 */
    72 	class ILibrarySys : public SMInterface
    73 	{
    74 	public:
    75 		virtual const char *GetInterfaceName()
    76 		{
    77 			return SMINTERFACE_LIBRARYSYS_NAME;
    78 		}
    79 		virtual unsigned int GetInterfaceVersion()
    80 		{
    81 			return SMINTERFACE_LIBRARYSYS_VERSION;
    82 		}
    83 	public:
    84 		/**
    85 		 * @brief Opens a dynamic library file.
    86 		 * 
    87 		 * @param path		Path to library file (.dll/.so).
    88 		 * @param error		Buffer for any error message (may be NULL).
    89 		 * @param err_max	Maximum length of error buffer.
    90 		 * @return			Pointer to an ILibrary, NULL if failed.
    91 		 */
    92 		virtual ILibrary *OpenLibrary(const char *path, char *error, size_t err_max) =0;
    93 
    94 		/**
    95 		 * @brief Opens a directory for reading.
    96 		 *
    97 		 * @param path		Path to directory.
    98 		 * @return			Pointer to an IDirectory, NULL if failed.
    99 		 */
   100 		virtual IDirectory *OpenDirectory(const char *path) =0;
   101 
   102 		/**
   103 		 * @brief Closes a directory and frees its handle.
   104 		 * 
   105 		 * @param dir		Pointer to IDirectory.
   106 		 */
   107 		virtual void CloseDirectory(IDirectory *dir) =0;
   108 
   109 		/**
   110 		 * @brief Returns true if a path exists.
   111 		 */
   112 		virtual bool PathExists(const char *path) =0;
   113 
   114 		/**
   115 		 * @brief Returns true if the path is a normal file.
   116 		 */
   117 		virtual bool IsPathFile(const char *path) =0;
   118 
   119 		/**
   120 		 * @brief Returns true if the path is a normal directory.
   121 		 */
   122 		virtual bool IsPathDirectory(const char *path) =0;
   123 
   124 		/**
   125 		 * @brief Gets a platform-specific error message.
   126 		 * This should only be called when an ILibrary function fails.
   127 		 * Win32 equivalent: GetLastError() + FormatMessage()
   128 		 * POSIX equivalent: errno + strerror()
   129 		 *
   130 		 * @param error		Error message buffer.
   131 		 * @param err_max	Maximum length of error buffer.
   132 		 */
   133 		virtual void GetPlatformError(char *error, size_t err_max) =0;
   134 	};
   135 };
   136 
   137 #endif //_INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_