diff --git a/src/api/processor/processor.cc b/src/api/processor/processor.cc index b3f6491..2383a39 100644 --- a/src/api/processor/processor.cc +++ b/src/api/processor/processor.cc @@ -59,11 +59,10 @@ void Processor::SetProcessCallback(ProcessCallback callback) { callback_ = std::move(callback); } -void Processor::Activate() { +void Processor::Activate(bool tree) { if (activated_) return; - activated_ = true; - { + if (tree) { // Activate all parents Processor *parent = parent_; while (parent != nullptr) { @@ -71,13 +70,20 @@ void Processor::Activate() { parent = parent->parent_; } } + activated_ = true; thread_ = std::thread(&Processor::Run, this); // thread_.detach(); } -void Processor::Deactivate() { +void Processor::Deactivate(bool tree) { if (!activated_) return; + if (tree) { + // Deactivate all childs + iterate_processors(GetChilds(), [](std::shared_ptr proc) { + proc->Deactivate(); + }); + } activated_ = false; { std::lock_guard lk(mtx_input_ready_); diff --git a/src/api/processor/processor.h b/src/api/processor/processor.h index d4a0906..9159d9f 100644 --- a/src/api/processor/processor.h +++ b/src/api/processor/processor.h @@ -39,8 +39,8 @@ class Processor /*: public std::enable_shared_from_this*/ { void SetPostProcessCallback(PostProcessCallback callback); void SetProcessCallback(ProcessCallback callback); - void Activate(); - void Deactivate(); + void Activate(bool tree = false); + void Deactivate(bool tree = false); bool IsActivated(); bool IsIdle(); @@ -93,6 +93,15 @@ class Processor /*: public std::enable_shared_from_this*/ { std::thread thread_; }; +template +void iterate_processors( + const T &processors, std::function)> fn) { + for (auto &&proc : processors) { + fn(proc); + iterate_processors(proc->GetChilds(), fn); + } +} + MYNTEYE_END_NAMESPACE #endif // MYNTEYE_PROCESSOR_H_ NOLINT