make apps customizable
This commit is contained in:
@@ -5,7 +5,7 @@ Archimedes::App* Archimedes::App::instance = nullptr;
|
||||
namespace Archimedes {
|
||||
|
||||
|
||||
App::App(const int& argc, char* argv[]) {
|
||||
App::App() {
|
||||
|
||||
if(instance != nullptr) {
|
||||
std::cout << "App already exists\nThere can only be one!\n";
|
||||
@@ -16,8 +16,6 @@ namespace Archimedes {
|
||||
|
||||
instance = this;
|
||||
|
||||
handleArgs(argc, argv);
|
||||
|
||||
}
|
||||
|
||||
App::~App() {
|
||||
@@ -34,7 +32,6 @@ namespace Archimedes {
|
||||
|
||||
bool App::load(std::string lib, std::list<std::string> blacklist = {}) {
|
||||
|
||||
|
||||
std::cout << "print twice!\n";
|
||||
void* h = dlopen(lib.c_str(), RTLD_NOW);
|
||||
|
||||
@@ -105,61 +102,4 @@ namespace Archimedes {
|
||||
toOpen.push_back(lib);
|
||||
}
|
||||
|
||||
void App::handleArgs(const int& argc, char* argv[]) {
|
||||
|
||||
int i = 1;
|
||||
|
||||
if(argc == 1) {
|
||||
printHelp();
|
||||
end();
|
||||
}
|
||||
|
||||
while(i < argc) {
|
||||
if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
|
||||
printHelp();
|
||||
end();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
while(i < argc) {
|
||||
std::cout << "Attempting to load: " << argv[i] << std::endl;
|
||||
load(argv[i]);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void App::printHelp() {
|
||||
std::cout << "archimedes [ -h | --help ] /path/to/some/library.so\n";
|
||||
}
|
||||
|
||||
|
||||
void App::run() {
|
||||
std::cout << "\nTesting...\n";
|
||||
|
||||
for(auto* m : modules)
|
||||
m->onLoad();
|
||||
|
||||
// Main loop
|
||||
while (!done && !modules.empty()) {
|
||||
|
||||
for(auto* m : modules) {
|
||||
m->run();
|
||||
}
|
||||
|
||||
for(auto it = toClose.begin(); it != toClose.end(); it++) {
|
||||
unload(it);
|
||||
}
|
||||
toClose.clear();
|
||||
|
||||
for(std::string s : toOpen) {
|
||||
load(s, getBlacklist());
|
||||
}
|
||||
toOpen.clear();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ namespace Archimedes {
|
||||
virtual bool load(std::string, std::list<std::string>);
|
||||
virtual void unload(std::list<Module*>::iterator);
|
||||
|
||||
virtual void handleArgs(const int&, char*[]);
|
||||
virtual void handleArgs(const int&, char*[]) = 0;
|
||||
|
||||
virtual void printHelp();
|
||||
virtual void printHelp() = 0;
|
||||
|
||||
std::list<std::string> getBlacklist() {
|
||||
std::list<std::string> l;
|
||||
@@ -32,16 +32,16 @@ namespace Archimedes {
|
||||
}
|
||||
|
||||
public:
|
||||
App(const int&, char*[]);
|
||||
~App();
|
||||
App();
|
||||
virtual ~App();
|
||||
|
||||
static App& Get() { return *instance; }
|
||||
static App* Get() { return instance; }
|
||||
|
||||
void run();
|
||||
virtual void run() = 0;
|
||||
|
||||
void stopModule(std::list<Module*>::iterator);
|
||||
virtual void stopModule(std::list<Module*>::iterator);
|
||||
|
||||
void startModule(std::string);
|
||||
virtual void startModule(std::string);
|
||||
|
||||
void end() { done = true; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user