67 lines
1.5 KiB
C++
67 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <mutex>
|
|
#include <condition_variable>
|
|
#include <vector>
|
|
#include <thread>
|
|
#include <atomic>
|
|
|
|
#include "node.h"
|
|
#include "plugin_loader.h"
|
|
#include "utils/simple_json.h"
|
|
|
|
namespace rk3588 {
|
|
|
|
class Graph {
|
|
public:
|
|
explicit Graph(std::string name);
|
|
~Graph();
|
|
|
|
bool Build(const SimpleJson& graph_cfg, PluginLoader& loader, size_t default_queue_size,
|
|
QueueDropStrategy default_strategy, std::string& err);
|
|
bool Start();
|
|
void Stop();
|
|
|
|
private:
|
|
struct NodeEntry {
|
|
std::string id;
|
|
std::string type;
|
|
std::string role;
|
|
bool enabled = true;
|
|
SimpleJson config;
|
|
NodeContext context;
|
|
std::unique_ptr<INode> node;
|
|
std::thread worker;
|
|
};
|
|
|
|
std::string name_;
|
|
std::vector<NodeEntry> nodes_;
|
|
std::atomic<bool> running_{false};
|
|
std::atomic<bool> stop_requested_{false};
|
|
};
|
|
|
|
class GraphManager {
|
|
public:
|
|
explicit GraphManager(std::string plugin_dir = "plugins");
|
|
~GraphManager();
|
|
|
|
static bool LoadConfigFile(const std::string& path, SimpleJson& out, std::string& err);
|
|
|
|
bool Build(const SimpleJson& root_cfg, std::string& err);
|
|
bool StartAll();
|
|
void StopAll();
|
|
void RequestStop();
|
|
void BlockUntilStop();
|
|
|
|
private:
|
|
bool running_ = false;
|
|
PluginLoader loader_;
|
|
std::vector<std::unique_ptr<Graph>> graphs_;
|
|
std::mutex mu_;
|
|
std::condition_variable cv_;
|
|
};
|
|
|
|
} // namespace rk3588
|