Feat: Simple module system

This commit is contained in:
xiaozhou233 committed 2026-04-19 18:57:32 +08:00
1 parent e7ce54188b
commit 6858a35754
4 files changed
+82

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include <string>
namespace JuiceAgent::Core::Modules {
class IModule {
public:
virtual ~IModule() = default;
virtual std::string name() const = 0;
virtual bool init() = 0;
virtual bool start() = 0;
virtual void stop() = 0;
};
}
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include <modules/IModule.hpp>
namespace JuiceAgent::Core::Modules {
class JarLoaderModule : public IModule {
public:
JarLoaderModule() = default;
~JarLoaderModule() override = default;
std::string name() const override {
return "JarLoader";
}
bool init() override;
bool start() override;
void stop() override;
private:
bool _initialized = false;
bool _running = false;
};
}
+10
View File
@@ -4,6 +4,7 @@
#include <event/event_type.hpp>
#include <event/eventbus.hpp>
#include <JuiceAgent/Config.hpp>
#include <modules/Modules.hpp>
namespace JuiceAgent {
// ===== Singleton =====
@@ -40,6 +41,11 @@ namespace JuiceAgent {
set_config(cfg);
PLOGD << "env: " << env << ", jvmti: " << jvmti;
// temporary register modules
// TODO: remove this, implement a better way to register modules
JuiceAgent::Core::Modules::JarLoaderModule jarloader;
jarloader.init();
// PreLoad Event
eventbus.post(EventPreLoad{
@@ -81,6 +87,10 @@ namespace JuiceAgent {
// register bytecodes_opt
JuiceAgent::Bytecodes::register_bytecodes();
// Temporary startup modules
// TODO: remove this, implement a better way to startup modules
jarloader.start();
// Loaded Event
eventbus.post(EventLoaded{
+30
View File
@@ -0,0 +1,30 @@
#include <modules/Modules.hpp>
#include <JuiceAgent/Logger.hpp>
namespace JuiceAgent::Core::Modules {
bool JarLoaderModule::init() {
if (_initialized) return true;
PLOGI << "JarLoader init";
_initialized = true;
return true;
}
bool JarLoaderModule::start() {
if (!_initialized) return false;
if (_running) return true;
PLOGI << "JarLoader start";
_running = true;
return true;
}
void JarLoaderModule::stop() {
if (!_running) return;
PLOGI << "JarLoader stop";
_running = false;
}
}