First commit
This commit is contained in:
90
src/Nazara/Core/DynLib.cpp
Normal file
90
src/Nazara/Core/DynLib.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#define NAZARA_DYNLIB_CPP
|
||||
|
||||
#include <Nazara/Core/DynLib.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
#include <Nazara/Core/Win32/DynLibImpl.hpp>
|
||||
#elif defined(NAZARA_PLATFORM_POSIX)
|
||||
#include <Nazara/Core/Posix/DynLibImpl.hpp>
|
||||
#else
|
||||
#error No implementation for this platform
|
||||
#endif
|
||||
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzDynLib::NzDynLib(const NzString& libraryPath) :
|
||||
m_path(libraryPath),
|
||||
m_impl(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
NzDynLib::~NzDynLib()
|
||||
{
|
||||
Unload();
|
||||
}
|
||||
|
||||
NzString NzDynLib::GetLastError() const
|
||||
{
|
||||
NazaraLock(m_mutex)
|
||||
|
||||
return m_lastError;
|
||||
}
|
||||
|
||||
NzDynLibFunc NzDynLib::GetSymbol(const NzString& symbol) const
|
||||
{
|
||||
NazaraLock(m_mutex)
|
||||
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Library not opened");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->GetSymbol(symbol);
|
||||
}
|
||||
|
||||
bool NzDynLib::Load()
|
||||
{
|
||||
NazaraLock(m_mutex)
|
||||
|
||||
Unload();
|
||||
|
||||
m_impl = new NzDynLibImpl(this);
|
||||
if (!m_impl->Load(m_path))
|
||||
{
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzDynLib::Unload()
|
||||
{
|
||||
NazaraLock(m_mutex)
|
||||
|
||||
if (m_impl)
|
||||
{
|
||||
m_impl->Unload();
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void NzDynLib::SetLastError(const NzString& error)
|
||||
{
|
||||
NazaraLock(m_mutex)
|
||||
|
||||
m_lastError = error;
|
||||
}
|
||||
Reference in New Issue
Block a user