diff --git a/include/Nazara/Core/DynLib.hpp b/include/Nazara/Core/DynLib.hpp index 767165fe4..4f2759e22 100644 --- a/include/Nazara/Core/DynLib.hpp +++ b/include/Nazara/Core/DynLib.hpp @@ -28,7 +28,7 @@ namespace Nz { - using DynLibFunc = int (*)(); // Type "générique" de pointeur sur fonction + using DynLibFunc = int (*)(); // "Generic" type of poiter to function class DynLibImpl; @@ -56,7 +56,7 @@ namespace Nz mutable String m_lastError; DynLibImpl* m_impl; -}; + }; } #endif // NAZARA_DYNLIB_HPP diff --git a/include/Nazara/Core/PluginManager.hpp b/include/Nazara/Core/PluginManager.hpp index b2b20ffde..833f0c5d2 100644 --- a/include/Nazara/Core/PluginManager.hpp +++ b/include/Nazara/Core/PluginManager.hpp @@ -13,7 +13,7 @@ #include #include -///TODO: Révision +///TODO: Revision namespace Nz { class DynLib; diff --git a/src/Nazara/Core/DynLib.cpp b/src/Nazara/Core/DynLib.cpp index 39539e7ed..3261f0959 100644 --- a/src/Nazara/Core/DynLib.cpp +++ b/src/Nazara/Core/DynLib.cpp @@ -25,11 +25,26 @@ namespace Nz { + /*! + * \class Nz::DynLib + * \brief Core class that represents a dynamic library loader + */ + + /*! + * \brief Constructs a DynLib object by default + */ + DynLib::DynLib() : m_impl(nullptr) { } + /*! + * \brief Constructs a DynLib object by move semantic + * + * \param lib DynLib to move into this + */ + DynLib::DynLib(DynLib&& lib) : m_lastError(std::move(lib.m_lastError)), m_impl(lib.m_impl) @@ -37,11 +52,22 @@ namespace Nz lib.m_impl = nullptr; } + /*! + * \brief Destructs the object and calls Unload + * + * \see Unload + */ + DynLib::~DynLib() { Unload(); } + /*! + * \brief Gets the last error + * \return Last error + */ + String DynLib::GetLastError() const { NazaraLock(m_mutex) @@ -49,12 +75,19 @@ namespace Nz return m_lastError; } + /*! + * \brief Gets the symbol for the name + * \return Function which is the symbol of the function name + * + * \remark Produces a NazaraError if library is not loaded with NAZARA_CORE_SAFE defined + */ + DynLibFunc DynLib::GetSymbol(const String& symbol) const { NazaraLock(m_mutex) #if NAZARA_CORE_SAFE - if (!m_impl) + if (!IsLoaded()) { NazaraError("Library not opened"); return nullptr; @@ -64,11 +97,25 @@ namespace Nz return m_impl->GetSymbol(symbol, &m_lastError); } + /*! + * \brief Checks whether the library is loaded + * \return true if loaded + */ + bool DynLib::IsLoaded() const { return m_impl != nullptr; } + /*! + * \brief Loads the library with that path + * \return true if loading is successful + * + * \param libraryPath Path of the library + * + * \remark Produces a NazaraError if library is could not be loaded + */ + bool DynLib::Load(const String& libraryPath) { NazaraLock(m_mutex) @@ -87,11 +134,15 @@ namespace Nz return true; } + /*! + * \brief Unloads the library + */ + void DynLib::Unload() { NazaraLock(m_mutex) - if (m_impl) + if (IsLoaded()) { m_impl->Unload(); delete m_impl; @@ -99,6 +150,13 @@ namespace Nz } } + /*! + * \brief Moves the other lib into this + * \return A reference to this + * + * \param lib DynLib to move in this + */ + DynLib& DynLib::operator=(DynLib&& lib) { Unload(); diff --git a/src/Nazara/Core/PluginManager.cpp b/src/Nazara/Core/PluginManager.cpp index ddfede54c..04fcafac7 100644 --- a/src/Nazara/Core/PluginManager.cpp +++ b/src/Nazara/Core/PluginManager.cpp @@ -24,6 +24,19 @@ namespace Nz }; } + /*! + * \class Nz::PluginManager + * \brief Core class that represents a manager for plugin + */ + + /*! + * \brief Adds a directory + * + * \param directoryPath Path to the directory + * + * \remark Produces a NazaraError if not initialized + */ + void PluginManager::AddDirectory(const String& directoryPath) { if (!Initialize()) @@ -35,6 +48,11 @@ namespace Nz s_directories.insert(File::AbsolutePath(directoryPath)); } + /*! + * \brief Initializes the plugin manager + * \return true if everything is ok + */ + bool PluginManager::Initialize() { if (s_initialized) @@ -48,11 +66,36 @@ namespace Nz return true; } + /*! + * \brief Mounts the plugin + * \return true if mounting was a success + * + * \remark Produces a NazaraError if not initialized + * \remark Produces a NazaraError if plugin is not found + * \remark Produces a NazaraError if fail to load plugin + * \remark Produces a NazaraError if fail to get symbol PluginLoad + * \remark Produces a NazaraError if fail to initialize the plugin with PluginLoad + */ + bool PluginManager::Mount(Plugin plugin) { return Mount(s_pluginFiles[plugin]); } + /*! + * \brief Mounts the plugin with a path + * \return true if mounting was a success + * + * \param pluginPath Path to the plugin + * \param appendExtension Adds the extension to the path or not + * + * \remark Produces a NazaraError if not initialized + * \remark Produces a NazaraError if plugin is not found + * \remark Produces a NazaraError if fail to load plugin + * \remark Produces a NazaraError if fail to get symbol PluginLoad + * \remark Produces a NazaraError if fail to initialize the plugin with PluginLoad + */ + bool PluginManager::Mount(const String& pluginPath, bool appendExtension) { if (!Initialize()) @@ -119,6 +162,14 @@ namespace Nz return true; } + /*! + * \brief Removes a directory + * + * \param directoryPath Path to the directory + * + * \remark Produces a NazaraError if not initialized + */ + void PluginManager::RemoveDirectory(const String& directoryPath) { if (!Initialize()) @@ -130,11 +181,29 @@ namespace Nz s_directories.erase(File::AbsolutePath(directoryPath)); } + /*! + * \brief Unmounts the plugin with a path + * + * \param pluginPath Path to the plugin + * + * \remark Produces a NazaraError if not initialized + * \remark Produces a NazaraError if plugin is not loaded + */ + void PluginManager::Unmount(Plugin plugin) { Unmount(s_pluginFiles[plugin]); } + /*! + * \brief Unmounts the plugin with a path + * + * \param pluginPath Path to the plugin + * + * \remark Produces a NazaraError if not initialized + * \remark Produces a NazaraError if plugin is not loaded + */ + void PluginManager::Unmount(const String& pluginPath) { if (!Initialize()) @@ -160,6 +229,10 @@ namespace Nz s_plugins.erase(it); } + /*! + * \brief Uninitializes the plugin manager + */ + void PluginManager::Uninitialize() { if (!s_initialized)