more work on testMenu
This commit is contained in:
22
src/App.cpp
22
src/App.cpp
@@ -20,15 +20,19 @@ App::App(const int& argc, char* argv[]) {
|
||||
App::~App() {
|
||||
|
||||
std::cout << "\nExiting...";
|
||||
for(auto it = modules.begin(); it != modules.end(); it++) {
|
||||
void* handle = (*it)->getHandle();
|
||||
delete *it;
|
||||
dlclose(handle);
|
||||
modules.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void App::run() {
|
||||
std::cout << "\nTesting...\n";
|
||||
|
||||
done = modules.empty();
|
||||
|
||||
// Main loop
|
||||
while (!done) {
|
||||
while (!done && !modules.empty()) {
|
||||
|
||||
for(auto it = modules.begin(); it != modules.end(); it++)
|
||||
(*it)->run();
|
||||
@@ -64,10 +68,22 @@ void App::load(std::string lib) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void App::unload(std::list<Module*>::iterator it) {
|
||||
void* handle = (*it)->getHandle();
|
||||
delete *it;
|
||||
dlclose(handle);
|
||||
modules.erase(it);
|
||||
}
|
||||
|
||||
void App::handleArgs(const int& argc, char* argv[]) {
|
||||
|
||||
int i = 0;
|
||||
|
||||
if(argc == 0) {
|
||||
printHelp();
|
||||
end();
|
||||
}
|
||||
|
||||
while(i < argc) {
|
||||
if(strcmp(argv[i], "-h") == 0) {
|
||||
|
||||
@@ -12,9 +12,7 @@ class App {
|
||||
|
||||
bool done;
|
||||
|
||||
std::vector<Module*> modules;
|
||||
std::vector<Module::create_t> mCreators;
|
||||
std::vector<Module::destroy_t> mDestroyers;
|
||||
std::list<Module*> modules;
|
||||
|
||||
public:
|
||||
App(const int&, char*[]);
|
||||
@@ -26,11 +24,13 @@ class App {
|
||||
|
||||
void load(std::string);
|
||||
|
||||
void unload(std::list<Module*>::iterator);
|
||||
|
||||
void handleArgs(const int&, char*[]);
|
||||
|
||||
void printHelp();
|
||||
|
||||
void end() { done = true; };
|
||||
void end() { done = true; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,16 +7,18 @@ class Module {
|
||||
|
||||
public:
|
||||
typedef Module* create_t(void*);
|
||||
typedef void destroy_t(Module*);
|
||||
typedef void* destroy_t(Module*);
|
||||
|
||||
|
||||
virtual ~Module() {}
|
||||
virtual void run() = 0;
|
||||
std::string getName() const { return name; }
|
||||
void* getHandle() { return handle; }
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
void* handle;
|
||||
std::list<Module*>::iterator self;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user