work on testMenu
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#include "testMenu.h"
|
#include "testMenu.h"
|
||||||
|
|
||||||
TestMenu::TestMenu() {}
|
TestMenu::TestMenu(void* h) {
|
||||||
|
handle = h;
|
||||||
|
}
|
||||||
|
|
||||||
TestMenu::~TestMenu() {}
|
TestMenu::~TestMenu() {}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
class TestMenu : public Module {
|
class TestMenu : public Module {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TestMenu();
|
TestMenu(void*);
|
||||||
~TestMenu();
|
~TestMenu();
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
@@ -13,8 +13,8 @@ class TestMenu : public Module {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Module* create() {
|
Module* create(void* handle) {
|
||||||
return new TestMenu();
|
return new TestMenu(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy(Module* m) {
|
void destroy(Module* m) {
|
||||||
|
|||||||
36
src/App.cpp
36
src/App.cpp
@@ -25,14 +25,44 @@ App::~App() {
|
|||||||
void App::run() {
|
void App::run() {
|
||||||
std::cout << "\nTesting...\n";
|
std::cout << "\nTesting...\n";
|
||||||
|
|
||||||
|
done = modules.empty();
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (!done) {
|
while (!done) {
|
||||||
end();
|
|
||||||
|
for(auto it = modules.begin(); it != modules.end(); it++)
|
||||||
|
(*it)->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::load(std::string lib) {
|
void App::load(std::string lib) {
|
||||||
|
|
||||||
|
void* handle = dlopen(lib.c_str(), RTLD_LAZY);
|
||||||
|
|
||||||
|
if(!handle) {
|
||||||
|
std::cout << "could not open lib!\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Module::create_t* create = (Module::create_t*) dlsym(handle, "create");
|
||||||
|
if(dlerror()) {
|
||||||
|
std::cout << "error finding create function in file: " << lib << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Module::destroy_t* destroy = (Module::destroy_t*) dlsym(handle, "destroy");
|
||||||
|
if(dlerror()) {
|
||||||
|
std::cout << "error finding destroy function in file: " << lib << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Module* m = create(handle);
|
||||||
|
|
||||||
|
for(auto it = modules.begin(); it != modules.end(); it++) {
|
||||||
|
|
||||||
|
if((*it)->getName() != "") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::handleArgs(const int& argc, char* argv[]) {
|
void App::handleArgs(const int& argc, char* argv[]) {
|
||||||
@@ -56,3 +86,7 @@ void App::handleArgs(const int& argc, char* argv[]) {
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void App::printHelp() {
|
||||||
|
std::cout << "archimedes [ -h | --help ] /path/to/some/library.so\n";
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,12 +6,17 @@
|
|||||||
class Module {
|
class Module {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef Module* create_t();
|
typedef Module* create_t(void*);
|
||||||
typedef void destroy_t(Module*);
|
typedef void destroy_t(Module*);
|
||||||
|
|
||||||
|
|
||||||
virtual ~Module() {}
|
virtual ~Module() {}
|
||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
|
std::string getName() const { return name; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string name;
|
||||||
|
void* handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user