mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-21 18:22:33 +01:00
Added dynamic_library utility
This commit is contained in:
parent
b52e885cde
commit
795170635f
60
Utilities/dynamic_library.cpp
Normal file
60
Utilities/dynamic_library.cpp
Normal 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();
|
||||
}
|
||||
}
|
41
Utilities/dynamic_library.h
Normal file
41
Utilities/dynamic_library.h
Normal 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;
|
||||
};
|
||||
}
|
@ -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()
|
||||
|
@ -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" />
|
||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user