diff --git a/include/GraphicalAPI/GraphicalAPI.hpp b/include/GraphicalAPI/GraphicalAPI.hpp index 0736d217..22889679 100644 --- a/include/GraphicalAPI/GraphicalAPI.hpp +++ b/include/GraphicalAPI/GraphicalAPI.hpp @@ -86,6 +86,7 @@ namespace Polymorph static void reloadAPI(std::string newHandler); static void *getHandler(); + static std::string getHandlerPath() const; private: static void _unloadModules(); diff --git a/src/GraphicalAPI/GraphicalAPI.cpp b/src/GraphicalAPI/GraphicalAPI.cpp index 9ceffb82..cd6cf917 100644 --- a/src/GraphicalAPI/GraphicalAPI.cpp +++ b/src/GraphicalAPI/GraphicalAPI.cpp @@ -12,6 +12,8 @@ Polymorph::GraphicalAPI::GraphicalAPI(std::string handlerPath) { _handlerPath = handlerPath; + if (_instance != nullptr) + throw GraphicalException("Cannot create several Graphical API instance at once.", Logger::MAJOR); _instance = this; } @@ -87,10 +89,21 @@ void Polymorph::GraphicalAPI::reloadAPI(std::string newHandler) _instance->_d_display = loadSymbol("deleteDisplay"); _instance->_d_sprite = loadSymbol("destroySprite"); _instance->_d_text = loadSymbol("destroyText"); + _instance->_handlerPath = newHandler; _reloadModules(); } +std::string Polymorph::GraphicalAPI::getHandlerPath() +{ + if (!_instance) + { + Logger::log("No Graphic API handler available to reload.", Logger::MAJOR); + return ""; + } + return _instance->_handlerPath; +} + Polymorph::Text Polymorph::GraphicalAPI::createText(std::shared_ptr &data) {