mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 21:15:56 +08:00
Feat: Simple module system
This commit is contained in:
1 parent
e7ce54188b
commit
6858a35754
4 files changed
+82
No files matched your search
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user