Files
JuiceAgent/src/libagent/includes/eventbus.hpp
T
xiaozhou233 6962c4a477 Feat: add event bus and service framework
- 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()
2026-08-17 15:45:39 +08:00

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;
};