改进api
This commit is contained in:
parent
e9d2d011f1
commit
c990efbd43
|
@ -59,7 +59,7 @@ QList<QString> RtWsEntity::inputTypes() const
|
||||||
{
|
{
|
||||||
QList<QString> types;
|
QList<QString> types;
|
||||||
for (auto c : this->_comps_list) {
|
for (auto c : this->_comps_list) {
|
||||||
for (auto f : c->signatureTypes())
|
for (auto f : c->respondSignatures())
|
||||||
types.append(f.first);
|
types.append(f.first);
|
||||||
}
|
}
|
||||||
return types.toSet().toList();
|
return types.toSet().toList();
|
||||||
|
@ -67,21 +67,22 @@ QList<QString> RtWsEntity::inputTypes() const
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
QList<WsRespondEntry> RtWsEntity::getEntryWithSignature(const WsRespondSignatureType& t) const
|
QList<WsRespondEntry> RtWsEntity::getRespondWithSignature(const WsRespondSignatureType& t) const
|
||||||
{
|
{
|
||||||
QList<WsRespondEntry> list;
|
QList<WsRespondEntry> list;
|
||||||
for (auto c : this->_comps_list)
|
for (auto c : this->_comps_list)
|
||||||
list.append(c->getEntryWithSignature(t));
|
list.append(c->getRespondWithSignature(t));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<WsRespondEntry> RtWsEntity::getEntryWithInType(const QString& msg_type) const
|
QList<WsRespondEntry> RtWsEntity::getRespondWithInType(const QString& msg_type) const
|
||||||
{
|
{
|
||||||
QList<WsRespondEntry> list;
|
QList<WsRespondEntry> list;
|
||||||
for (auto c : this->_comps_list)
|
for (auto c : this->_comps_list)
|
||||||
list.append(c->getEntrysWithInType(msg_type));
|
list.append(c->getRespondWithInType(msg_type));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtWsEntity::recoveryFrom(const QJsonObject& obj)
|
void RtWsEntity::recoveryFrom(const QJsonObject& obj)
|
||||||
{
|
{
|
||||||
this->_entity_id = obj["entity_id"].toVariant().toULongLong();
|
this->_entity_id = obj["entity_id"].toVariant().toULongLong();
|
||||||
|
@ -143,19 +144,19 @@ std::shared_ptr<WsEntity> RtEntityManager::defaultNew() const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<WsRespondEntry> RtEntityManager::getEntryWithSignature(const WsRespondSignatureType& t) const
|
QList<WsRespondEntry> RtEntityManager::getRespondWithSignature(const WsRespondSignatureType& t) const
|
||||||
{
|
{
|
||||||
QList<WsRespondEntry> list;
|
QList<WsRespondEntry> list;
|
||||||
for (auto c : this->_comps_list)
|
for (auto c : this->_comps_list)
|
||||||
list.append(c->getEntryWithSignature(t));
|
list.append(c->getRespondWithSignature(t));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<WsRespondEntry> RtEntityManager::getEntryWithInType(const QString& msg_type) const
|
QList<WsRespondEntry> RtEntityManager::getRespondWithInType(const QString& msg_type) const
|
||||||
{
|
{
|
||||||
QList<WsRespondEntry> list;
|
QList<WsRespondEntry> list;
|
||||||
for (auto c : this->_comps_list)
|
for (auto c : this->_comps_list)
|
||||||
list.append(c->getEntrysWithInType(msg_type));
|
list.append(c->getRespondWithInType(msg_type));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,38 +198,6 @@ QList<std::shared_ptr<WsComponent>> RtEntityManager::components() const
|
||||||
return this->_comps_list.values();
|
return this->_comps_list.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImmediateKernel::ImmediateKernel(std::shared_ptr<WsEntity> bind) :_bind_entity(bind) {}
|
|
||||||
|
|
||||||
uint64_t ImmediateKernel::entityManagerID() const
|
|
||||||
{
|
|
||||||
return RtEntityManager::const_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<std::shared_ptr<WsMessage>> ImmediateKernel::execute(const WsRespondSignatureType& resp_signature, std::shared_ptr<const WsMessage> in)
|
|
||||||
{
|
|
||||||
QList<std::shared_ptr<WsMessage>> rets;
|
|
||||||
auto list = this->_bind_entity->getEntryWithSignature(resp_signature);
|
|
||||||
for (auto func : list) {
|
|
||||||
func(shared_from_this(), in, rets);
|
|
||||||
}
|
|
||||||
return rets;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<std::shared_ptr<WsMessage>> ImmediateKernel::execute(std::shared_ptr<const WsMessage> in)
|
|
||||||
{
|
|
||||||
QList<std::shared_ptr<WsMessage>> 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
|
QString RtResourceManager::templetName() const
|
||||||
{
|
{
|
||||||
return "RtResourceManager";
|
return "RtResourceManager";
|
||||||
|
@ -249,19 +218,19 @@ std::shared_ptr<WsEntity> RtResourceManager::defaultNew() const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<WsRespondEntry> RtResourceManager::getEntryWithSignature(const WsRespondSignatureType& t) const
|
QList<WsRespondEntry> RtResourceManager::getRespondWithSignature(const WsRespondSignatureType& t) const
|
||||||
{
|
{
|
||||||
QList<WsRespondEntry> list;
|
QList<WsRespondEntry> list;
|
||||||
for (auto c : this->_comps_list)
|
for (auto c : this->_comps_list)
|
||||||
list.append(c->getEntryWithSignature(t));
|
list.append(c->getRespondWithSignature(t));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<WsRespondEntry> RtResourceManager::getEntryWithInType(const QString& msg_type) const
|
QList<WsRespondEntry> RtResourceManager::getRespondWithInType(const QString& msg_type) const
|
||||||
{
|
{
|
||||||
QList<WsRespondEntry> list;
|
QList<WsRespondEntry> list;
|
||||||
for (auto c : this->_comps_list)
|
for (auto c : this->_comps_list)
|
||||||
list.append(c->getEntrysWithInType(msg_type));
|
list.append(c->getRespondWithInType(msg_type));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,13 +80,13 @@ public:
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="t">签名</param>
|
/// <param name="t">签名</param>
|
||||||
/// <returns>处理接口</returns>
|
/// <returns>处理接口</returns>
|
||||||
virtual QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const;
|
virtual QList<WsRespondEntry> getRespondWithSignature(const WsRespondSignatureType& t) const;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过输入消息类型获取处理入口
|
/// 通过输入消息类型获取处理入口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="msg_type">输入消息类型</param>
|
/// <param name="msg_type">输入消息类型</param>
|
||||||
/// <returns>处理接口列表</returns>
|
/// <returns>处理接口列表</returns>
|
||||||
virtual QList<WsRespondEntry> getEntryWithInType(const QString& msg_type) const;
|
virtual QList<WsRespondEntry> getRespondWithInType(const QString& msg_type) const override;
|
||||||
|
|
||||||
// 通过 Serializable 继承
|
// 通过 Serializable 继承
|
||||||
void recoveryFrom(const QJsonObject& obj) override;
|
void recoveryFrom(const QJsonObject& obj) override;
|
||||||
|
@ -111,8 +111,8 @@ public:
|
||||||
QList<std::shared_ptr<WsComponent>> components() const override;
|
QList<std::shared_ptr<WsComponent>> components() const override;
|
||||||
|
|
||||||
std::shared_ptr<WsEntity> defaultNew() const override;
|
std::shared_ptr<WsEntity> defaultNew() const override;
|
||||||
QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const override;
|
QList<WsRespondEntry> getRespondWithSignature(const WsRespondSignatureType& t) const override;
|
||||||
QList<WsRespondEntry> getEntryWithInType(const QString& msg_type) const override;
|
QList<WsRespondEntry> getRespondWithInType(const QString& msg_type) const override;
|
||||||
|
|
||||||
void recoveryFrom(const QJsonObject& obj) override;
|
void recoveryFrom(const QJsonObject& obj) override;
|
||||||
void saveTo(QJsonObject& obj) const override;
|
void saveTo(QJsonObject& obj) const override;
|
||||||
|
@ -130,8 +130,8 @@ public:
|
||||||
QString name() const override;
|
QString name() const override;
|
||||||
|
|
||||||
std::shared_ptr<WsEntity> defaultNew() const override;
|
std::shared_ptr<WsEntity> defaultNew() const override;
|
||||||
QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const override;
|
QList<WsRespondEntry> getRespondWithSignature(const WsRespondSignatureType& t) const override;
|
||||||
QList<WsRespondEntry> getEntryWithInType(const QString& msg_type) const override;
|
QList<WsRespondEntry> getRespondWithInType(const QString& msg_type) const override;
|
||||||
|
|
||||||
void recoveryFrom(const QJsonObject& obj) override;
|
void recoveryFrom(const QJsonObject& obj) override;
|
||||||
void saveTo(QJsonObject& obj) const override;
|
void saveTo(QJsonObject& obj) const override;
|
||||||
|
@ -141,34 +141,3 @@ public:
|
||||||
QList<std::shared_ptr<WsComponent>> components() const override;
|
QList<std::shared_ptr<WsComponent>> components() const override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 实体内迅捷调用核心
|
|
||||||
/// </summary>
|
|
||||||
class SIMSBASIC_EXPORT ImmediateKernel : public Immediate,
|
|
||||||
public std::enable_shared_from_this<ImmediateKernel> {
|
|
||||||
private:
|
|
||||||
std::shared_ptr<WsEntity> _bind_entity = nullptr;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ImmediateKernel(std::shared_ptr<WsEntity> bind);
|
|
||||||
/// <summary>
|
|
||||||
/// 获取实体管理器id
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
virtual uint64_t entityManagerID() const override;
|
|
||||||
|
|
||||||
virtual uint64_t resourceManagerID() const override;
|
|
||||||
/// <summary>
|
|
||||||
/// 实体内指定类型的调用立即执行
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="in"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
virtual QList<std::shared_ptr<WsMessage>> execute(const WsRespondSignatureType& resp_signature, std::shared_ptr<const WsMessage> in) override;
|
|
||||||
/// <summary>
|
|
||||||
/// 实体内兼容调用立即执行
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="in"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
virtual QList<std::shared_ptr<WsMessage>> execute(std::shared_ptr<const WsMessage> in) override;
|
|
||||||
};
|
|
|
@ -74,53 +74,14 @@ public:
|
||||||
/// Respond签名类型
|
/// Respond签名类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
using WsRespondSignatureType = std::pair<QString, QString>;
|
using WsRespondSignatureType = std::pair<QString, QString>;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 实体内立即执行入口
|
/// Request签名类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class Immediate {
|
using WsRequestSignatureType = std::pair<QString, QString>;
|
||||||
public:
|
|
||||||
virtual ~Immediate() = default;
|
|
||||||
/// <summary>
|
|
||||||
/// 获取实体管理器id
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
virtual uint64_t entityManagerID() const = 0;
|
|
||||||
/// <summary>
|
|
||||||
/// 获取资源管理器id
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
virtual uint64_t resourceManagerID() const = 0;
|
|
||||||
/// <summary>
|
|
||||||
/// 实体内指定类型的调用立即执行
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="in"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
virtual QList<std::shared_ptr<WsMessage>> execute(const WsRespondSignatureType& resp_signature, std::shared_ptr<const WsMessage> in) = 0;
|
|
||||||
|
|
||||||
template<typename TypeIn, typename TypeOut>
|
|
||||||
QList<std::shared_ptr<TypeOut>> execute(std::shared_ptr<const WsMessage> in) {
|
|
||||||
auto sign = std::make_pair<QString, QString>(TypeIn().topicString(), TypeOut().topicString());
|
|
||||||
auto rest_list = this->execute(sign, in);
|
|
||||||
|
|
||||||
QList<std::shared_ptr<TypeOut>> typed_list;
|
|
||||||
for (auto it : rest_list) {
|
|
||||||
typed_list << std::static_pointer_cast<TypeOut>(it);
|
|
||||||
}
|
|
||||||
return typed_list;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 实体内兼容调用立即执行
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="in"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
virtual QList<std::shared_ptr<WsMessage>> execute(std::shared_ptr<const WsMessage> in) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 所有消息处理单元通用接口
|
/// 所有消息处理单元通用接口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
using WsRespondEntry = std::function<void(std::shared_ptr<Immediate> map, std::shared_ptr<const WsMessage>, QList<std::shared_ptr<WsMessage>>&)>;
|
using WsRespondEntry = std::function<void(std::shared_ptr<const WsMessage>, QList<std::shared_ptr<WsMessage>>&)>;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 实体抽象接口
|
/// 实体抽象接口
|
||||||
|
@ -153,17 +114,17 @@ public:
|
||||||
virtual std::shared_ptr<WsEntity> defaultNew() const = 0;
|
virtual std::shared_ptr<WsEntity> defaultNew() const = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过指定的签名获取处理入口
|
/// 通过指定的签名获取消息响应处理入口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="t">签名</param>
|
/// <param name="t">签名</param>
|
||||||
/// <returns>处理接口</returns>
|
/// <returns>处理接口</returns>
|
||||||
virtual QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const = 0;
|
virtual QList<WsRespondEntry> getRespondWithSignature(const WsRespondSignatureType& t) const = 0;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过输入消息类型获取处理入口
|
/// 通过输入消息类型获取处理入口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="msg_type">输入消息类型</param>
|
/// <param name="msg_type">输入消息类型</param>
|
||||||
/// <returns>处理接口列表</returns>
|
/// <returns>处理接口列表</returns>
|
||||||
virtual QList<WsRespondEntry> getEntryWithInType(const QString& msg_type) const = 0;
|
virtual QList<WsRespondEntry> getRespondWithInType(const QString& msg_type) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -173,6 +134,12 @@ class WsComponent : public Serializable, public std::enable_shared_from_this<WsC
|
||||||
public:
|
public:
|
||||||
virtual ~WsComponent() = default;
|
virtual ~WsComponent() = default;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 插件唯一命名
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>插件名</returns>
|
||||||
|
virtual QString name() const = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 克隆一个具有相同数据的实例
|
/// 克隆一个具有相同数据的实例
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -185,28 +152,28 @@ public:
|
||||||
virtual void bindEntity(std::weak_ptr<WsEntity> host) = 0;
|
virtual void bindEntity(std::weak_ptr<WsEntity> host) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 插件唯一命名
|
/// 允许发送的消息类型签名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>插件名</returns>
|
/// <returns></returns>
|
||||||
virtual QString name() const = 0;
|
virtual QList<WsRequestSignatureType> requestSignatures() const = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 允许处理的消息签名类型
|
/// 允许响应处理的消息签名类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>消息签名类型集合</returns>
|
/// <returns>消息签名类型集合</returns>
|
||||||
virtual QList<WsRespondSignatureType> signatureTypes() const = 0;
|
virtual QList<WsRespondSignatureType> respondSignatures() const = 0;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过指定的签名获取处理入口
|
/// 通过指定的签名获取消息响应处理入口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="t">处理签名</param>
|
/// <param name="t">处理签名</param>
|
||||||
/// <returns>处理接口</returns>
|
/// <returns>处理接口</returns>
|
||||||
virtual QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const = 0;
|
virtual QList<WsRespondEntry> getRespondWithSignature(const WsRespondSignatureType& t) const = 0;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过输入消息类型获取处理入口
|
/// 通过输入消息类型获取处理入口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="msg_type">输入消息类型</param>
|
/// <param name="msg_type">输入消息类型</param>
|
||||||
/// <returns>处理接口列表</returns>
|
/// <returns>处理接口列表</returns>
|
||||||
virtual QList<WsRespondEntry> getEntrysWithInType(const QString& msg_type) const = 0;
|
virtual QList<WsRespondEntry> getRespondWithInType(const QString& msg_type) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue