From 2b1293d4148dbf73714459ddbd4f91db3cac572b Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 14 Mar 2025 16:13:26 -0500 Subject: [PATCH] add App& member to Module class --- modules/print/src/print.cpp | 5 ++--- modules/print/src/print.h | 6 +++--- src/App.cpp | 2 +- src/Module.h | 9 +++++++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/print/src/print.cpp b/modules/print/src/print.cpp index 14afe2a..35b563f 100644 --- a/modules/print/src/print.cpp +++ b/modules/print/src/print.cpp @@ -1,7 +1,6 @@ #include "print.h" -Print::Print(void* h) { - handle = h; +Print::Print(void* h, App& a) : Module(h, a) { name = "Print"; } @@ -12,6 +11,6 @@ Print::~Print() { void Print::run() { std::cout << "Print lib loaded and run!\n"; //App::Get().unload(self); - App::Get().end(); + app.end(); std::cout << "App::Get() called\n"; } diff --git a/modules/print/src/print.h b/modules/print/src/print.h index 803a7d3..e082b8f 100644 --- a/modules/print/src/print.h +++ b/modules/print/src/print.h @@ -3,14 +3,14 @@ class Print : public Module { public: - Print(void*); + Print(void*, App&); ~Print(); void run(); }; extern "C" { - Module* create(void* handle) { - return new Print(handle); + Module* create(void* handle, App& app) { + return new Print(handle, app); } } diff --git a/src/App.cpp b/src/App.cpp index 4c1395e..9c3fc00 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -63,7 +63,7 @@ void App::load(std::string lib) { std::cout << "error finding create function in file: " << lib << std::endl; } - Module* m = create(h); + Module* m = create(h, App::Get()); for(auto it = modules.begin(); it != modules.end(); it++) { diff --git a/src/Module.h b/src/Module.h index 7d01bca..598ef1e 100644 --- a/src/Module.h +++ b/src/Module.h @@ -3,13 +3,15 @@ #include "pch.hpp" +class App; + class Module { public: - typedef Module* create_t(void*); + typedef Module* create_t(void*, App&); typedef void* destroy_t(Module*); - + Module(void* h, App& a) : handle(h), app(a) {}; virtual ~Module() {} virtual void run() = 0; std::string getName() const { return name; } @@ -21,6 +23,9 @@ class Module { std::string name; void* handle; std::list::iterator self; + + App& app; + }; #endif