Add posix DynLibImpl support.

Former-commit-id: c80dcc31c0935916082d5f19a7cf2dbe15da7b2f
This commit is contained in:
Alexandre Janniaux 2013-01-04 16:02:21 +01:00
parent ce6a63647f
commit 22d9e98422
4 changed files with 82 additions and 1 deletions

View File

@ -0,0 +1,45 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Win32/DynLibImpl.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/Debug.hpp>
NzDynLibImpl::NzDynLibImpl(NzDynLib* parent) :
m_parent(parent)
{
}
NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol) const
{
NzDynLibFunc sym = reinterpret_cast<NzDynLibFunc>(dlsym(m_handle, symbol.GetConstBuffer()));
if (!sym)
m_parent->SetLastError(NzGetLastSystemError()); // dlerror() ?
return sym;
}
bool NzDynLibImpl::Load(const NzString& libraryPath)
{
NzString path = libraryPath;
if (!path.EndsWith(".so"))
path += ".so";
m_handle = dlopen(path.GetConstBuffer(),);
if (m_handle)
return true;
else
{
m_parent->SetLastError(NzGetLastSystemError());
return false;
}
}
void NzDynLibImpl::Unload()
{
dlclose(m_handle);
}

View File

@ -0,0 +1,31 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DYNLIBIMPL_HPP
#define NAZARA_DYNLIBIMPL_HPP
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <dlfcn.h>
class NzString;
class NzDynLibImpl : NzNonCopyable
{
public:
NzDynLibImpl(NzDynLib* m_parent);
~NzDynLibImpl() = default;
NzDynLibFunc GetSymbol(const NzString& symbol) const;
bool Load(const NzString& libraryPath);
void Unload();
private:
void* m_handle;
NzDynLib* m_parent;
};
#endif // NAZARA_DYNLIBIMPL_HPP

View File

@ -18,6 +18,11 @@
#include <fcntl.h>
#include <unistd.h>
/*
04/01/2012 : alexandre.janniaux@gmail.com
Add posix file implementation.
*/
class NzFile;
class NzString;

View File

@ -4,7 +4,7 @@
/*
04/01/2012 : alexandre.janniaux@gmail.com
Add pthread mutex implementation
Add pthread mutex implementation.
*/
#pragma once