62 lines
1.9 KiB
C++
62 lines
1.9 KiB
C++
#pragma once
|
|
// 定义管道引擎 包含队列、运行状态、工作线程、计数器、插件管理器
|
|
// 队列是用来存储管道上下文的
|
|
// 运行状态是用来控制引擎的运行和停止的
|
|
// 工作线程是用来处理管道上下文的
|
|
// 计数器是用来统计管道上下文的数量和错误数量的
|
|
// 插件管理器是用来管理插件的
|
|
#include <atomic>
|
|
#include <memory>
|
|
#include <thread>
|
|
|
|
#include "core/plugin_system/PluginManager.h"
|
|
#include "core/memory/LockFreeQueue.h"
|
|
#include "message_bus/pipeline/PipelineContext.h"
|
|
|
|
namespace softbus::message_bus::pipeline
|
|
{
|
|
|
|
class PipelineEngine
|
|
{
|
|
public:
|
|
struct Counters
|
|
{
|
|
std::atomic<std::uint64_t> in{0};
|
|
std::atomic<std::uint64_t> out{0};
|
|
std::atomic<std::uint64_t> drop{0};
|
|
std::atomic<std::uint64_t> error{0};
|
|
};
|
|
|
|
explicit PipelineEngine(std::size_t queueCapacity = 4096);
|
|
~PipelineEngine();
|
|
|
|
void start();
|
|
void stop();
|
|
void drain();
|
|
|
|
bool enqueueIngress(PipelineContext ctx);
|
|
bool enqueueEgress(PipelineContext ctx);
|
|
|
|
bool tryPopEgress(PipelineContext& out);
|
|
void setPluginManager(std::shared_ptr<softbus::core::plugin_system::PluginManager> pluginManager);
|
|
|
|
const Counters& counters() const { return m_counters; }
|
|
|
|
private:
|
|
void run();
|
|
bool stage1Framer(PipelineContext& ctx);
|
|
bool stage2Parser(PipelineContext& ctx);
|
|
bool stage3Filter(PipelineContext& ctx);
|
|
bool stage4Validator(PipelineContext& ctx);
|
|
|
|
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::shared_ptr<softbus::core::plugin_system::PluginManager> m_pluginManager;
|
|
};
|
|
|
|
} // namespace softbus::message_bus::pipeline
|