λ61
Loading...
Searching...
No Matches
l61::ExtensionSystem::NativeExtension Class Referencefinal

Handling native extensions. More...

#include <NativeExtension.hpp>

Inheritance diagram for l61::ExtensionSystem::NativeExtension:
l61::Object

Public Types

using ExtensionEntryPoint_t = int(l61_api_extension_ptr)
using ExtensionEntryPointPtr_t = std::add_pointer_t<ExtensionEntryPoint_t>
using ExtensionEntryPointCall_t = std::function<ExtensionEntryPoint_t>

Public Member Functions

bool isValid () const
 NativeExtension (const std::string &path)
const ExtensionEntryPointCall_tgetExtensionEntryPointCall () const
const std::string & getExtensionPath () const
std::string toString () const override
void unload ()
template<typename T>
std::expected< std::add_pointer_t< std::type_identity_t< T > >, std::string > extensionSymbolLookup (const std::string &symStr) const
 A relatively safe way to look up symbols within an extension.
const lex61_header_tgetExtensionHeader () const
__inline const lex61_header_tgetExtensionHeaderAsRef () const
 ~NativeExtension () override
 NativeExtension (NativeExtension &)=delete
 NativeExtension (const NativeExtension &)=delete
 NativeExtension (NativeExtension &&nativeExtension) noexcept
Public Member Functions inherited from l61::Object
virtual ~Object ()=default
virtual std::size_t hashCode () const
 Returns a hash code for the object.
std::string typeName () const
 Returns the demangled name of the type.
const std::type_info & typeInfo () const
 Returns RTTI type information object.
virtual nlohmann::json toJsonValue () const
 Serializes the object into JSON form.
 operator std::string () const
 Explicit conversion operator to std::string.
 operator nlohmann::json () const
 Explicit conversion operator to nlohmann::json.

Static Public Member Functions

static int safeExtensionLoad (const std::expected< NativeExtension, std::string > &extension, l61_api_extension_ptr api, bool required=true)
 Safely loads an extension.
static std::expected< NativeExtension, std::string > extensionLookUp (const std::vector< std::string > &spaths, const std::string &exName)
 A lookup system.

Static Public Attributes

static constexpr const char * entryPointSymbolName = "__l61_rt_ex_init__"
 The standard entry point for an extension usually defined by the extension runtime.
static constexpr const char * headerSymbolName = "__lex61_header__"
 The symbol name for the extension header this must be self defined.

Private Member Functions

l61_rosetta_SharedLibrary_symbol_t blindSymbolLookup (const std::string &symStr) const
 Horrifically unsafe and that's why it's private.
void isGoodExtension () const

Private Attributes

std::string extensionPath
l61_rosetta_SharedLibrary_handle_t soHandle
 an OS dependent handle to a shared library
ExtensionEntryPointCall_t extensionEntryPointCall
std::mutex soMutex
 A mutex for a slight safety.

Detailed Description

Handling native extensions.

Member Typedef Documentation

◆ ExtensionEntryPoint_t

◆ ExtensionEntryPointCall_t

◆ ExtensionEntryPointPtr_t

Constructor & Destructor Documentation

◆ NativeExtension() [1/4]

l61::ExtensionSystem::NativeExtension::NativeExtension ( const std::string & path)
explicit
Parameters
pathThe full path to an extension

◆ ~NativeExtension()

l61::ExtensionSystem::NativeExtension::~NativeExtension ( )
override

◆ NativeExtension() [2/4]

l61::ExtensionSystem::NativeExtension::NativeExtension ( NativeExtension & )
delete

◆ NativeExtension() [3/4]

l61::ExtensionSystem::NativeExtension::NativeExtension ( const NativeExtension & )
delete

◆ NativeExtension() [4/4]

l61::ExtensionSystem::NativeExtension::NativeExtension ( NativeExtension && nativeExtension)
noexcept

Member Function Documentation

◆ blindSymbolLookup()

