This commit is contained in:
2025-03-14 15:54:04 -05:00
parent a8dff07bf1
commit d53ace06cf
2 changed files with 16 additions and 10 deletions

View File

@@ -19,12 +19,16 @@ App::App(const int& argc, char* argv[]) {
App::~App() {
std::cout << "\nExiting...";
std::cout << "\nExiting...\n";
for(auto it = modules.begin(); it != modules.end(); it++) {
void* handle = (*it)->getHandle();
std::cout << "retrieved handle\n";
delete *it;
std::cout << "deleted module\n";
dlclose(handle);
modules.erase(it);
std::cout << "closed lib\n";
it = modules.erase(it);
std::cout << "erased list node\n";
}
}
@@ -34,28 +38,30 @@ void App::run() {
// Main loop
while (!done && !modules.empty()) {
for(auto it = modules.begin(); it != modules.end(); it++)
for(auto it = modules.begin(); it != modules.end(); it++) {
std::cout << "Running module: " << (*it)->getName() << std::endl;
(*it)->run();
}
}
}
void App::load(std::string lib) {
void* handle = dlopen(lib.c_str(), RTLD_LAZY);
void* h = dlopen(lib.c_str(), RTLD_NOW);
if(!handle) {
std::cout << "could not open lib!\n";
if(!h) {
std::cout << "could not open lib: \"" << lib.c_str() << "\"\nError: " << dlerror() << std::endl;
return;
}
Module::create_t* create = (Module::create_t*) dlsym(handle, "create");
Module::create_t* create = (Module::create_t*) dlsym(h, "create");
if(dlerror()) {
std::cout << "error finding create function in file: " << lib << std::endl;
}
Module* m = create(handle);
Module* m = create(h);
for(auto it = modules.begin(); it != modules.end(); it++) {
@@ -96,7 +102,7 @@ void App::handleArgs(const int& argc, char* argv[]) {
}
while(i < argc) {
std::cout << "Attempting to load: " << argv[i] << std::endl;
load(argv[i]);
i++;