From e5aea5bce01a6998357e6b54e028141182ed94f5 Mon Sep 17 00:00:00 2001 From: Malte Langosz Date: Thu, 14 Nov 2024 21:31:42 +0100 Subject: [PATCH] Add option to create new instances of loaded libraries --- src/LibManager.cpp | 25 +++++++++++++++++++++++-- src/LibManager.hpp | 3 +++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/LibManager.cpp b/src/LibManager.cpp index 0cffea9..2c767e7 100644 --- a/src/LibManager.cpp +++ b/src/LibManager.cpp @@ -133,6 +133,8 @@ namespace lib_manager { string name = _lib->getLibName(); newLib.destroy = 0; + newLib.create = 0; + newLib.configCreate = 0; newLib.libInterface = _lib; newLib.useCount = 1; newLib.wasUnloaded = false; @@ -165,6 +167,8 @@ namespace lib_manager { libStruct newLib; newLib.destroy = 0; + newLib.create = 0; + newLib.configCreate = 0; newLib.libInterface = 0; newLib.useCount = 0; newLib.wasUnloaded = false; @@ -177,12 +181,16 @@ namespace lib_manager { if(newLib.destroy) { if(!config) { createLib *tmp_con = getFunc(pl, "create_c"); - if(tmp_con) + if(tmp_con) { + newLib.create = tmp_con; newLib.libInterface = tmp_con(this); + } } else { createLib2 *tmp_con2 = getFunc(pl, "config_create_c"); - if(tmp_con2) + if(tmp_con2){ + newLib.configCreate = tmp_con2; newLib.libInterface = tmp_con2(this, config); + } } } } @@ -303,6 +311,19 @@ namespace lib_manager { return theLib->libInterface; } + LibInterface* LibManager::getNewInstance(const string &libName) { + if(libMap.find(libName) == libMap.end()) { +#ifdef DEBUF + fprintf(stderr, "LibManager: could not find \"%s\"\n", libName.c_str()); +#endif + return 0; + } + libStruct *theLib = &(libMap[libName]); + // todo: clear how to deal with the use count in this case + //theLib->useCount++; + return theLib->create(this); + } + /** * Releases a previously acquired library * @param libName diff --git a/src/LibManager.hpp b/src/LibManager.hpp index 68fb7a5..292b7ae 100644 --- a/src/LibManager.hpp +++ b/src/LibManager.hpp @@ -45,6 +45,8 @@ namespace lib_manager { struct libStruct { LibInterface *libInterface; destroyLib *destroy; + createLib *create; + createLib2 *configCreate; int useCount; bool wasUnloaded; std::string path; @@ -92,6 +94,7 @@ namespace lib_manager { bool load = false) { return acquireLibraryAs(libName, load); } + LibInterface* getNewInstance(const std::string &libName); ErrorNumber releaseLibrary(const std::string &libName); ErrorNumber unloadLibrary(const std::string &libPath);