2025-05-25 04:43:37 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "componentbasic_global.h"
|
|
|
|
|
#include <simsbasic.h>
|
2025-06-10 04:52:59 +00:00
|
|
|
|
#include <QHash>
|
2025-05-25 04:43:37 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="MsgA"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></typeparam>
|
|
|
|
|
/// <typeparam name="MsgB"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></typeparam>
|
|
|
|
|
template<typename MsgA, typename MsgB> class WsRespond {
|
|
|
|
|
public:
|
|
|
|
|
using SelfType = WsRespond<MsgA, MsgB>;
|
|
|
|
|
|
|
|
|
|
virtual ~WsRespond() = default;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Respond<6E><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩ<EFBFBD><C7A9>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
static WsRespondSignatureType signature()
|
|
|
|
|
{
|
|
|
|
|
return std::make_pair<QString, QString>(MsgA().topicString(), MsgB().topicString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="in"></param>
|
2025-05-31 04:18:43 +00:00
|
|
|
|
/// <param name="out"></param>
|
2025-06-10 04:41:33 +00:00
|
|
|
|
virtual void execute(std::shared_ptr<Immediate> map, std::shared_ptr<const MsgA> in, QList<std::shared_ptr<MsgB>>& out) = 0;
|
2025-05-25 04:43:37 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// WsRespond<6E><64><EFBFBD>캯<EFBFBD><ECBAAF>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="map">ע<>ắ<EFBFBD><E1BAAF></param>
|
|
|
|
|
explicit WsRespond(QHash<WsRespondSignatureType, WsRespondEntry>& map) {
|
2025-06-10 04:41:33 +00:00
|
|
|
|
WsRespondEntry ins = [=](std::shared_ptr<Immediate> map, std::shared_ptr<const WsMessage> in, QList<std::shared_ptr<WsMessage>>& out) {
|
2025-06-08 04:12:15 +00:00
|
|
|
|
QList<std::shared_ptr<MsgB>> o_ptrs;
|
|
|
|
|
this->execute(map, std::static_pointer_cast<const MsgA>(in), o_ptrs);
|
|
|
|
|
std::transform(o_ptrs.begin(), o_ptrs.end(), std::back_inserter(out),
|
|
|
|
|
[](std::shared_ptr<MsgB> v) { return std::static_pointer_cast<WsMessage>(v); });
|
2025-05-25 04:43:37 +00:00
|
|
|
|
};
|
|
|
|
|
map[SelfType::signature()] = ins;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename... ProcSigs>struct _ProcRoute_;
|
|
|
|
|
template <> struct COMPONENTBASIC_EXPORT _ProcRoute_<>
|
|
|
|
|
{
|
|
|
|
|
QHash<WsRespondSignatureType, WsRespondEntry> _execute_map;
|
|
|
|
|
|
|
|
|
|
_ProcRoute_() = default;
|
|
|
|
|
};
|
|
|
|
|
template <typename ProcSig, typename... ProcSigs>
|
|
|
|
|
struct _ProcRoute_<ProcSig, ProcSigs...> : public _ProcRoute_<ProcSigs...>, public ProcSig
|
|
|
|
|
{
|
|
|
|
|
_ProcRoute_() : _ProcRoute_<ProcSigs...>(), ProcSig(_ProcRoute_<>::_execute_map) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename... Procs>
|
|
|
|
|
struct ProcList : public _ProcRoute_<Procs...>, public WsComponent
|
|
|
|
|
{
|
|
|
|
|
using SuperType = ProcList<Procs...>;
|
|
|
|
|
|
|
|
|
|
ProcList() : _ProcRoute_<Procs...>() {}
|
|
|
|
|
|
|
|
|
|
// ͨ<><CDA8> WsComponent <20>̳<EFBFBD>
|
2025-06-10 06:12:53 +00:00
|
|
|
|
QList<WsRespondSignatureType> signatureTypes() const override
|
2025-05-25 04:43:37 +00:00
|
|
|
|
{
|
2025-06-10 06:12:53 +00:00
|
|
|
|
return _ProcRoute_<>::_execute_map.keys();
|
2025-05-25 04:43:37 +00:00
|
|
|
|
}
|
2025-05-31 04:18:43 +00:00
|
|
|
|
QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const override
|
2025-05-25 04:43:37 +00:00
|
|
|
|
{
|
2025-05-31 04:18:43 +00:00
|
|
|
|
QList<WsRespondEntry> list;
|
2025-05-25 04:43:37 +00:00
|
|
|
|
for (auto key : _ProcRoute_<>::_execute_map.keys()) {
|
|
|
|
|
if (key == t)
|
2025-05-31 04:18:43 +00:00
|
|
|
|
list.append(_ProcRoute_<>::_execute_map[key]);
|
2025-05-25 04:43:37 +00:00
|
|
|
|
}
|
2025-05-31 04:18:43 +00:00
|
|
|
|
return list;
|
2025-05-25 04:43:37 +00:00
|
|
|
|
}
|
|
|
|
|
QList<WsRespondEntry> getEntrysWithInType(const QString& msg_type) const override
|
|
|
|
|
{
|
|
|
|
|
QList<WsRespondEntry> list;
|
|
|
|
|
for (auto key : _ProcRoute_<>::_execute_map.keys()) {
|
|
|
|
|
if (key.first == msg_type)
|
|
|
|
|
list.append(_ProcRoute_<>::_execute_map[key]);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
};
|