Add posix DynLibImpl support.
Former-commit-id: c80dcc31c0935916082d5f19a7cf2dbe15da7b2f
This commit is contained in:
parent
ce6a63647f
commit
22d9e98422
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
/*
|
||||
04/01/2012 : alexandre.janniaux@gmail.com
|
||||
Add pthread mutex implementation
|
||||
Add pthread mutex implementation.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
|
|
|||
Loading…
Reference in New Issue