#pragma once #include "simsbasic_global.h" #include #include #include /// /// 所有异常基类 /// class SIMSBASIC_EXPORT UniException { private: QString _error_store; public: explicit UniException(const QString& msg); virtual ~UniException() = default; virtual QString content() const noexcept; }; // ======================================================= /// /// 可序列化对象 /// class Serializable { public: /// /// /// 提取包含默认值的实例 /// /// virtual std::shared_ptr newDefault() const = 0; /// 通过反序列化完全恢复数据 /// /// 数据Json virtual void recoveryFrom(const QJsonObject& obj) = 0; /// /// 通过序列化输出所有数据 /// /// 目标Json virtual void saveTo(QJsonObject& obj) const = 0; }; /// /// 命名类型数据 /// class TopicData : public Serializable { public: /// /// 获取消息类型字符串 /// /// 消息类型 virtual QString topicString() const = 0; }; /// /// 通用消息基类 /// class WsMessage : public TopicData { public: virtual ~WsMessage() = default; /// /// 目标实体ID /// /// ID virtual uint64_t targetEntity() const = 0; /// /// 来源实体ID /// /// ID virtual uint64_t sourceEntity() const = 0; }; // ================================================================ /// /// Respond签名类型 /// using WsRespondSignatureType = std::pair; /// /// Request签名类型 /// using WsRequestSignatureType = std::pair; /// /// 所有消息处理单元通用接口 /// using WsRespondEntry = std::function, QList>&)>; /// /// 对外开放地址表 /// struct PublicTable { /// /// 实体管理器地址 /// /// static uint64_t entityManagerAddress(); /// /// 资源管理器地址 /// /// static uint64_t resourceManagerAddress(); }; /// /// 实体抽象接口 /// class WsEntity : public Serializable { public: virtual ~WsEntity() = default; /// /// 获取本实例的模板名 /// /// 模板名称 virtual QString templetName() const = 0; /// /// 获取本实例的运行ID /// /// virtual uint64_t entityID() const = 0; /// /// 获取本实例的运行名称 /// /// 运行名称 virtual QString name() const = 0; /// /// 通过指定的签名获取消息响应处理入口 /// /// 签名 /// 处理接口 virtual QList getRespondWithSignature(const WsRespondSignatureType& t) const = 0; /// /// 通过输入消息类型获取处理入口 /// /// 输入消息类型 /// 处理接口列表 virtual QList getRespondWithInType(const QString& msg_type) const = 0; }; /// /// 功能插件的基类 /// class WsComponent : public Serializable, public std::enable_shared_from_this { public: /// /// 插件唯一命名 /// /// 插件名 virtual QString name() const = 0; /// /// 绑定Entity /// /// 实体实例 virtual void bindEntity(std::weak_ptr host) = 0; /// /// 允许响应处理的消息签名类型 /// /// 消息签名类型集合 virtual QList respondSignatures() const = 0; /// /// 通过指定的签名获取消息响应处理入口 /// /// 处理签名 /// 处理接口 virtual QList getRespondWithSignature(const WsRespondSignatureType& t) const = 0; /// /// 通过输入消息类型获取处理入口 /// /// 输入消息类型 /// 处理接口列表 virtual QList getRespondWithInType(const QString& msg_type) const = 0; }; /// /// 组件管理接口 /// class ComponentSet { public: /// /// 为本实例添加指定类型的插件 /// /// virtual void append(std::shared_ptr ins) = 0; /// /// 移除指定类型的插件实例 /// /// virtual void remove(const QString& component_type) = 0; /// /// 获取本实例内包含的所有插件实例 /// /// virtual QList> components() const = 0; }; /// /// 批量处理单元通用接口 /// using WsBatchRespondEntry = std::function>&, const QList>&, QList>&)>; /// /// 批量处理拓展 /// class WsBatchComponent : public Serializable, public std::enable_shared_from_this{ public: /// /// 插件唯一命名 /// /// 插件名 virtual QString name() const = 0; /// /// 允许响应处理的消息签名类型 /// /// 消息签名类型集合 virtual QList respondSignatures() const = 0; /// /// 通过输入消息类型获取处理入口 /// /// 输入消息类型 /// 处理接口列表 virtual QList getRespondWithInType(const QString& msg_type) const = 0; };