l61_rosetta_SharedLibrary_symbol_t l61::ExtensionSystem::NativeExtension::blindSymbolLookup ( const std::string & symStr) const
nodiscardprivate

Horrifically unsafe and that's why it's private.

Parameters
symStrThe name of the symbol
Returns
Returns a raw pointer to that symbol

◆ extensionLookUp()

std::expected< NativeExtension, std::string > l61::ExtensionSystem::NativeExtension::extensionLookUp ( const std::vector< std::string > & spaths,
const std::string & exName )
static

A lookup system.

Parameters
spaths
exNameExtension file name not the path
Returns
An extension on successful a string on error

◆ extensionSymbolLookup()

template<typename T>
std::expected< std::add_pointer_t< std::type_identity_t< T > >, std::string > l61::ExtensionSystem::NativeExtension::extensionSymbolLookup ( const std::string & symStr) const
inline

A relatively safe way to look up symbols within an extension.

Template Parameters
TThe type of the symbol you are looking up
Parameters
symStr
Returns
A pointer to that symbol as T* But on error returns a string
Note
for C++ code Please make sure that the symbol names are not mangled

◆ getExtensionEntryPointCall()

const NativeExtension::ExtensionEntryPointCall_t & l61::ExtensionSystem::NativeExtension::getExtensionEntryPointCall ( ) const
nodiscard
Returns
A reference to the extension entry point

◆ getExtensionHeader()

const lex61_header_t * l61::ExtensionSystem::NativeExtension::getExtensionHeader ( ) const
Returns
Returns a pointer to the extensions header

◆ getExtensionHeaderAsRef()

__inline const lex61_header_t & l61::ExtensionSystem::NativeExtension::getExtensionHeaderAsRef ( ) const
inline

◆ getExtensionPath()

const std::string & l61::ExtensionSystem::NativeExtension::getExtensionPath ( ) const
nodiscard
Returns
Returns the path to the extension

◆ isGoodExtension()

void l61::ExtensionSystem::NativeExtension::isGoodExtension ( ) const
private

◆ isValid()

bool l61::ExtensionSystem::NativeExtension::isValid ( ) const
nodiscard
Returns
Returns false of an extension has been moved or is no longer valid

◆ safeExtensionLoad()

int l61::ExtensionSystem::NativeExtension::safeExtensionLoad ( const std::expected< NativeExtension, std::string > & extension,
l61_api_extension_ptr api,
bool required = true )
static

Safely loads an extension.

Parameters
extensionFill in with the result of the lookup
apiFill in with a pointer to the api exchange structure
requiredDo you care if this extension is not loaded
Returns
The return value of the entry point

◆ toString()

std::string l61::ExtensionSystem::NativeExtension::toString ( ) const
overridevirtual
Returns
the path of the extension as well

Reimplemented from l61::Object.

◆ unload()

void l61::ExtensionSystem::NativeExtension::unload ( )

Member Data Documentation

◆ entryPointSymbolName

const char* l61::ExtensionSystem::NativeExtension::entryPointSymbolName = "__l61_rt_ex_init__"
staticconstexpr

The standard entry point for an extension usually defined by the extension runtime.

◆ extensionEntryPointCall

ExtensionEntryPointCall_t l61::ExtensionSystem::NativeExtension::extensionEntryPointCall
private

◆ extensionPath

std::string l61::ExtensionSystem::NativeExtension::extensionPath
private

◆ headerSymbolName

const char* l61::ExtensionSystem::NativeExtension::headerSymbolName = "__lex61_header__"
staticconstexpr

The symbol name for the extension header this must be self defined.

◆ soHandle

l61_rosetta_SharedLibrary_handle_t l61::ExtensionSystem::NativeExtension::soHandle
private

an OS dependent handle to a shared library

Note
Praise be to Linux dynamic linker

◆ soMutex

std::mutex l61::ExtensionSystem::NativeExtension::soMutex
mutableprivate

A mutex for a slight safety.


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