Update to LibConf system, added loading of dynamic libraries (only Linux for now) and some more fixes.
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
|
||||
#include "os.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include "../detect.hpp"
|
||||
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||
// TODO
|
||||
#endif
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
|
||||
@@ -36,7 +40,24 @@ namespace mijin
|
||||
// public functions
|
||||
//
|
||||
|
||||
void setCurrentThreadName(const char* threadName)
|
||||
LibraryHandle openSharedLibrary(std::string_view libraryFile) noexcept
|
||||
{
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||
const fs::path libraryPath = fs::absolute(libraryFile);
|
||||
return {.data = dlopen(libraryPath.c_str(), RTLD_NOW)};
|
||||
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||
#endif
|
||||
}
|
||||
|
||||
void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) noexcept
|
||||
{
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||
return dlsym(library.data, symbolName);
|
||||
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||
#endif
|
||||
}
|
||||
|
||||
void setCurrentThreadName(const char* threadName) noexcept
|
||||
{
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||
pthread_setname_np(pthread_self(), threadName);
|
||||
@@ -44,4 +65,15 @@ void setCurrentThreadName(const char* threadName)
|
||||
#endif
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) noexcept
|
||||
{
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||
return "lib" + std::string(libraryName) + ".so";
|
||||
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||
return std::string(libraryName) + ".dll";
|
||||
#else
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace mijin
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#if !defined(MIJIN_UTIL_OS_HPP_INCLUDED)
|
||||
#define MIJIN_UTIL_OS_HPP_INCLUDED 1
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
|
||||
@@ -19,11 +22,23 @@ namespace mijin
|
||||
// public types
|
||||
//
|
||||
|
||||
struct LibraryHandle
|
||||
{
|
||||
void* data = nullptr;
|
||||
|
||||
constexpr operator bool() const noexcept { return data != nullptr; }
|
||||
constexpr bool operator!() const noexcept { return data == nullptr; }
|
||||
};
|
||||
|
||||
//
|
||||
// public functions
|
||||
//
|
||||
|
||||
void setCurrentThreadName(const char* threadName);
|
||||
[[nodiscard]] LibraryHandle openSharedLibrary(std::string_view libraryFile) noexcept;
|
||||
[[nodiscard]] void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) noexcept;
|
||||
void setCurrentThreadName(const char* threadName) noexcept;
|
||||
|
||||
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) noexcept;
|
||||
|
||||
} // namespace mijin
|
||||
|
||||
|
||||
Reference in New Issue
Block a user