modules must pass dynamic handles to static dependencies

This commit is contained in:
2025-04-12 18:00:12 -05:00
parent a3b3a9b6e8
commit d068bcbabd
5 changed files with 32 additions and 9 deletions

View File

@@ -39,7 +39,15 @@ namespace Archimedes {
virtual void run() = 0;
virtual void stopModule(std::string lib) { toClose.push_back(lib); }
virtual void stopModule(std::string lib) {
//unload modules that depend on the one we are unloading
for(std::string s : runOrder) {
if(modules[s]->deps.find(lib) != modules[s]->deps.end()) {
stopModule(s);
}
}
toClose.push_back(lib);
}
virtual void startModule(std::variant<std::string, Module*> m) { toOpen.push_back(m); }
@@ -148,27 +156,42 @@ namespace Archimedes {
virtual void unload(std::string name) {
std::cout << "Attempting to unload module: " << name << std::endl;
if(modules.find(name) == modules.end())
return;
/*
//unload modules that depend on the one we are unloading
for(std::string s : runOrder) {
if(modules[s]->deps.find(name) != modules[s]->deps.end()) {
unload(s);
}
}
*/
Module* m = modules[name];
void* h = m->getHandle();
modules[name] = nullptr;
runOrder.remove(name);
if(h) {
//don't dlclose if other modules are still in runOrder!
bool closable = true;
for(auto s = runOrder.begin(); s != runOrder.end(); s++) {
if(modules[*s]->getHandle() == h) {
closable = false;
}
}
delete m;
dlclose(h);
if(closable) {
dlclose(h);
}
}
runOrder.remove(name);
std::cout << "Successfully unloaded module: " << name << std::endl << "runOrder.empty(): " << runOrder.empty() << std::endl;
}
virtual void printHelp() = 0;