49 std::string m_libraryPath;
54 std::string m_nativeLibraryPath;
57 const std::string&
libraryPath,
const std::string& symbolName) {
62 if(
nullptr != nlp ) {
63 return std::string(nlp);
79 return m_dynLink.lookupSymbol(m_libraryHandle, funcName);
83 return m_dynLink.lookupSymbolGlobal(funcName);
93 bool isValid() const noexcept {
return m_nativeLibraryPath.size() > 0; }
96 bool isOpen() const noexcept {
return nullptr != m_libraryHandle; }
102 const std::string&
libraryPath() const noexcept {
return m_libraryPath; }
115 if (
nullptr != m_libraryHandle ) {
117 m_libraryHandle =
nullptr;
118 m_dynLink.closeLibrary(handle);
125 return "NativeLibrary[path[given '" + m_libraryPath +
"', native '"+m_nativeLibraryPath+
"'], 0x" +
126 jau::to_hexstring(m_libraryHandle) +
", global " + std::to_string(m_global) +
"]";
128 return "NativeLibrary[invalid, path[given '" + m_libraryPath +
"'], 0x" +
129 jau::to_hexstring(m_libraryHandle) +
", global " + std::to_string(m_global) +
"]";
150 static NativeLibrary
open(
const std::string& libName,
151 const bool searchSystemPath,
152 const bool searchSystemPathFirst,
153 const bool global)
noexcept {
154 return open(libName, searchSystemPath, searchSystemPathFirst, global,
"");
178 static NativeLibrary
open(
const std::string& libName,
179 const bool searchSystemPath,
180 const bool searchSystemPathFirst,
181 const bool global,
const std::string& symbolName)
noexcept {
187 for (
const std::string& path : paths ) {
188 DBG_PRINT(
"NativeLibrary.open(global %d): Trying to load %s", global, path.c_str());
191 res = m_dynLink.openLibraryGlobal(path);
193 res = m_dynLink.openLibraryLocal(path);
195 if (
nullptr != res ) {
196 NativeLibrary nl(m_dynLink, res, path, global, symbolName);
200 DBG_PRINT(
"NativeLibrary.open: Failed to open '%s', last error %s",
201 path.c_str(), m_dynLink.getLastError().c_str());
204 DBG_PRINT(
"NativeLibrary.open(global %d): Did not succeed in loading: '%s' within '%s'",
206 return NativeLibrary(m_dynLink,
nullptr, libName, global, symbolName);
static environment & get(const std::string &root_prefix_domain="jau") noexcept
Static singleton initialization of this project's environment with the given global root prefix_domai...
Low level secure dynamic linker access.
static DynamicLinker & get() noexcept
Returns static singleton instance of DynamicLinker.
static std::vector< std::string > enumerateLibraryPaths(const std::string &libName, bool searchSystemPath=false, bool searchSystemPathFirst=false) noexcept
Returns list of potential absolute library filenames.
void * symhandle_t
symbol handle within a library
void * libhandle_t
library handle
const char * lookupLibraryPathname(libhandle_t handle, const std::string &symbolName) noexcept
Interface callers may use ProcAddressHelper's reset helper method to install function pointers into a...
DynamicLinker & dynamicLinker() const noexcept
Returns the used DynamicLinker reference.
bool isValid() const noexcept
Returns true if this instance is valid, i.e.
void close() noexcept
Closes this native library.
DynamicLinker::symhandle_t dynamicLookupFunctionGlobal(const std::string &funcName) const noexcept override
Returns the function handle for function funcName gathered globally within all loaded libraries.
const std::string & resolvedLibraryPath() const noexcept
Returns the resolved native path of the opened native library, might be libraryPath() if not supporte...
const std::string & libraryPath() const noexcept
Returns the path of the opened native library file.
DynamicLinker::symhandle_t dynamicLookupFunction(const std::string &funcName) const noexcept override
Returns the function handle for function funcName gathered within the associated native library.
std::string toString() const noexcept
DynamicLinker::libhandle_t libraryHandle() const noexcept
Returns the native library handle if valid and not closed, otherwise nullptr.
bool isOpen() const noexcept
Returns true if this instance isValid() and not close()'ed, otherwise false.
static NativeLibrary open(const std::string &libName, const bool searchSystemPath, const bool searchSystemPathFirst, const bool global, const std::string &symbolName) noexcept
Opens the given native library, assuming it has the same base name on all platforms.
static NativeLibrary open(const std::string &libName, const bool searchSystemPath, const bool searchSystemPathFirst, const bool global) noexcept
Opens the given native library, assuming it has the same base name on all platforms.
#define DBG_PRINT(...)
Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] De...
std::string to_string(const endian_t v) noexcept
Return std::string representation of the given endian.
std::string to_hexstring(value_type const &v, const bool skipLeading0x=false) noexcept
Produce a lower-case hexadecimal string representation with leading 0x in MSB of the given pointer.
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2024 Gothel Software e.K.