16#include <dfx-utilities/CompilerSupport.hpp>
19#include <dfx-utilities/FileSystem.hpp>
67 fs::path
const &
libPath() const noexcept {
return _libPath; }
70 bool isLoaded() const noexcept {
return _handle !=
nullptr; }
80 std::expected<T, std::string>
resolveSymbol(std::string
const & name)
const noexcept
82 auto const result = _resolveSymbolImpl(name.c_str());
83 if (!result.has_value())
84 return std::unexpected(result.error());
87 DFX_DIAGNOSTIC_IGNORE(
"-Wconditionally-supported")
88 return reinterpret_cast<T
>(result.value());
93 void _close() noexcept;
94 std::expected<
void *,
std::
string> _resolveSymbolImpl(
char const * name) const noexcept;
98 void * _handle =
nullptr;
Convenience macros to explicitly control copy and move semantics.
#define DFX_DISABLE_COPY(ClassName)
Disable copy (copy ctor + copy-assign)
Definition CopyMoveControl.hpp:27
Macro-based enum <-> string utilities for dfx.
#define DFX_DECLARE_ENUM_STRING_FUNCTIONS(E)
Declare the enum string API (and std::formatter) for enum type E.
Definition EnumString.hpp:327
Typesafe enum bitmask wrapper and helper macros.
#define DFX_DECLARE_OPERATOR_FOR_FLAGS(FlagsName)
Declare a free operator| to combine two enum values into a Flags.
Definition Flags.hpp:325
#define DFX_DECLARE_STD_FORMATTER_FOR_FLAGS(FlagsName)
Declare a std::formatter<FlagsName> that prints set flags joined by |.
Definition Flags.hpp:342
#define DFX_DECLARE_FLAGS(FlagsName, Enum)
Declare a convenient alias for dfx::Utils::Flags<Enum>.
Definition Flags.hpp:309
RAII wrapper for dynamic shared library loading.
Definition SharedLibrary.hpp:32
LoadFlag
Flags controlling how the library is loaded into the process address space.
Definition SharedLibrary.hpp:36
@ Now
Resolve all undefined symbols before dlopen() returns.
Definition SharedLibrary.hpp:38
@ Lazy
Perform lazy binding. Only resolve symbols as they are needed.
Definition SharedLibrary.hpp:37
@ Global
Make symbols in this library available for subsequently loaded libraries.
Definition SharedLibrary.hpp:39
@ Local
Symbols are not made available to resolve references in subsequently loaded libraries.
Definition SharedLibrary.hpp:40
@ NoDelete
Do not unload the library during dlclose().
Definition SharedLibrary.hpp:41
~SharedLibrary()
Destructor. Calls dlclose() if the handle is valid.
fs::path const & libPath() const noexcept
Returns the filesystem path to the shared library.
Definition SharedLibrary.hpp:67
bool isLoaded() const noexcept
Checks if the library is currently loaded.
Definition SharedLibrary.hpp:70
SharedLibrary(SharedLibrary &&other) noexcept
Move constructor. Transfers ownership of the library handle.
std::expected< T, std::string > resolveSymbol(std::string const &name) const noexcept
Resolves a symbol address and casts it to the requested type.
Definition SharedLibrary.hpp:80
SharedLibrary & operator=(SharedLibrary &&other) noexcept
Move assigment operator. Transfers ownership of the library handle.
SharedLibrary(fs::path libPath, LoadFlags loadFlags=defaultLoadFlags)
Loads a shared library from the specified path.
static constexpr LoadFlags defaultLoadFlags
Default flags for plugin loading: immediate resolution and local visibility.
Definition SharedLibrary.hpp:46
Definition MessageApi.hpp:16
std::unique_ptr< SharedLibrary > SharedLibraryPtr
Unique ownership pointer type for SharedLibrary.
Definition SharedLibrary.hpp:102
Definition Message.hpp:21