RAII wrapper for dynamic shared library loading.
More...
#include <dfx-plugins/SharedLibrary.hpp>
|
|
| DFX_DECLARE_FLAGS (LoadFlags, LoadFlag) |
| | SharedLibrary (fs::path libPath, LoadFlags loadFlags=defaultLoadFlags) |
| | Loads a shared library from the specified path.
|
| | SharedLibrary (SharedLibrary &&other) noexcept |
| | Move constructor. Transfers ownership of the library handle.
|
| | ~SharedLibrary () |
| | Destructor. Calls dlclose() if the handle is valid.
|
|
| DFX_DISABLE_COPY (SharedLibrary) |
| SharedLibrary & | operator= (SharedLibrary &&other) noexcept |
| | Move assigment operator. Transfers ownership of the library handle.
|
| fs::path const & | libPath () const noexcept |
| | Returns the filesystem path to the shared library.
|
| bool | isLoaded () const noexcept |
| | Checks if the library is currently loaded.
|
| template<typename T> |
| std::expected< T, std::string > | resolveSymbol (std::string const &name) const noexcept |
| | Resolves a symbol address and casts it to the requested type.
|
RAII wrapper for dynamic shared library loading.
SharedLibrary manages the lifecycle of a loaded shared object (.so). It provides a type-safe interface for symbol resolution and ensures that dlclose() is called only when the object is no longer needed.
◆ LoadFlag
Flags controlling how the library is loaded into the process address space.
| Enumerator |
|---|
| Lazy | Perform lazy binding. Only resolve symbols as they are needed.
|
| Now | Resolve all undefined symbols before dlopen() returns.
|
| Global | Make symbols in this library available for subsequently loaded libraries.
|
| Local | Symbols are not made available to resolve references in subsequently loaded libraries.
|
| NoDelete | Do not unload the library during dlclose().
|
◆ SharedLibrary() [1/2]
| dfx::Plugins::SharedLibrary::SharedLibrary |
( |
fs::path | libPath, |
|
|
LoadFlags | loadFlags = defaultLoadFlags ) |
|
explicit |
Loads a shared library from the specified path.
- Exceptions
-
◆ SharedLibrary() [2/2]
| dfx::Plugins::SharedLibrary::SharedLibrary |
( |
SharedLibrary && | other | ) |
|
|
noexcept |
Move constructor. Transfers ownership of the library handle.
◆ ~SharedLibrary()
| dfx::Plugins::SharedLibrary::~SharedLibrary |
( |
| ) |
|
Destructor. Calls dlclose() if the handle is valid.
◆ isLoaded()
| bool dfx::Plugins::SharedLibrary::isLoaded |
( |
| ) |
const |
|
inlinenoexcept |
Checks if the library is currently loaded.
◆ libPath()
| fs::path const & dfx::Plugins::SharedLibrary::libPath |
( |
| ) |
const |
|
inlinenoexcept |
Returns the filesystem path to the shared library.
◆ operator=()
Move assigment operator. Transfers ownership of the library handle.
◆ resolveSymbol()
template<typename T>
| std::expected< T, std::string > dfx::Plugins::SharedLibrary::resolveSymbol |
( |
std::string const & | name | ) |
const |
|
inlinenoexcept |
Resolves a symbol address and casts it to the requested type.
- Template Parameters
-
| T | The function pointer or object pointer type to cast to. |
- Parameters
-
| name | The exact name of the symbol in the ELF symbol table. |
- Returns
- std::expected containing the typed pointer on success, or an error string on failure.
◆ defaultLoadFlags
Default flags for plugin loading: immediate resolution and local visibility.
The documentation for this class was generated from the following file: