work on ServerModule
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
#include <list>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "pch.hpp"
|
||||
#include "utils/Module/Module.h"
|
||||
#include "utils/Events/Event.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
@@ -55,9 +56,22 @@ namespace Archimedes {
|
||||
|
||||
bool isDone() const { return done; }
|
||||
|
||||
std::unordered_map<std::string, unsigned int> getEventTypes() const { return eventTypes; }
|
||||
void emitEvent(Event* e) { events.push_back(e); }
|
||||
|
||||
void addEventType(std::string type) { eventTypes[type] = nextEventType++; }
|
||||
unsigned int getEventType(std::string event) { return eventTypes[event]; }
|
||||
|
||||
void addEventType(std::string type) {
|
||||
//only add each type once
|
||||
if(eventTypes.find(type) == eventTypes.end())
|
||||
eventTypes[type] = nextEventType++;
|
||||
}
|
||||
|
||||
void removeEventType(std::string type) {
|
||||
//only erase registered types
|
||||
auto it = eventTypes.find(type);
|
||||
if(it != eventTypes.end())
|
||||
eventTypes.erase(it);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -73,10 +87,25 @@ namespace Archimedes {
|
||||
std::unordered_map<std::string, Module*> modules;
|
||||
std::unordered_map<std::string, unsigned int> eventTypes;
|
||||
|
||||
std::list<Event*> events;
|
||||
|
||||
std::list<std::string> runOrder;
|
||||
|
||||
std::list<std::string> toClose;
|
||||
std::list<std::variant<std::string, Module*>> toOpen;
|
||||
|
||||
void handleEvents() {
|
||||
while(!events.empty()) {
|
||||
for(auto it = runOrder.rbegin(); it != runOrder.rend(); it++) {
|
||||
if(modules[*it]->onEvent(*events.front())) {
|
||||
Event* e = events.front();
|
||||
events.pop_front();
|
||||
delete e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual Module* dynamicLoad(std::string lib) {
|
||||
|
||||
@@ -169,18 +198,12 @@ namespace Archimedes {
|
||||
|
||||
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;
|
||||
modules.erase(name);
|
||||
|
||||
runOrder.remove(name);
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
unsigned int type;
|
||||
virtual ~Event() {}
|
||||
|
||||
virtual operator std::string() const = 0;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user