瀏覽代碼

add show pipeline

leon 2 周之前
父節點
當前提交
3c27f40297
共有 2 個文件被更改,包括 67 次插入2 次删除
  1. 1 0
      src/main.cpp
  2. 66 2
      src/pipeline/pipeline.hpp

+ 1 - 0
src/main.cpp

@@ -31,6 +31,7 @@ int main(int argc , char* argv[])
         }
     }
     pipeline_manager.start_pipelines();
+    pipeline_manager.show_all_pipeline();
     getchar();
     return 0;
 }

+ 66 - 2
src/pipeline/pipeline.hpp

@@ -45,7 +45,7 @@ public:
         return shared_models_;
     }
 
-    void start_pipelines() 
+    void start_all_pipelines() 
     {
       for (auto& instance : configured_pipelines_) 
       {
@@ -60,7 +60,7 @@ public:
       }
     }
 
-    void stop_pipelines() 
+    void stop_all_pipelines() 
     {
       for (auto& instance : configured_pipelines_) 
       {
@@ -75,6 +75,70 @@ public:
       }
     }
 
+    void start_pipelines_by_id(std::string pipeline_id) 
+    {
+      auto instance = std::find_if(configured_pipelines_.begin(), configured_pipelines_.end(), 
+        [&pipeline_id](const PipelineInstance& instance) { return instance.pipeline_id == pipeline_id; });
+      if (instance == configured_pipelines_.end())
+      {
+        std::cerr << "Pipeline with ID " << pipeline_id << " not found." << std::endl;
+        return;
+      }
+      std::cout << "Starting pipeline: " << instance->pipeline_id << std::endl;
+      // Start the pipeline by starting all nodes in reverse order
+      for (auto it = instance->nodes.rbegin(); it != instance->nodes.rend(); ++it) 
+      {
+        (*it)->start();
+      }
+    }
+
+    void stop_pipelines_by_id(std::string pipeline_id) 
+    {
+      auto instance = std::find_if(configured_pipelines_.begin(), configured_pipelines_.end(), 
+        [&pipeline_id](const PipelineInstance& instance) { return instance.pipeline_id == pipeline_id; });
+      if (instance == configured_pipelines_.end())
+      {
+        std::cerr << "Pipeline with ID " << pipeline_id << " not found." << std::endl;
+        return;
+      }
+      std::cout << "Stopping pipeline: " << instance->pipeline_id << std::endl;
+      // Stop the pipeline by stopping all nodes
+      for (const auto& node : instance->nodes) 
+      {
+        node->stop();
+      }
+    }
+
+    void show_all_pipeline()
+    {
+        for (const auto& pipeline : configured_pipelines_)
+        {
+            printf("Pipeline ID: %s\nDescription: %s\n", pipeline.pipeline_id.c_str(), pipeline.description.c_str());
+            for (const auto& node : instance->nodes)
+            {
+                printf("%s --> ", node->get_name().c_str());
+            }
+            printf("\n");
+        }
+    }
+
+    void show_pipeline_by_id(std::string pipeline_id)
+    {
+        auto instance = std::find_if(configured_pipelines_.begin(), configured_pipelines_.end(), 
+            [&pipeline_id](const PipelineInstance& instance) { return instance.pipeline_id == pipeline_id; });
+        if (instance == configured_pipelines_.end())
+        {
+            std::cerr << "Pipeline with ID " << pipeline_id << " not found." << std::endl;
+            return;
+        }
+        printf("Pipeline ID: %s\nDescription: %s\n", pipeline.pipeline_id.c_str(), pipeline.description.c_str());
+        for (const auto& node : instance->nodes)
+        {
+            printf("%s --> ", node->get_name().c_str());
+        }
+        printf("\n");
+    }
+
 
     void create_from_json(const std::string& json_path);