diff --git a/applications/vision/src/main.cpp b/applications/vision/src/main.cpp index 88069323f58287d189f9df27d210462ac0ca0977..c27129e456207497575a0696c791c2ada46dcc24 100644 --- a/applications/vision/src/main.cpp +++ b/applications/vision/src/main.cpp @@ -184,10 +184,7 @@ static void run(ftl::Configurable *root) { float latency = 0.0f; int64_t stats_time = 0; - quiet = root->value("quiet", false); - root->on("quiet", [root](const ftl::config::Event &e) { - quiet = root->value("quiet", false); - }); + root->on("quiet", quiet, false); auto *pipeline = ftl::config::create<ftl::operators::Graph>(root, "pipeline"); pipeline->append<ftl::operators::DetectAndTrack>("facedetection")->value("enabled", false); diff --git a/components/common/cpp/include/ftl/configurable.hpp b/components/common/cpp/include/ftl/configurable.hpp index c32b3dce434a3b93ddb60b1a71841d60825ed3c8..c0b8ae802aeb722a547af95f0b884e780f0cd933 100644 --- a/components/common/cpp/include/ftl/configurable.hpp +++ b/components/common/cpp/include/ftl/configurable.hpp @@ -95,6 +95,19 @@ class Configurable { */ void on(const std::string &prop, std::function<void(const config::Event&)>); + //void on(const std::string &prop, const std::function<void()> &); + + template <typename T> + void on(const std::string &prop, T &v) { + on(prop, [&v,this,prop](const config::Event &e) { v = *this->get<T>(prop); }); + } + + template <typename T> + void on(const std::string &prop, T &v, const T &def) { + v = this->value(prop, def); + on(prop, [&v,this,prop](const config::Event &e) { v = *this->get<T>(prop); }); + } + void patchPtr(nlohmann::json &newcfg) { config_ = &newcfg; } /**