introduce active and passive events
This commit is contained in:
@@ -17,10 +17,22 @@ namespace Archimedes {
|
||||
}
|
||||
instance = this;
|
||||
roInsert = runOrder.begin();
|
||||
|
||||
registerEvent(DoLoadModuleEvent());
|
||||
registerEvent(DoUnloadModuleEvent());
|
||||
|
||||
registerEvent(LoadModuleEvent());
|
||||
registerEvent(UnloadModuleEvent());
|
||||
}
|
||||
|
||||
virtual ~App() {
|
||||
|
||||
unregisterEvent(DoLoadModuleEvent());
|
||||
unregisterEvent(DoUnloadModuleEvent());
|
||||
|
||||
unregisterEvent(LoadModuleEvent());
|
||||
unregisterEvent(UnloadModuleEvent());
|
||||
|
||||
for(std::string s : runOrder) {
|
||||
void* handle = modules[s]->getHandle();
|
||||
delete modules[s];
|
||||
@@ -40,17 +52,6 @@ namespace Archimedes {
|
||||
|
||||
virtual void run() = 0;
|
||||
|
||||
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); }
|
||||
|
||||
void end() { done = true; }
|
||||
|
||||
@@ -94,8 +95,23 @@ namespace Archimedes {
|
||||
std::list<std::string> toClose;
|
||||
std::list<std::variant<std::string, Module*>> toOpen;
|
||||
|
||||
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); }
|
||||
|
||||
virtual bool onEvent(const Event&) = 0;
|
||||
|
||||
void handleEvents() {
|
||||
static bool handled;
|
||||
|
||||
while(!events.empty()) {
|
||||
|
||||
handled = false;
|
||||
@@ -113,7 +129,13 @@ namespace Archimedes {
|
||||
}
|
||||
|
||||
if(!handled) {
|
||||
std::cout << "Error: Unhandled Event: " << (std::string) *events.front() << std::endl;
|
||||
if(this->onEvent(*events.front())) {
|
||||
Event* e = events.front();
|
||||
events.pop_front();
|
||||
delete e;
|
||||
} else {
|
||||
std::cout << "Error: Unhandled Event: " << (std::string) *events.front() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,13 +234,12 @@ namespace Archimedes {
|
||||
|
||||
runOrder.insert(roInsert, *m);
|
||||
|
||||
emitEvent(new LoadModuleEvent(*m));
|
||||
return m;
|
||||
}
|
||||
|
||||
virtual void unload(std::string name) {
|
||||
|
||||
std::cout << "Attempting to unload module: " << name << std::endl;
|
||||
|
||||
if(modules.find(name) == modules.end())
|
||||
return;
|
||||
|
||||
@@ -246,7 +267,7 @@ namespace Archimedes {
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Successfully unloaded module: " << name << std::endl;
|
||||
emitEvent(new UnloadModuleEvent(name));
|
||||
}
|
||||
|
||||
virtual void printHelp() = 0;
|
||||
|
||||
Reference in New Issue
Block a user