yeah you close
This commit is contained in:
@@ -15,17 +15,19 @@ namespace Archimedes {
|
||||
std::abort();
|
||||
}
|
||||
instance = this;
|
||||
roInsert = runOrder.begin();
|
||||
}
|
||||
|
||||
virtual ~App() {
|
||||
|
||||
for(auto it = modules.begin(); it != modules.end(); it++) {
|
||||
void* handle = (*it)->getHandle();
|
||||
delete *it;
|
||||
for(std::string s : runOrder) {
|
||||
void* handle = modules[s]->getHandle();
|
||||
delete modules[s];
|
||||
if(handle)
|
||||
dlclose(handle);
|
||||
it = modules.erase(it);
|
||||
modules[s] = nullptr;
|
||||
}
|
||||
runOrder.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,13 +37,15 @@ namespace Archimedes {
|
||||
|
||||
virtual void run() = 0;
|
||||
|
||||
virtual void stopModule(std::list<Module*>::iterator it) { toClose.push_back(*it); }
|
||||
virtual void stopModule(std::string lib) { toClose.push_back(lib); }
|
||||
|
||||
virtual void startModule(std::string lib) { toOpen.push_back(lib); }
|
||||
|
||||
void end() { done = true; }
|
||||
|
||||
private:
|
||||
|
||||
std::list<std::string>::iterator roInsert;
|
||||
|
||||
inline static App* instance = nullptr;
|
||||
|
||||
@@ -52,7 +56,7 @@ namespace Archimedes {
|
||||
std::unordered_map<std::string, Module*> modules;
|
||||
std::list<std::string> runOrder;
|
||||
|
||||
std::list<Module*> toClose;
|
||||
std::list<std::string> toClose;
|
||||
std::list<std::string> toOpen;
|
||||
|
||||
virtual Module* dynamicLoad(std::string lib) {
|
||||
@@ -75,12 +79,12 @@ namespace Archimedes {
|
||||
return create(h, Get());
|
||||
}
|
||||
|
||||
virtual Module* load(std::string modulePath, std::list<std::string>::iterator ins) {
|
||||
virtual Module* load(std::string modulePath) {
|
||||
Module* m = dynamicLoad(modulePath);
|
||||
return load(m, ins);
|
||||
return load(m);
|
||||
}
|
||||
|
||||
virtual Module* load(Module* m, std::list<std::string>::iterator ins) {
|
||||
virtual Module* load(Module* m) {
|
||||
|
||||
if(!m) {
|
||||
return nullptr;
|
||||
@@ -97,36 +101,51 @@ namespace Archimedes {
|
||||
}
|
||||
}
|
||||
|
||||
bool skip = false;
|
||||
modules[m->getName()] = m;
|
||||
|
||||
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
|
||||
|
||||
if(m->deps.find(*it) != m->deps.end()) {
|
||||
skip = true;
|
||||
m->depsInstances[*it] = modules[*it];
|
||||
}
|
||||
if(skip) {
|
||||
skip = false;
|
||||
continue;
|
||||
} else {
|
||||
//modules should be located after their dependencies
|
||||
if(std::distance(roInsert, it) <= 0) {
|
||||
roInsert = ++it--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//insert temporarily to avoid circular dependencies
|
||||
runOrder.insert(roInsert, m->getName());
|
||||
|
||||
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
|
||||
|
||||
if(m->deps.find(*it) == m->deps.end()) {
|
||||
if(std::holds_alternative<std::string>(m->deps[*it]))
|
||||
m->depsInstances[*it] = load(std::get<std::string>(m->deps[*it]), ins);
|
||||
m->depsInstances[*it] = load(std::get<std::string>(m->deps[*it]));
|
||||
else
|
||||
m->depsInstances[*it] = load(std::get<Module*>(m->deps[*it]), ins);
|
||||
m->depsInstances[*it] = load(std::get<Module*>(m->deps[*it]));
|
||||
}
|
||||
}
|
||||
|
||||
//reinsert once final order has been reached
|
||||
runOrder.remove(m->getName());
|
||||
|
||||
runOrder.insert(roInsert, m->getName());
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
virtual void unload(std::list<Module*>::iterator it) {
|
||||
Module* m = *it;
|
||||
virtual void unload(std::string name) {
|
||||
Module* m = modules[name];
|
||||
void* h = m->getHandle();
|
||||
|
||||
modules.erase(m->self);
|
||||
modules[name] = nullptr;
|
||||
delete m;
|
||||
|
||||
if(h)
|
||||
dlclose(h);
|
||||
|
||||
runOrder.remove(name);
|
||||
}
|
||||
|
||||
virtual void printHelp() = 0;
|
||||
|
||||
Reference in New Issue
Block a user