80 lines
2.4 KiB
C++
Executable File
80 lines
2.4 KiB
C++
Executable File
#pragma once
|
||
#include "XNBaseFrameObject.h"
|
||
#include <QVariant>
|
||
// 事件优先级定义
|
||
namespace XNEvent
|
||
{
|
||
enum class Priority {
|
||
RealTime = 0, // 实时优先级
|
||
High = 1, // 高优先级
|
||
Normal = 2, // 普通优先级
|
||
Low = 3 // 低优先级
|
||
};
|
||
}
|
||
// 前向声明私有类
|
||
class XNEventManagerPrivate;
|
||
|
||
// 事件管理器类,继承自XNBaseFrameObject
|
||
class XNEventManager : public XNBaseFrameObject
|
||
{
|
||
Q_OBJECT // 启用Qt的元对象系统
|
||
Q_DECLARE_PRIVATE(XNEventManager) // 声明私有实现类
|
||
Q_DISABLE_COPY(XNEventManager) // 禁用拷贝构造和赋值操作
|
||
|
||
public :
|
||
// 构造函数,创建事件管理器实例
|
||
explicit XNEventManager(QObject *parent = nullptr);
|
||
// 析构函数
|
||
~XNEventManager();
|
||
|
||
// 注册事件处理器
|
||
// @param eventName: 事件名称
|
||
// @param callback: 事件处理回调函数
|
||
// @param objectId: 对象ID
|
||
// @param async: 是否异步处理该事件
|
||
// @param priority: 事件优先级
|
||
// @return: 返回处理器ID,失败返回-1
|
||
int RegisterEventHandler(const QString &eventName,
|
||
std::function<void(const QVariant &)> callback, quint32 objectId,
|
||
bool async = false,
|
||
XNEvent::Priority priority = XNEvent::Priority::Normal);
|
||
// 移除事件处理器
|
||
// @param eventName: 事件名称
|
||
// @param handlerId: 处理器ID
|
||
// @return: 移除是否成功
|
||
bool RemoveEventHandler(const QString &eventName, int handlerId);
|
||
// 触发指定事件
|
||
// @param eventName: 要触发的事件名称
|
||
// @param eventData: 事件携带的数据
|
||
// @param forceAsync: 强制异步处理
|
||
// @param priority: 事件优先级
|
||
void TriggerEvent(const QString &eventName, const QVariant &eventData = QVariant(),
|
||
bool forceAsync = false,
|
||
XNEvent::Priority priority = XNEvent::Priority::Normal);
|
||
|
||
// 设置线程池最大线程数
|
||
void SetMaxThreadCount(int count);
|
||
|
||
// 获取线程池最大线程数
|
||
int GetMaxThreadCount() const;
|
||
|
||
// 等待所有异步事件处理完成
|
||
void WaitForAsyncEvents();
|
||
|
||
// 设置实时线程池参数
|
||
void SetRTThreadPoolConfig(int maxThreads, int minPriority, int maxPriority);
|
||
|
||
protected:
|
||
// 保护构造函数,用于继承实现
|
||
XNEventManager(XNEventManagerPrivate &dd, QObject *parent = nullptr);
|
||
|
||
public slots:
|
||
// 初始化事件管理器
|
||
virtual void OnInitialize() override;
|
||
// 准备执行
|
||
virtual void OnPrepareForExecute() override;
|
||
|
||
signals:
|
||
// 事件处理完成信号
|
||
void EventProcessed(const QString &eventName, bool success);
|
||
}; |