1 #ifndef _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
2 #define _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
8 #define SMINTERFACE_LIBRARYSYS_NAME "ILibrarySys"
9 #define SMINTERFACE_LIBRARYSYS_VERSION 1
16 /* Calling delete will call CloseLibrary! */
20 * @brief Closes dynamic library and invalidates pointer.
22 virtual void CloseLibrary() =0;
25 * @brief Retrieves a symbol pointer from the dynamic library.
27 * @param symname Symbol name.
28 * @return Symbol pointer, NULL if not found.
30 virtual void *GetSymbolAddress(const char *symname) =0;
34 * @brief Directory browsing abstraction.
44 * @brief Returns true if there are more files to read, false otherwise.
46 virtual bool MoreFiles() =0;
49 * @brief Advances to the next entry in the stream.
51 virtual void NextEntry() =0;
54 * @brief Returns the name of the current entry.
56 virtual const char *GetEntryName() =0;
59 * @brief Returns whether the current entry is a directory.
61 virtual bool IsEntryDirectory() =0;
64 * @brief Returns whether the current entry is a file.
66 virtual bool IsEntryFile() =0;
70 * @brief Contains various operating system specific code.
72 class ILibrarySys : public SMInterface
75 virtual const char *GetInterfaceName()
77 return SMINTERFACE_LIBRARYSYS_NAME;
79 virtual unsigned int GetInterfaceVersion()
81 return SMINTERFACE_LIBRARYSYS_VERSION;
85 * @brief Opens a dynamic library file.
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.
92 virtual ILibrary *OpenLibrary(const char *path, char *error, size_t err_max) =0;
95 * @brief Opens a directory for reading.
97 * @param path Path to directory.
98 * @return Pointer to an IDirectory, NULL if failed.
100 virtual IDirectory *OpenDirectory(const char *path) =0;
103 * @brief Closes a directory and frees its handle.
105 * @param dir Pointer to IDirectory.
107 virtual void CloseDirectory(IDirectory *dir) =0;
110 * @brief Returns true if a path exists.
112 virtual bool PathExists(const char *path) =0;
115 * @brief Returns true if the path is a normal file.
117 virtual bool IsPathFile(const char *path) =0;
120 * @brief Returns true if the path is a normal directory.
122 virtual bool IsPathDirectory(const char *path) =0;
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()
130 * @param error Error message buffer.
131 * @param err_max Maximum length of error buffer.
133 virtual void GetPlatformError(char *error, size_t err_max) =0;
137 #endif //_INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_