devices pipelinecontext
This commit is contained in:
@@ -1,21 +1,40 @@
|
||||
#pragma once
|
||||
// 定义管道引擎 包含队列、运行状态、工作线程、计数器、插件管理器
|
||||
// 队列是用来存储管道上下文的
|
||||
// 运行状态是用来控制引擎的运行和停止的
|
||||
// 工作线程是用来处理管道上下文的
|
||||
// 计数器是用来统计管道上下文的数量和错误数量的
|
||||
// 插件管理器是用来管理插件的
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <QHash>
|
||||
#include <QJsonObject>
|
||||
#include <QString>
|
||||
|
||||
#include "core/plugin_system/PluginManager.h"
|
||||
#include "core/memory/LockFreeQueue.h"
|
||||
#include "core/memory/MemoryPool.h"
|
||||
#include "core/threading/MutexQueue.h"
|
||||
#include "message_bus/pipeline/PipelineContext.h"
|
||||
#include "message_bus/pipeline/stages/1_framers/ModbusRtuFramer.h"
|
||||
#include "message_bus/pipeline/stages/1_framers/PassthroughFramer.h"
|
||||
|
||||
namespace softbus::message_bus::pipeline
|
||||
{
|
||||
|
||||
struct PipelineRuntimeConfig
|
||||
{
|
||||
bool parallelPipeline{false};
|
||||
int parseWorkerCount{2};
|
||||
bool orderedEgress{true};
|
||||
|
||||
std::size_t framedQueueMax{4096};
|
||||
std::size_t maxReorderDepth{256};
|
||||
|
||||
softbus::message_bus::pipeline::stages::framers::ModbusRtuFramerConfig modbus;
|
||||
};
|
||||
|
||||
struct EndpointFramingState;
|
||||
|
||||
class PipelineEngine
|
||||
{
|
||||
public:
|
||||
@@ -25,6 +44,7 @@ public:
|
||||
std::atomic<std::uint64_t> out{0};
|
||||
std::atomic<std::uint64_t> drop{0};
|
||||
std::atomic<std::uint64_t> error{0};
|
||||
std::atomic<std::uint64_t> mergeDrop{0};
|
||||
};
|
||||
|
||||
explicit PipelineEngine(std::size_t queueCapacity = 4096);
|
||||
@@ -39,12 +59,38 @@ public:
|
||||
|
||||
bool tryPopEgress(PipelineContext& out);
|
||||
void setPluginManager(std::shared_ptr<softbus::core::plugin_system::PluginManager> pluginManager);
|
||||
void setMemoryPool(std::shared_ptr<softbus::core::memory::MemoryPool> pool);
|
||||
void setRuntimeConfig(PipelineRuntimeConfig cfg);
|
||||
void loadRuntimeConfigFromJson(const QJsonObject& obj);
|
||||
|
||||
const Counters& counters() const { return m_counters; }
|
||||
|
||||
private:
|
||||
void run();
|
||||
bool stage1Framer(PipelineContext& ctx);
|
||||
struct MergeItem
|
||||
{
|
||||
QString endpoint;
|
||||
std::uint64_t seq{0};
|
||||
PipelineContext ctx;
|
||||
bool pipelineOk{false};
|
||||
};
|
||||
|
||||
struct MergeState
|
||||
{
|
||||
std::uint64_t nextExpected{1};
|
||||
QHash<std::uint64_t, std::pair<PipelineContext, bool>> buffer;
|
||||
};
|
||||
|
||||
void runSingleWorker();
|
||||
void parseWorkerLoop();
|
||||
void mergerLoop();
|
||||
|
||||
void ensureEndpointFramer(const QString& endpoint);
|
||||
|
||||
void dispatchFramer(PipelineContext& chunkIn, std::vector<PipelineContext>& completeFramesOut);
|
||||
void assignFrameSequence(PipelineContext& ctx);
|
||||
bool runStages234(PipelineContext& ctx);
|
||||
void ingestMergeItem(MergeItem item);
|
||||
|
||||
bool stage2Parser(PipelineContext& ctx);
|
||||
bool stage3Filter(PipelineContext& ctx);
|
||||
bool stage4Validator(PipelineContext& ctx);
|
||||
@@ -53,9 +99,29 @@ private:
|
||||
softbus::core::memory::LockFreeQueue<PipelineContext> m_ingressQ;
|
||||
softbus::core::memory::LockFreeQueue<PipelineContext> m_egressQ;
|
||||
std::atomic<bool> m_running{false};
|
||||
std::thread m_worker;
|
||||
Counters m_counters;
|
||||
std::thread m_worker;
|
||||
Counters m_counters;
|
||||
std::shared_ptr<softbus::core::plugin_system::PluginManager> m_pluginManager;
|
||||
std::shared_ptr<softbus::core::memory::MemoryPool> m_pool;
|
||||
|
||||
PipelineRuntimeConfig m_rtConfig;
|
||||
|
||||
std::unique_ptr<softbus::message_bus::pipeline::stages::framers::ModbusRtuFramer> m_modbusFramer;
|
||||
std::shared_ptr<softbus::message_bus::pipeline::stages::framers::PassthroughFramer> m_passthroughFramer;
|
||||
|
||||
std::mutex m_seqMutex;
|
||||
QHash<QString, std::uint64_t> m_nextFrameSeqByEndpoint;
|
||||
|
||||
std::unique_ptr<softbus::core::threading::MutexQueue<PipelineContext>> m_framedQ;
|
||||
std::unique_ptr<softbus::core::threading::MutexQueue<MergeItem>> m_mergeQ;
|
||||
std::vector<std::thread> m_parseThreads;
|
||||
std::thread m_mergerThread;
|
||||
|
||||
std::mutex m_endpointMutex;
|
||||
QHash<QString, std::shared_ptr<EndpointFramingState>> m_endpointFramers;
|
||||
|
||||
std::mutex m_mergeStateMutex;
|
||||
QHash<QString, MergeState> m_mergeByEndpoint;
|
||||
};
|
||||
|
||||
} // namespace softbus::message_bus::pipeline
|
||||
|
||||
Reference in New Issue
Block a user