dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Plugins::SharedLibrary Class Reference

RAII wrapper for dynamic shared library loading. More...

#include <dfx-plugins/SharedLibrary.hpp>

Public Types

enum class  LoadFlag {
  Lazy = 0x01 , Now = 0x02 , Global = 0x04 , Local = 0x08 ,
  NoDelete = 0x10
}
 Flags controlling how the library is loaded into the process address space. More...

Public Member Functions

 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)
SharedLibraryoperator= (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.

Static Public Attributes

static constexpr LoadFlags defaultLoadFlags = LoadFlags(LoadFlag::Now) | LoadFlag::Local
 Default flags for plugin loading: immediate resolution and local visibility.

Detailed Description

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.

Member Enumeration Documentation

◆ 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().

Constructor & Destructor Documentation

◆ SharedLibrary() [1/2]

dfx::Plugins::SharedLibrary::SharedLibrary ( fs::path libPath,
LoadFlags loadFlags = defaultLoadFlags )
explicit

Loads a shared library from the specified path.

Exceptions
du::Exceptionif the library cannot be found or loaded.

◆ 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.

Member Function Documentation

◆ 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=()

SharedLibrary & dfx::Plugins::SharedLibrary::operator= ( SharedLibrary && other)
noexcept

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
TThe function pointer or object pointer type to cast to.
Parameters
nameThe 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.

Member Data Documentation

◆ defaultLoadFlags

LoadFlags dfx::Plugins::SharedLibrary::defaultLoadFlags = LoadFlags(LoadFlag::Now) | LoadFlag::Local
staticconstexpr

Default flags for plugin loading: immediate resolution and local visibility.


The documentation for this class was generated from the following file: