1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Added dynamic_library utility

This commit is contained in:
DHrpcs3 2016-05-08 10:38:40 +03:00
parent b52e885cde
commit 795170635f
5 changed files with 110 additions and 1 deletions

View File

@ -0,0 +1,60 @@
#include "stdafx.h"
#include "dynamic_library.h"
#ifdef _WIN32
#include <Windows.h>
#else
#include <dlfcn.h>
#endif
namespace utils
{
dynamic_library::dynamic_library(const std::string &path)
{
load(path);
}
dynamic_library::~dynamic_library()
{
close();
}
bool dynamic_library::load(const std::string &path)
{
#ifdef _WIN32
m_handle = LoadLibraryA(path.c_str());
#else
m_handle = dlopen(path.c_str(), RTLD_LAZY);
#endif
return loaded();
}
void dynamic_library::close()
{
#ifdef _WIN32
FreeLibrary((HMODULE)m_handle);
#else
dlclose(m_handle);
#endif
m_handle = nullptr;
}
void *dynamic_library::get_impl(const std::string &name) const
{
#ifdef _WIN32
return GetProcAddress((HMODULE)m_handle, name.c_str());
#else
return dlsym(m_handle, (char *)name.c_str());
#endif
}
bool dynamic_library::loaded() const
{
return !m_handle;
}
dynamic_library::operator bool() const
{
return loaded();
}
}

View File

@ -0,0 +1,41 @@
#include <string>
namespace utils
{
class dynamic_library
{
void *m_handle = nullptr;
public:
dynamic_library() = default;
dynamic_library(const std::string &path);
~dynamic_library();
bool load(const std::string &path);
void close();
private:
void *get_impl(const std::string &name) const;
public:
template<typename Type = void>
Type *get(const std::string &name) const
{
Type *result;
*(void **)(&result) = get_impl(name);
return result;
}
template<typename Type>
bool get(Type *&function, const std::string &name) const
{
*(void **)(&function) = get_impl(name);
return !!function;
}
bool loaded() const;
explicit operator bool() const;
};
}

View File

@ -198,7 +198,7 @@ if(WIN32)
target_link_libraries(rpcs3 avformat.lib avcodec.lib avutil.lib swresample.lib swscale.lib png16_static ${wxWidgets_LIBRARIES} ${OPENAL_LIBRARY} ${ADDITIONAL_LIBS})
else()
target_link_libraries(rpcs3 ${wxWidgets_LIBRARIES} ${OPENAL_LIBRARY} ${GLEW_LIBRARY} ${OPENGL_LIBRARIES})
target_link_libraries(rpcs3 libavformat.a libavcodec.a libavutil.a libswresample.a libswscale.a png16_static ${ZLIB_LIBRARIES} ${ADDITIONAL_LIBS})
target_link_libraries(rpcs3 libavformat.a libavcodec.a libavutil.a libswresample.a libswscale.a -ldl png16_static ${ZLIB_LIBRARIES} ${ADDITIONAL_LIBS})
if (NOT APPLE)
target_link_libraries(rpcs3 vulkan glslang OSDependent OGLCompiler SPIRV)
endif()

View File

@ -66,6 +66,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\Utilities\AutoPause.cpp" />
<ClCompile Include="..\Utilities\dynamic_library.cpp" />
<ClCompile Include="..\Utilities\Log.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
@ -363,6 +364,7 @@
<ClInclude Include="..\Utilities\BEType.h" />
<ClInclude Include="..\Utilities\BitField.h" />
<ClInclude Include="..\Utilities\BitSet.h" />
<ClInclude Include="..\Utilities\dynamic_library.h" />
<ClInclude Include="..\Utilities\event.h" />
<ClInclude Include="..\Utilities\geometry.h" />
<ClInclude Include="..\Utilities\GSL.h" />

View File

@ -854,6 +854,9 @@
<ClCompile Include="Emu\PSP2\Modules\sceVoiceQoS.cpp">
<Filter>Emu\PSP2\Modules</Filter>
</ClCompile>
<ClCompile Include="..\Utilities\dynamic_library.cpp">
<Filter>Utilities</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Crypto\aes.h">
@ -1624,5 +1627,8 @@
<ClInclude Include="..\Utilities\sync.h">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="..\Utilities\dynamic_library.h">
<Filter>Utilities</Filter>
</ClInclude>
</ItemGroup>
</Project>