Refactor: auto-register services and inline BytecodeService

- add ServiceRegistry and JUICEAGENT_REGISTER_SERVICE macro so each
  service self-registers at static init; initializeAll() no longer
  includes concrete service headers
- move BytecodeService class entirely into its .cpp (no header needed,
  only accessed via IService)
- split ClassFileLoadHook handling into captureBytecodes and
  patchBytecodes listeners, registered in order
This commit is contained in:
xiaozhou233 committed 2026-08-17 18:54:36 +08:00
1 parent 6962c4a477
commit 8e1b8b38e4
4 files changed
+98 -46

No files matched your search

+37 -20
View File
@@ -1,32 +1,49 @@
#include <services/bytecode_service.hpp>
#include <services/base.hpp>
#include <services/service_manager.hpp>
#include <event/event_type.hpp>
#include <JuiceAgent/Logger.hpp>
namespace JuiceAgent {
namespace Services {
BytecodeService& BytecodeService::getInstance() {
static BytecodeService instance;
return instance;
}
class BytecodeService : public IService {
public:
const char* name() const override { return "BytecodeService"; }
bool BytecodeService::onInitialize() {
listen<BytecodeService, EventClassFileLoadHook>(
EventId::ClassFileLoadHook,
&BytecodeService::onClassFileLoad
);
bool onInitialize() override {
listen<BytecodeService, EventClassFileLoadHook>(
EventId::ClassFileLoadHook,
&BytecodeService::captureBytecodes
);
spdlog::info("[BytecodeService] Initialized");
return true;
}
listen<BytecodeService, EventClassFileLoadHook>(
EventId::ClassFileLoadHook,
&BytecodeService::patchBytecodes
);
void BytecodeService::onShutdown() {
spdlog::info("[BytecodeService] Shutdown");
}
spdlog::info("[BytecodeService] Initialized");
return true;
}
void BytecodeService::onClassFileLoad(const EventClassFileLoadHook& event) {
spdlog::trace("[BytecodeService] ClassFileLoadHook: {}",
event.name ? event.name : "<null>");
}
void onShutdown() override {
spdlog::info("[BytecodeService] Shutdown");
}
private:
void captureBytecodes(const EventClassFileLoadHook& e) {
// TODO: Capture original bytes
spdlog::trace("[BytecodeService] Capture original bytes: {}",
e.name ? e.name : "<null>");
}
void patchBytecodes(const EventClassFileLoadHook& e) {
// TODO: Apply patches
spdlog::trace("[BytecodeService] Apply patches: {}",
e.name ? e.name : "<null>");
}
};
}
}
JUICEAGENT_REGISTER_SERVICE(::JuiceAgent::Services::BytecodeService)