mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
- introduce EventBus singleton wrapping eventpp::EventDispatcher with typed event ids and const void* payloads - post EventClassFileLoadHook from ClassFileLoadHook callback - add IService base with typed listen<>() helper that binds a member function directly to an event, no virtual onEvent dispatch - add ServiceManager to register, initialize and shutdown services - add BytecodeService that subscribes to ClassFileLoadHook - wire Services::initializeAll() into Agent::init()
47 lines
1.0 KiB
C++
47 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <eventpp/eventdispatcher.h>
|
|
#include <event/event_type.hpp>
|
|
|
|
enum class EventId {
|
|
ClassFileLoadHook,
|
|
MethodEntry,
|
|
MethodExit,
|
|
PreLoad,
|
|
Loaded
|
|
};
|
|
|
|
class EventBus {
|
|
public:
|
|
using Dispatcher = eventpp::EventDispatcher<EventId, void(const void*)>;
|
|
|
|
static EventBus& getInstance() {
|
|
static EventBus instance;
|
|
return instance;
|
|
}
|
|
|
|
EventBus(const EventBus&) = delete;
|
|
EventBus& operator=(const EventBus&) = delete;
|
|
|
|
void post(EventId id, const void* event) {
|
|
dispatcher.dispatch(id, event);
|
|
}
|
|
|
|
template <typename C>
|
|
auto appendListener(EventId id, const C& callback) {
|
|
return dispatcher.appendListener(id, callback);
|
|
}
|
|
|
|
template <typename C>
|
|
auto prependListener(EventId id, const C& callback) {
|
|
return dispatcher.prependListener(id, callback);
|
|
}
|
|
|
|
bool removeListener(EventId id, Dispatcher::Handle handle) {
|
|
return dispatcher.removeListener(id, handle);
|
|
}
|
|
|
|
private:
|
|
EventBus() = default;
|
|
Dispatcher dispatcher;
|
|
}; |