update
This commit is contained in:
parent
10b5bb706a
commit
b8f071b935
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <simsbasic.h>
|
#include <internal_impl.h>
|
||||||
#include <messagebasic.h>
|
#include <messagebasic.h>
|
||||||
#include "componentbasic.h"
|
#include "componentbasic.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "componentbasic_global.h"
|
#include "componentbasic_global.h"
|
||||||
#include <simsbasic.h>
|
#include <simsbasic.h>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 消息处理单元基类
|
/// 消息处理单元基类
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include "messagebasic_global.h"
|
#include "messagebasic_global.h"
|
||||||
#include <simsbasic.h>
|
#include <simsbasic.h>
|
||||||
#include <standardglobe.h>
|
#include <standardglobe.h>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
#define NAME(v) #v
|
#define NAME(v) #v
|
||||||
#define DOUBLE_SAVE(u) obj[NAME(u)] = u
|
#define DOUBLE_SAVE(u) obj[NAME(u)] = u
|
||||||
|
|
|
@ -96,7 +96,9 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="simsbasic_global.h" />
|
<ClInclude Include="simsbasic_global.h" />
|
||||||
<ClInclude Include="simsbasic.h" />
|
<ClInclude Include="simsbasic.h" />
|
||||||
|
<ClCompile Include="internal_impl.cpp" />
|
||||||
<ClCompile Include="simsbasic.cpp" />
|
<ClCompile Include="simsbasic.cpp" />
|
||||||
|
<ClInclude Include="internal_impl.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
|
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
|
||||||
|
|
|
@ -32,5 +32,13 @@
|
||||||
<ClInclude Include="simsbasic.h">
|
<ClInclude Include="simsbasic.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="internal_impl.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="internal_impl.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -0,0 +1,222 @@
|
||||||
|
#include "internal_impl.h"
|
||||||
|
|
||||||
|
|
||||||
|
RtWsEntity::RtWsEntity() {}
|
||||||
|
|
||||||
|
void RtWsEntity::resetTemplet(const QString& name) {
|
||||||
|
this->_templet_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RtWsEntity::templetName() const {
|
||||||
|
return this->_templet_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtWsEntity::resetID(uint64_t id) {
|
||||||
|
this->_entity_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t RtWsEntity::entityID() const {
|
||||||
|
return this->_entity_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtWsEntity::resetName(const QString& name) {
|
||||||
|
this->_runtime_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RtWsEntity::name() const {
|
||||||
|
return this->_runtime_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtWsEntity::append(std::shared_ptr<WsComponent> ins) {
|
||||||
|
if (this->_comps_list.contains(ins->name()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ins->bindEntity(this->shared_from_this());
|
||||||
|
this->_comps_list[ins->name()] = ins;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtWsEntity::remove(const QString& component_type) {
|
||||||
|
this->_comps_list.remove(component_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<std::shared_ptr<WsComponent>> RtWsEntity::components() const {
|
||||||
|
return _comps_list.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<WsEntity> RtWsEntity::defaultNew() const {
|
||||||
|
auto newx = std::make_shared<RtWsEntity>();
|
||||||
|
newx->_entity_id = this->_entity_id;
|
||||||
|
newx->_templet_name = this->_templet_name;
|
||||||
|
newx->_runtime_name = this->_runtime_name;
|
||||||
|
|
||||||
|
for (auto c : this->_comps_list)
|
||||||
|
newx->append(c->defaultNew());
|
||||||
|
return newx;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <QSet>
|
||||||
|
QList<QString> RtWsEntity::inputTypes() const
|
||||||
|
{
|
||||||
|
QList<QString> types;
|
||||||
|
for (auto c : this->_comps_list)
|
||||||
|
types.append(c->inputTypes());
|
||||||
|
return types.toSet().toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QJsonArray>
|
||||||
|
QList<WsRespondEntry> RtWsEntity::getEntryWithSignature(const WsRespondSignatureType& t) const
|
||||||
|
{
|
||||||
|
QList<WsRespondEntry> list;
|
||||||
|
for (auto c : this->_comps_list)
|
||||||
|
list.append(c->getEntryWithSignature(t));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<WsRespondEntry> RtWsEntity::getEntryWithInType(const QString& msg_type) const
|
||||||
|
{
|
||||||
|
QList<WsRespondEntry> list;
|
||||||
|
for (auto c : this->_comps_list)
|
||||||
|
list.append(c->getEntrysWithInType(msg_type));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
void RtWsEntity::recoveryFrom(const QJsonObject& obj)
|
||||||
|
{
|
||||||
|
this->_entity_id = obj["entity_id"].toVariant().toULongLong();
|
||||||
|
this->_runtime_name = obj["entity_name"].toString();
|
||||||
|
this->_templet_name = obj["entity_templet"].toString();
|
||||||
|
|
||||||
|
auto array = obj["component_array"].toArray();
|
||||||
|
for (auto idx = 0; idx < array.size(); ++idx) {
|
||||||
|
auto value = array.at(idx).toObject();
|
||||||
|
auto type = value["component_type"].toString();
|
||||||
|
|
||||||
|
auto compins = this->_comps_list[type];
|
||||||
|
if (!compins)
|
||||||
|
throw new UniException(type + "类型插件不存在!");
|
||||||
|
|
||||||
|
compins->recoveryFrom(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtWsEntity::saveTo(QJsonObject& obj) const
|
||||||
|
{
|
||||||
|
obj["entity_id"] = QJsonValue::fromVariant(QVariant::fromValue(this->_entity_id));
|
||||||
|
obj["entity_name"] = this->_runtime_name;
|
||||||
|
obj["entity_templet"] = this->_templet_name;
|
||||||
|
|
||||||
|
QJsonArray array;
|
||||||
|
for (auto c : this->_comps_list)
|
||||||
|
{
|
||||||
|
QJsonObject comp_obj;
|
||||||
|
comp_obj["component_type"] = c->name();
|
||||||
|
c->saveTo(comp_obj);
|
||||||
|
array.append(comp_obj);
|
||||||
|
}
|
||||||
|
obj["component_array"] = array;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RtEntityManager::templetName() const
|
||||||
|
{
|
||||||
|
return "实体管理器";
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t RtEntityManager::entityID() const
|
||||||
|
{
|
||||||
|
return const_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RtEntityManager::name() const
|
||||||
|
{
|
||||||
|
return "实体管理器唯一实例";
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtEntityManager::append(std::shared_ptr<WsComponent> ins) {
|
||||||
|
_comps_list[ins->name()] = ins;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<WsEntity> RtEntityManager::defaultNew() const
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<WsRespondEntry> RtEntityManager::getEntryWithSignature(const WsRespondSignatureType& t) const
|
||||||
|
{
|
||||||
|
QList<WsRespondEntry> list;
|
||||||
|
for (auto c : this->_comps_list)
|
||||||
|
list.append(c->getEntryWithSignature(t));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<WsRespondEntry> RtEntityManager::getEntryWithInType(const QString& msg_type) const
|
||||||
|
{
|
||||||
|
QList<WsRespondEntry> list;
|
||||||
|
for (auto c : this->_comps_list)
|
||||||
|
list.append(c->getEntrysWithInType(msg_type));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtEntityManager::recoveryFrom(const QJsonObject& obj)
|
||||||
|
{
|
||||||
|
auto array = obj["component_array"].toArray();
|
||||||
|
for (auto idx = 0; idx < array.size(); ++idx) {
|
||||||
|
auto value = array.at(idx).toObject();
|
||||||
|
auto type = value["component_type"].toString();
|
||||||
|
|
||||||
|
auto compins = this->_comps_list[type];
|
||||||
|
if (!compins)
|
||||||
|
throw new UniException(type + "类型插件不存在!");
|
||||||
|
|
||||||
|
compins->recoveryFrom(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtEntityManager::saveTo(QJsonObject& obj) const
|
||||||
|
{
|
||||||
|
QJsonArray array;
|
||||||
|
for (auto c : this->_comps_list)
|
||||||
|
{
|
||||||
|
QJsonObject comp_obj;
|
||||||
|
comp_obj["component_type"] = c->name();
|
||||||
|
c->saveTo(comp_obj);
|
||||||
|
array.append(comp_obj);
|
||||||
|
}
|
||||||
|
obj["component_array"] = array;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtEntityManager::remove(const QString& component_type)
|
||||||
|
{
|
||||||
|
this->_comps_list.remove(component_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<std::shared_ptr<WsComponent>> RtEntityManager::components() const
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
|
@ -0,0 +1,149 @@
|
||||||
|
#pragma once
|
||||||
|
#include "simsbasic.h"
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 内存实体实例类型
|
||||||
|
/// </summary>
|
||||||
|
class SIMSBASIC_EXPORT RtWsEntity : public WsEntity, public ComponentSet, public std::enable_shared_from_this<RtWsEntity> {
|
||||||
|
private:
|
||||||
|
uint64_t _entity_id = 0;
|
||||||
|
QString _templet_name, _runtime_name;
|
||||||
|
QHash<QString, std::shared_ptr<WsComponent>> _comps_list;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit RtWsEntity();
|
||||||
|
virtual ~RtWsEntity() = default;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重置本实例模板名
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">模板名称</param>
|
||||||
|
virtual void resetTemplet(const QString& name);
|
||||||
|
/// <summary>
|
||||||
|
/// 获取本实例的模板名
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>模板名称</returns>
|
||||||
|
virtual QString templetName() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重置本实例的运行ID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
virtual void resetID(uint64_t id);
|
||||||
|
/// <summary>
|
||||||
|
/// 获取本实例的运行ID
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
virtual uint64_t entityID() const;
|
||||||
|
/// <summary>
|
||||||
|
/// 重置本实例的运行名称
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
virtual void resetName(const QString& name);
|
||||||
|
/// <summary>
|
||||||
|
/// 获取本实例的运行名称
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>运行名称</returns>
|
||||||
|
virtual QString name() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 为本实例添加指定类型的插件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ins"></param>
|
||||||
|
virtual void append(std::shared_ptr<WsComponent> ins) override;
|
||||||
|
/// <summary>
|
||||||
|
/// 移除指定类型的插件实例
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="component_type"></param>
|
||||||
|
virtual void remove(const QString& component_type) override;
|
||||||
|
/// <summary>
|
||||||
|
/// 获取本实例内包含的所有插件实例
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
virtual QList<std::shared_ptr<WsComponent>> components() const override;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 深度克隆本实例,插件和数据一致
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
virtual std::shared_ptr<WsEntity> defaultNew() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 允许输入的消息类型
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>消息类型集合</returns>
|
||||||
|
virtual QList<QString> inputTypes() const;
|
||||||
|
/// <summary>
|
||||||
|
/// 通过指定的签名获取处理入口
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="t">签名</param>
|
||||||
|
/// <returns>处理接口</returns>
|
||||||
|
virtual QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const;
|
||||||
|
/// <summary>
|
||||||
|
/// 通过输入消息类型获取处理入口
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg_type">输入消息类型</param>
|
||||||
|
/// <returns>处理接口列表</returns>
|
||||||
|
virtual QList<WsRespondEntry> getEntryWithInType(const QString& msg_type) const;
|
||||||
|
|
||||||
|
// 通过 Serializable 继承
|
||||||
|
void recoveryFrom(const QJsonObject& obj) override;
|
||||||
|
void saveTo(QJsonObject& obj) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 运行时实体管理器
|
||||||
|
/// </summary>
|
||||||
|
class SIMSBASIC_EXPORT RtEntityManager : public WsEntity, public ComponentSet,
|
||||||
|
public std::enable_shared_from_this<RtEntityManager>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const uint64_t const_id = 0x01ff;
|
||||||
|
QHash<QString, std::shared_ptr<WsComponent>> _comps_list;
|
||||||
|
|
||||||
|
QString templetName() const override;
|
||||||
|
uint64_t entityID() const override;
|
||||||
|
QString name() const override;
|
||||||
|
void append(std::shared_ptr<WsComponent> ins) override;
|
||||||
|
void remove(const QString& component_type) override;
|
||||||
|
QList<std::shared_ptr<WsComponent>> components() const override;
|
||||||
|
|
||||||
|
std::shared_ptr<WsEntity> defaultNew() const override;
|
||||||
|
QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const override;
|
||||||
|
QList<WsRespondEntry> getEntryWithInType(const QString& msg_type) const override;
|
||||||
|
|
||||||
|
void recoveryFrom(const QJsonObject& obj) override;
|
||||||
|
void saveTo(QJsonObject& obj) 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;
|
||||||
|
/// <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;
|
||||||
|
|
||||||
|
};
|
|
@ -9,223 +9,3 @@ QString UniException::content() const noexcept
|
||||||
{
|
{
|
||||||
return _error_store;
|
return _error_store;
|
||||||
}
|
}
|
||||||
|
|
||||||
RtWsEntity::RtWsEntity() {}
|
|
||||||
|
|
||||||
void RtWsEntity::resetTemplet(const QString& name) {
|
|
||||||
this->_templet_name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString RtWsEntity::templetName() const {
|
|
||||||
return this->_templet_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RtWsEntity::resetID(uint64_t id) {
|
|
||||||
this->_entity_id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t RtWsEntity::entityID() const {
|
|
||||||
return this->_entity_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RtWsEntity::resetName(const QString& name) {
|
|
||||||
this->_runtime_name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString RtWsEntity::name() const {
|
|
||||||
return this->_runtime_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RtWsEntity::append(std::shared_ptr<WsComponent> ins) {
|
|
||||||
if (this->_comps_list.contains(ins->name()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ins->bindEntity(this->shared_from_this());
|
|
||||||
this->_comps_list[ins->name()] = ins;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RtWsEntity::remove(const QString& component_type) {
|
|
||||||
this->_comps_list.remove(component_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<std::shared_ptr<WsComponent>> RtWsEntity::components() const {
|
|
||||||
return _comps_list.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<WsEntity> RtWsEntity::defaultNew() const {
|
|
||||||
auto newx = std::make_shared<RtWsEntity>();
|
|
||||||
newx->_entity_id = this->_entity_id;
|
|
||||||
newx->_templet_name = this->_templet_name;
|
|
||||||
newx->_runtime_name = this->_runtime_name;
|
|
||||||
|
|
||||||
for (auto c : this->_comps_list)
|
|
||||||
newx->append(c->defaultNew());
|
|
||||||
return newx;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <QSet>
|
|
||||||
QList<QString> RtWsEntity::inputTypes() const
|
|
||||||
{
|
|
||||||
QList<QString> types;
|
|
||||||
for (auto c : this->_comps_list)
|
|
||||||
types.append(c->inputTypes());
|
|
||||||
return types.toSet().toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <QVariant>
|
|
||||||
#include <QJsonArray>
|
|
||||||
QList<WsRespondEntry> RtWsEntity::getEntryWithSignature(const WsRespondSignatureType& t) const
|
|
||||||
{
|
|
||||||
QList<WsRespondEntry> list;
|
|
||||||
for (auto c : this->_comps_list)
|
|
||||||
list.append(c->getEntryWithSignature(t));
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<WsRespondEntry> RtWsEntity::getEntryWithInType(const QString& msg_type) const
|
|
||||||
{
|
|
||||||
QList<WsRespondEntry> list;
|
|
||||||
for (auto c : this->_comps_list)
|
|
||||||
list.append(c->getEntrysWithInType(msg_type));
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
void RtWsEntity::recoveryFrom(const QJsonObject& obj)
|
|
||||||
{
|
|
||||||
this->_entity_id = obj["entity_id"].toVariant().toULongLong();
|
|
||||||
this->_runtime_name = obj["entity_name"].toString();
|
|
||||||
this->_templet_name = obj["entity_templet"].toString();
|
|
||||||
|
|
||||||
auto array = obj["component_array"].toArray();
|
|
||||||
for (auto idx = 0; idx < array.size(); ++idx) {
|
|
||||||
auto value = array.at(idx).toObject();
|
|
||||||
auto type = value["component_type"].toString();
|
|
||||||
|
|
||||||
auto compins = this->_comps_list[type];
|
|
||||||
if (!compins)
|
|
||||||
throw new UniException(type + "类型插件不存在!");
|
|
||||||
|
|
||||||
compins->recoveryFrom(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RtWsEntity::saveTo(QJsonObject& obj) const
|
|
||||||
{
|
|
||||||
obj["entity_id"] = QJsonValue::fromVariant(QVariant::fromValue(this->_entity_id));
|
|
||||||
obj["entity_name"] = this->_runtime_name;
|
|
||||||
obj["entity_templet"] = this->_templet_name;
|
|
||||||
|
|
||||||
QJsonArray array;
|
|
||||||
for (auto c : this->_comps_list)
|
|
||||||
{
|
|
||||||
QJsonObject comp_obj;
|
|
||||||
comp_obj["component_type"] = c->name();
|
|
||||||
c->saveTo(comp_obj);
|
|
||||||
array.append(comp_obj);
|
|
||||||
}
|
|
||||||
obj["component_array"] = array;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString RtEntityManager::templetName() const
|
|
||||||
{
|
|
||||||
return "实体管理器";
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t RtEntityManager::entityID() const
|
|
||||||
{
|
|
||||||
return const_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString RtEntityManager::name() const
|
|
||||||
{
|
|
||||||
return "实体管理器唯一实例";
|
|
||||||
}
|
|
||||||
|
|
||||||
void RtEntityManager::append(std::shared_ptr<WsComponent> ins) {
|
|
||||||
_comps_list[ins->name()] = ins;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<WsEntity> RtEntityManager::defaultNew() const
|
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<WsRespondEntry> RtEntityManager::getEntryWithSignature(const WsRespondSignatureType& t) const
|
|
||||||
{
|
|
||||||
QList<WsRespondEntry> list;
|
|
||||||
for (auto c : this->_comps_list)
|
|
||||||
list.append(c->getEntryWithSignature(t));
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<WsRespondEntry> RtEntityManager::getEntryWithInType(const QString& msg_type) const
|
|
||||||
{
|
|
||||||
QList<WsRespondEntry> list;
|
|
||||||
for (auto c : this->_comps_list)
|
|
||||||
list.append(c->getEntrysWithInType(msg_type));
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RtEntityManager::recoveryFrom(const QJsonObject& obj)
|
|
||||||
{
|
|
||||||
auto array = obj["component_array"].toArray();
|
|
||||||
for (auto idx = 0; idx < array.size(); ++idx) {
|
|
||||||
auto value = array.at(idx).toObject();
|
|
||||||
auto type = value["component_type"].toString();
|
|
||||||
|
|
||||||
auto compins = this->_comps_list[type];
|
|
||||||
if (!compins)
|
|
||||||
throw new UniException(type + "类型插件不存在!");
|
|
||||||
|
|
||||||
compins->recoveryFrom(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RtEntityManager::saveTo(QJsonObject& obj) const
|
|
||||||
{
|
|
||||||
QJsonArray array;
|
|
||||||
for (auto c : this->_comps_list)
|
|
||||||
{
|
|
||||||
QJsonObject comp_obj;
|
|
||||||
comp_obj["component_type"] = c->name();
|
|
||||||
c->saveTo(comp_obj);
|
|
||||||
array.append(comp_obj);
|
|
||||||
}
|
|
||||||
obj["component_array"] = array;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RtEntityManager::remove(const QString& component_type)
|
|
||||||
{
|
|
||||||
this->_comps_list.remove(component_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<std::shared_ptr<WsComponent>> RtEntityManager::components() const
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -203,144 +203,3 @@ public:
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
virtual QList<std::shared_ptr<WsComponent>> components() const = 0;
|
virtual QList<std::shared_ptr<WsComponent>> components() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <QHash>
|
|
||||||
/// <summary>
|
|
||||||
/// 内存实体实例类型
|
|
||||||
/// </summary>
|
|
||||||
class SIMSBASIC_EXPORT RtWsEntity : public WsEntity, public ComponentSet, public std::enable_shared_from_this<RtWsEntity> {
|
|
||||||
private:
|
|
||||||
uint64_t _entity_id = 0;
|
|
||||||
QString _templet_name, _runtime_name;
|
|
||||||
QHash<QString, std::shared_ptr<WsComponent>> _comps_list;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit RtWsEntity();
|
|
||||||
virtual ~RtWsEntity() = default;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 重置本实例模板名
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">模板名称</param>
|
|
||||||
virtual void resetTemplet(const QString& name);
|
|
||||||
/// <summary>
|
|
||||||
/// 获取本实例的模板名
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>模板名称</returns>
|
|
||||||
virtual QString templetName() const;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 重置本实例的运行ID
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id"></param>
|
|
||||||
virtual void resetID(uint64_t id);
|
|
||||||
/// <summary>
|
|
||||||
/// 获取本实例的运行ID
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
virtual uint64_t entityID() const;
|
|
||||||
/// <summary>
|
|
||||||
/// 重置本实例的运行名称
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name"></param>
|
|
||||||
virtual void resetName(const QString& name);
|
|
||||||
/// <summary>
|
|
||||||
/// 获取本实例的运行名称
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>运行名称</returns>
|
|
||||||
virtual QString name() const;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 为本实例添加指定类型的插件
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ins"></param>
|
|
||||||
virtual void append(std::shared_ptr<WsComponent> ins) override;
|
|
||||||
/// <summary>
|
|
||||||
/// 移除指定类型的插件实例
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="component_type"></param>
|
|
||||||
virtual void remove(const QString& component_type) override;
|
|
||||||
/// <summary>
|
|
||||||
/// 获取本实例内包含的所有插件实例
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
virtual QList<std::shared_ptr<WsComponent>> components() const override;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 深度克隆本实例,插件和数据一致
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
virtual std::shared_ptr<WsEntity> defaultNew() const;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 允许输入的消息类型
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>消息类型集合</returns>
|
|
||||||
virtual QList<QString> inputTypes() const;
|
|
||||||
/// <summary>
|
|
||||||
/// 通过指定的签名获取处理入口
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="t">签名</param>
|
|
||||||
/// <returns>处理接口</returns>
|
|
||||||
virtual QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const;
|
|
||||||
/// <summary>
|
|
||||||
/// 通过输入消息类型获取处理入口
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="msg_type">输入消息类型</param>
|
|
||||||
/// <returns>处理接口列表</returns>
|
|
||||||
virtual QList<WsRespondEntry> getEntryWithInType(const QString& msg_type) const;
|
|
||||||
|
|
||||||
// 通过 Serializable 继承
|
|
||||||
void recoveryFrom(const QJsonObject& obj) override;
|
|
||||||
void saveTo(QJsonObject& obj) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class SIMSBASIC_EXPORT RtEntityManager : public WsEntity, public ComponentSet,
|
|
||||||
public std::enable_shared_from_this<RtEntityManager>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const uint64_t const_id = 0x01ff;
|
|
||||||
QHash<QString, std::shared_ptr<WsComponent>> _comps_list;
|
|
||||||
|
|
||||||
QString templetName() const override;
|
|
||||||
uint64_t entityID() const override;
|
|
||||||
QString name() const override;
|
|
||||||
void append(std::shared_ptr<WsComponent> ins) override;
|
|
||||||
void remove(const QString& component_type) override;
|
|
||||||
QList<std::shared_ptr<WsComponent>> components() const override;
|
|
||||||
|
|
||||||
std::shared_ptr<WsEntity> defaultNew() const override;
|
|
||||||
QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const override;
|
|
||||||
QList<WsRespondEntry> getEntryWithInType(const QString& msg_type) const override;
|
|
||||||
|
|
||||||
void recoveryFrom(const QJsonObject& obj) override;
|
|
||||||
void saveTo(QJsonObject& obj) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
/// <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;
|
|
||||||
|
|
||||||
};
|
|
Loading…
Reference in New Issue