From 269d0cc30857454b042ac07b3d63b4436889a141 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Fri, 17 Jul 2020 15:59:06 +0300 Subject: [PATCH] Improve source restore and fix strip bug --- applications/vision/src/main.cpp | 5 +++++ components/common/cpp/src/configuration.cpp | 6 +++++- components/common/cpp/src/uri.cpp | 2 +- components/rgbd-sources/src/source.cpp | 7 ++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/applications/vision/src/main.cpp b/applications/vision/src/main.cpp index ddaa3a285..f26e43d59 100644 --- a/applications/vision/src/main.cpp +++ b/applications/vision/src/main.cpp @@ -294,6 +294,11 @@ int main(int argc, char **argv) { std::cout << "FTL Vision Node " << FTL_VERSION_LONG << std::endl; auto root = ftl::configure(argc, argv, "vision_default"); + root->restore("root", { + "uri", + "fps" + }); + // Use other GPU if available. //ftl::cuda::setDevice(ftl::cuda::deviceCount()-1); diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp index a455a5c84..45428962b 100644 --- a/components/common/cpp/src/configuration.cpp +++ b/components/common/cpp/src/configuration.cpp @@ -657,14 +657,18 @@ Configurable *ftl::config::configure(ftl::config::json_t &cfg) { // Remove all $ keys from json static void stripJSON(nlohmann::json &j) { - for(auto &el : j.items()) { + auto items = j.items(); + for(auto i=items.begin(); i != items.end(); ) { + auto &el = *i; if (el.key()[0] == '$') { + ++i; j.erase(el.key()); continue; } if (el.value().is_structured()) { stripJSON(el.value()); } + ++i; } } diff --git a/components/common/cpp/src/uri.cpp b/components/common/cpp/src/uri.cpp index 14270640c..768e6a612 100644 --- a/components/common/cpp/src/uri.cpp +++ b/components/common/cpp/src/uri.cpp @@ -200,7 +200,7 @@ void URI::setAttribute(const string &key, int value) { } void URI::to_json(nlohmann::json &json) { - std::string uri = getBaseURI(); + std::string uri = to_string(); if (m_frag.size() > 0) uri += std::string("#") + getFragment(); json["uri"] = uri; diff --git a/components/rgbd-sources/src/source.cpp b/components/rgbd-sources/src/source.cpp index 64d882a53..cb2b04eec 100644 --- a/components/rgbd-sources/src/source.cpp +++ b/components/rgbd-sources/src/source.cpp @@ -149,7 +149,9 @@ void Source::reset() { auto uristr = get<string>("uri"); if (!uristr) return; - restore(*uristr, { + ftl::URI uri(*uristr); + + restore(uri.getBaseURI(), { "min_depth", "max_depth", "name", @@ -161,6 +163,9 @@ void Source::reset() { "feed", "pipeline" }); + + uri.to_json(getConfig()); + impl_ = createImplementation(*uristr, this); } -- GitLab