modules must pass dynamic handles to static dependencies
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -11,7 +11,7 @@ ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Mo
|
||||
|
||||
name = "ImguiModule";
|
||||
|
||||
WindowModule* wm = new WindowModule(a);
|
||||
WindowModule* wm = new WindowModule(a, h);
|
||||
deps[wm->getName()] = wm;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ MainGUI::MainGUI(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "MainGUI";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, nullptr);
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[im->getName()] = im;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Ollama::Ollama(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "Ollama";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, nullptr);
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[im->getName()] = im;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ Terminal::Terminal(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "Terminal";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, nullptr);
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[im->getName()] = im;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user