8#include "Arp/System/Core/CommonTypeName.hxx"
9#include "Arp/System/Commons/Runtime/SharedLibrary.hpp"
10#include "Arp/System/Commons/Extensibility/SharedModuleLibraryLoader.hpp"
11#include "Arp/System/Commons/Extensibility/ModuleLibraryBase.hxx"
12#include "Arp/System/Commons/Exceptions/InvalidOperationException.hpp"
14namespace Arp {
namespace System {
namespace Commons {
namespace Extensibility
21template<
typename TModuleInterface>
30 using ModuleLibraryFactoryFunction =
const ModuleLibrary & (*)();
33 explicit SharedModuleLibrary(
const String& path, SharedLibraryMemoryLockOption sharedLibraryMemoryLockOption = SharedLibraryMemoryLockOption::Nothing);
47 template<
typename TModule>
64 ModuleLibraryFactoryFunction GetModuleLibraryFactoryFunction(
SharedLibrary& sharedLibrary)
const;
73template<
typename TModuleInterface>
75 : loader(path, sharedLibraryMemoryLockOption)
83template<
typename TModuleInterface>
84template<
typename TModule>
94template<
typename TModuleInterface>
98 if (this->libraryBase ==
nullptr)
104 return this->libraryBase->GetFactory().Create(moduleName);
109template<
typename TModuleInterface>
112 return loader.GetFullPath();
116template<
typename TModuleInterface>
119 return loader.GetFileName();
123template<
typename TModuleInterface>
126 return loader.Exists();
130template<
typename TModuleInterface>
133 return loader.IsLoaded();
139template<
typename TModuleInterface>
143 if (this->loader.IsLoaded())
145 auto f = GetModuleLibraryFactoryFunction(this->loader.GetSharedLibrary());
146 this->libraryBase = &f();
151template<
typename TModuleInterface>
154 if (this->loader.IsLoaded())
156 this->libraryBase =
nullptr;
158 this->loader.Unload();
161template<
typename TModuleInterface>
162typename SharedModuleLibrary<TModuleInterface>::ModuleLibraryFactoryFunction
165 auto result =
reinterpret_cast<ModuleLibraryFactoryFunction
>(
167 if (result ==
nullptr)
170 "Could not get module library factory function from '{0}'", this->GetFileName());
This exception is thrown when an operation cannot be executed because the related state is invalid.
Definition: InvalidOperationException.hpp:16
This (meta programming) class provides the type-name according the CLS (common language specification...
Definition: CommonTypeName.hxx:33
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
Base class for a library providing extension modules
Definition: ModuleLibraryBase.hxx:29
Definition: SharedModuleLibraryLoader.hpp:17
Base class for loading a library with modules
Definition: SharedModuleLibrary.hxx:23
SharedModuleLibrary(SharedModuleLibrary &&arg)=delete
Move constructor.
void Unload()
Unload the library
Definition: SharedModuleLibrary.hxx:152
const String & GetFullPath() const
Returns the full path to the library file
Definition: SharedModuleLibrary.hxx:110
bool IsLoaded() const
Returns true if the library is loaded
Definition: SharedModuleLibrary.hxx:131
String GetFileName() const
Returns the file name of the library (without directory)
Definition: SharedModuleLibrary.hxx:117
SharedModuleLibrary & operator=(SharedModuleLibrary &&arg)=delete
Move-assignment operator.
SharedModuleLibrary(const SharedModuleLibrary &arg)=delete
Copy constructor.
SharedModuleLibrary(const String &path, SharedLibraryMemoryLockOption sharedLibraryMemoryLockOption=SharedLibraryMemoryLockOption::Nothing)
Constructs an SharedModuleLibrary instance.
Definition: SharedModuleLibrary.hxx:74
virtual ~SharedModuleLibrary(void)=default
Destructs this instance and frees all resources.
virtual String GetModuleLibraryFactoryFunctionName() const =0
Returns the name of the factory function for the module library
void Load()
Loads the library
Definition: SharedModuleLibrary.hxx:140
SharedModuleLibrary & operator=(const SharedModuleLibrary &arg)=delete
Copy-assignment operator.
ModuleInterfacePtr CreateModule() const
Creates a module by type
Definition: SharedModuleLibrary.hxx:85
std::unique_ptr< TModuleInterface > ModuleInterfacePtr
owning pointer to a module
Definition: SharedModuleLibrary.hxx:26
bool Exists() const
Returns true if the library file exists.
Definition: SharedModuleLibrary.hxx:124
High level API to enable work with dynamically loadable shared libraries.
Definition: SharedLibrary.hpp:21
void * GetFunctionAddress(const String &symbolName)
Returns the address where specified symbol is located in the memory.
Definition: SharedLibrary.cpp:104
Root namespace for the PLCnext API