Arcade architecture
LibLoader.hpp
Go to the documentation of this file.
1
13#ifndef LIBLOADER_HPP
14#define LIBLOADER_HPP
15
16#include <memory>
17#include "IDisplayModule.hpp"
18#include "LoaderType.hpp"
19#include "Exception.hpp"
20#include "DynamicLib.hpp" // Ensure this header contains the declaration of getFunctionDynamicLib
21
22namespace Loader
23{
32 class LibLoader {
33 protected:
34 void *_moduleHandle = nullptr;
35 std::string _modulePath;
38 typedef Loader::ModuleType_t (*GetModuleTypeFct)();
41 public:
42
47 Loader::ModuleType_t getModuleType() const {return this->_moduleType;};
48
53 const char *getModulePath() const {return this->_modulePath.c_str();};
54
66 template<class T>
68 T *(*create)() = reinterpret_cast< T *(*)()>(getFunctionDynamicLib(this->_moduleHandle, "getClass"));
69 if (!create)
70 throw DllException("Error cannot getClass function");
71 return (*create)();
72 }
73
82 void closeLib();
95 void openLib(const std::string &path);
96
103 LibLoader() = default;
104
110 ~LibLoader();
111 };
112}
113#endif //LIBLOADER_HPP
Header file for dynamic library handling functions.
void * getFunctionDynamicLib(void *moduleHandle, const char *name)
Retrieves a function or symbol from a dynamic library.
Definition: DynamicLib.cpp:16
Exception class for handling DLL-related errors in the barcade project.
Interface for display modules in the barcade project.
Defines the module types used in the Loader namespace.
Exception class for handling DLL-related errors.
Definition: Exception.hpp:29
A class for dynamically loading and managing modules.
Definition: LibLoader.hpp:32
~LibLoader()
Destructor for the LibLoader class.
Definition: LibLoader.cpp:34
Loader::ModuleType_t _moduleType
Definition: LibLoader.hpp:36
GetModuleTypeFct _getModuleType
Definition: LibLoader.hpp:39
std::string _modulePath
Definition: LibLoader.hpp:35
T * initEntryPoint()
Initializes and retrieves an instance of a class from a dynamically loaded library.
Definition: LibLoader.hpp:67
Loader::ModuleType_t(* GetModuleTypeFct)()
Definition: LibLoader.hpp:38
LibLoader()=default
Constructor for the LibLoader class.
Loader::ModuleType_t getModuleType() const
Get the type of the loaded module.
Definition: LibLoader.hpp:47
void openLib(const std::string &path)
Opens a shared library from the specified file path.
Definition: LibLoader.cpp:11
const char * getModulePath() const
Get the path of the loaded module.
Definition: LibLoader.hpp:53
void closeLib()
Closes the currently loaded library.
Definition: LibLoader.cpp:28
void * _moduleHandle
Definition: LibLoader.hpp:34
@ TYPE_COUNT
Definition: LoaderType.hpp:40