diff --git a/SimsBasic/internal_impl.cpp b/SimsBasic/internal_impl.cpp index da916b1..cb09768 100644 --- a/SimsBasic/internal_impl.cpp +++ b/SimsBasic/internal_impl.cpp @@ -59,7 +59,7 @@ QList RtWsEntity::inputTypes() const { QList types; for (auto c : this->_comps_list) { - for (auto f : c->signatureTypes()) + for (auto f : c->respondSignatures()) types.append(f.first); } return types.toSet().toList(); @@ -67,21 +67,22 @@ QList RtWsEntity::inputTypes() const #include #include -QList RtWsEntity::getEntryWithSignature(const WsRespondSignatureType& t) const +QList RtWsEntity::getRespondWithSignature(const WsRespondSignatureType& t) const { QList list; for (auto c : this->_comps_list) - list.append(c->getEntryWithSignature(t)); + list.append(c->getRespondWithSignature(t)); return list; } -QList RtWsEntity::getEntryWithInType(const QString& msg_type) const +QList RtWsEntity::getRespondWithInType(const QString& msg_type) const { QList list; for (auto c : this->_comps_list) - list.append(c->getEntrysWithInType(msg_type)); + list.append(c->getRespondWithInType(msg_type)); return list; } + void RtWsEntity::recoveryFrom(const QJsonObject& obj) { this->_entity_id = obj["entity_id"].toVariant().toULongLong(); @@ -143,19 +144,19 @@ std::shared_ptr RtEntityManager::defaultNew() const return nullptr; } -QList RtEntityManager::getEntryWithSignature(const WsRespondSignatureType& t) const +QList RtEntityManager::getRespondWithSignature(const WsRespondSignatureType& t) const { QList list; for (auto c : this->_comps_list) - list.append(c->getEntryWithSignature(t)); + list.append(c->getRespondWithSignature(t)); return list; } -QList RtEntityManager::getEntryWithInType(const QString& msg_type) const +QList RtEntityManager::getRespondWithInType(const QString& msg_type) const { QList list; for (auto c : this->_comps_list) - list.append(c->getEntrysWithInType(msg_type)); + list.append(c->getRespondWithInType(msg_type)); return list; } @@ -197,38 +198,6 @@ QList> RtEntityManager::components() const return this->_comps_list.values(); } -ImmediateKernel::ImmediateKernel(std::shared_ptr bind) :_bind_entity(bind) {} - -uint64_t ImmediateKernel::entityManagerID() const -{ - return RtEntityManager::const_id; -} - -QList> ImmediateKernel::execute(const WsRespondSignatureType& resp_signature, std::shared_ptr in) -{ - QList> rets; - auto list = this->_bind_entity->getEntryWithSignature(resp_signature); - for (auto func : list) { - func(shared_from_this(), in, rets); - } - return rets; -} - -QList> ImmediateKernel::execute(std::shared_ptr in) -{ - QList> rets; - auto list = this->_bind_entity->getEntryWithInType(in->topicString()); - for (auto func : list) { - func(shared_from_this(), in, rets); - } - return rets; -} - -uint64_t ImmediateKernel::resourceManagerID() const -{ - return RtResourceManager::const_id; -} - QString RtResourceManager::templetName() const { return "RtResourceManager"; @@ -249,19 +218,19 @@ std::shared_ptr RtResourceManager::defaultNew() const return nullptr; } -QList RtResourceManager::getEntryWithSignature(const WsRespondSignatureType& t) const +QList RtResourceManager::getRespondWithSignature(const WsRespondSignatureType& t) const { QList list; for (auto c : this->_comps_list) - list.append(c->getEntryWithSignature(t)); + list.append(c->getRespondWithSignature(t)); return list; } -QList RtResourceManager::getEntryWithInType(const QString& msg_type) const +QList RtResourceManager::getRespondWithInType(const QString& msg_type) const { QList list; for (auto c : this->_comps_list) - list.append(c->getEntrysWithInType(msg_type)); + list.append(c->getRespondWithInType(msg_type)); return list; } diff --git a/SimsBasic/internal_impl.h b/SimsBasic/internal_impl.h index 740e88a..b245abd 100644 --- a/SimsBasic/internal_impl.h +++ b/SimsBasic/internal_impl.h @@ -80,14 +80,14 @@ public: /// /// 签名 /// 处理接口 - virtual QList getEntryWithSignature(const WsRespondSignatureType& t) const; + virtual QList getRespondWithSignature(const WsRespondSignatureType& t) const; /// /// 通过输入消息类型获取处理入口 /// /// 输入消息类型 /// 处理接口列表 - virtual QList getEntryWithInType(const QString& msg_type) const; - + virtual QList getRespondWithInType(const QString& msg_type) const override; + // 通过 Serializable 继承 void recoveryFrom(const QJsonObject& obj) override; void saveTo(QJsonObject& obj) const override; @@ -111,8 +111,8 @@ public: QList> components() const override; std::shared_ptr defaultNew() const override; - QList getEntryWithSignature(const WsRespondSignatureType& t) const override; - QList getEntryWithInType(const QString& msg_type) const override; + QList getRespondWithSignature(const WsRespondSignatureType& t) const override; + QList getRespondWithInType(const QString& msg_type) const override; void recoveryFrom(const QJsonObject& obj) override; void saveTo(QJsonObject& obj) const override; @@ -130,8 +130,8 @@ public: QString name() const override; std::shared_ptr defaultNew() const override; - QList getEntryWithSignature(const WsRespondSignatureType& t) const override; - QList getEntryWithInType(const QString& msg_type) const override; + QList getRespondWithSignature(const WsRespondSignatureType& t) const override; + QList getRespondWithInType(const QString& msg_type) const override; void recoveryFrom(const QJsonObject& obj) override; void saveTo(QJsonObject& obj) const override; @@ -141,34 +141,3 @@ public: QList> components() const override; }; - -/// -/// 实体内迅捷调用核心 -/// -class SIMSBASIC_EXPORT ImmediateKernel : public Immediate, - public std::enable_shared_from_this { -private: - std::shared_ptr _bind_entity = nullptr; - -public: - ImmediateKernel(std::shared_ptr bind); - /// - /// 获取实体管理器id - /// - /// - virtual uint64_t entityManagerID() const override; - - virtual uint64_t resourceManagerID() const override; - /// - /// 实体内指定类型的调用立即执行 - /// - /// - /// - virtual QList> execute(const WsRespondSignatureType& resp_signature, std::shared_ptr in) override; - /// - /// 实体内兼容调用立即执行 - /// - /// - /// - virtual QList> execute(std::shared_ptr in) override; -}; \ No newline at end of file diff --git a/SimsBasic/simsbasic.h b/SimsBasic/simsbasic.h index 14042dd..7e3ccda 100644 --- a/SimsBasic/simsbasic.h +++ b/SimsBasic/simsbasic.h @@ -74,53 +74,14 @@ public: /// Respond签名类型 /// using WsRespondSignatureType = std::pair; - /// -/// 实体内立即执行入口 +/// Request签名类型 /// -class Immediate { -public: - virtual ~Immediate() = default; - /// - /// 获取实体管理器id - /// - /// - virtual uint64_t entityManagerID() const = 0; - /// - /// 获取资源管理器id - /// - /// - virtual uint64_t resourceManagerID() const = 0; - /// - /// 实体内指定类型的调用立即执行 - /// - /// - /// - virtual QList> execute(const WsRespondSignatureType& resp_signature, std::shared_ptr in) = 0; - - template - QList> execute(std::shared_ptr in) { - auto sign = std::make_pair(TypeIn().topicString(), TypeOut().topicString()); - auto rest_list = this->execute(sign, in); - - QList> typed_list; - for (auto it : rest_list) { - typed_list << std::static_pointer_cast(it); - } - return typed_list; - } - /// - /// 实体内兼容调用立即执行 - /// - /// - /// - virtual QList> execute(std::shared_ptr in) = 0; -}; - +using WsRequestSignatureType = std::pair; /// /// 所有消息处理单元通用接口 /// -using WsRespondEntry = std::function map, std::shared_ptr, QList>&)>; +using WsRespondEntry = std::function, QList>&)>; /// /// 实体抽象接口 @@ -153,17 +114,17 @@ public: virtual std::shared_ptr defaultNew() const = 0; /// - /// 通过指定的签名获取处理入口 + /// 通过指定的签名获取消息响应处理入口 /// /// 签名 /// 处理接口 - virtual QList getEntryWithSignature(const WsRespondSignatureType& t) const = 0; + virtual QList getRespondWithSignature(const WsRespondSignatureType& t) const = 0; /// /// 通过输入消息类型获取处理入口 /// /// 输入消息类型 /// 处理接口列表 - virtual QList getEntryWithInType(const QString& msg_type) const = 0; + virtual QList getRespondWithInType(const QString& msg_type) const = 0; }; /// @@ -173,6 +134,12 @@ class WsComponent : public Serializable, public std::enable_shared_from_this + /// 插件唯一命名 + /// + /// 插件名 + virtual QString name() const = 0; + /// /// 克隆一个具有相同数据的实例 /// @@ -183,30 +150,30 @@ public: /// /// 实体实例 virtual void bindEntity(std::weak_ptr host) = 0; - + /// - /// 插件唯一命名 + /// 允许发送的消息类型签名 /// - /// 插件名 - virtual QString name() const = 0; + /// + virtual QList requestSignatures() const = 0; /// - /// 允许处理的消息签名类型 + /// 允许响应处理的消息签名类型 /// /// 消息签名类型集合 - virtual QList signatureTypes() const = 0; + virtual QList respondSignatures() const = 0; /// - /// 通过指定的签名获取处理入口 + /// 通过指定的签名获取消息响应处理入口 /// /// 处理签名 /// 处理接口 - virtual QList getEntryWithSignature(const WsRespondSignatureType& t) const = 0; + virtual QList getRespondWithSignature(const WsRespondSignatureType& t) const = 0; /// /// 通过输入消息类型获取处理入口 /// /// 输入消息类型 /// 处理接口列表 - virtual QList getEntrysWithInType(const QString& msg_type) const = 0; + virtual QList getRespondWithInType(const QString& msg_type) const = 0; }; ///