diff --git a/components/common/cpp/include/ftl/configuration.hpp b/components/common/cpp/include/ftl/configuration.hpp index 099a6c33b504dfb97ec9f0b9f3ff2ffd09236ad5..6a91c9b05781a6442844a53b73828027b1fcf9e0 100644 --- a/components/common/cpp/include/ftl/configuration.hpp +++ b/components/common/cpp/include/ftl/configuration.hpp @@ -37,7 +37,7 @@ bool update(const std::string &puri, const json_t &value); * Resolve a JSON schema reference, but do not wait for a remote reference * if it is not available. A null entity is returned if not resolved. */ -json_t &resolve(const std::string &); +json_t &resolve(const std::string &, bool eager=true); /** * Resolve a reference object, or if not a reference object it simply returns @@ -85,17 +85,17 @@ using config::configure; template <typename T, typename... ARGS> T *ftl::config::create(json_t &link, ARGS ...args) { - auto &r = link; // = ftl::config::resolve(link); + //auto &r = link; // = ftl::config::resolve(link); - if (!r["$id"].is_string()) { - LOG(FATAL) << "Entity does not have $id or parent: " << r; + if (!link["$id"].is_string()) { + LOG(FATAL) << "Entity does not have $id or parent: " << link; return nullptr; } - ftl::Configurable *cfg = ftl::config::find(r["$id"].get<std::string>()); + ftl::Configurable *cfg = ftl::config::find(link["$id"].get<std::string>()); if (!cfg) { // try { - cfg = new T(r, args...); + cfg = new T(link, args...); //} catch(...) { // LOG(FATAL) << "Could not construct " << link; //} diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp index 58cade5dd1d08c1e9b9c7e87ecf56da327465679..eff18ba9eb0c287ee7d964f57842c26bf3cb5f31 100644 --- a/components/common/cpp/src/configuration.cpp +++ b/components/common/cpp/src/configuration.cpp @@ -218,7 +218,8 @@ bool ftl::config::update(const std::string &puri, const json_t &value) { cfg->set<json_t>(tail, value); } else { DLOG(1) << "Updating: " << head << "[" << tail << "] = " << value; - auto r = resolve(head); + auto &r = resolve(head, false); + if (!r.is_structured()) { LOG(ERROR) << "Cannot update property '" << tail << "' of '" << head << "'"; return false; @@ -229,7 +230,7 @@ bool ftl::config::update(const std::string &puri, const json_t &value) { } } -json_t &ftl::config::resolve(const std::string &puri) { +json_t &ftl::config::resolve(const std::string &puri, bool eager) { string uri_str = puri; // TODO(Nick) Must support alternative root (last $id) @@ -252,11 +253,13 @@ json_t &ftl::config::resolve(const std::string &puri) { auto ptr = nlohmann::json::json_pointer("/"+uri.getFragment()); try { - return resolve((*ix).second->at(ptr)); + return (eager) ? resolve((*ix).second->at(ptr)) : (*ix).second->at(ptr); } catch(...) { + LOG(WARNING) << "Resolve failed for " << puri; return null_json; } } else { + LOG(WARNING) << "Resolve failed for " << puri; return null_json; } } @@ -429,6 +432,10 @@ Configurable *ftl::config::configure(int argc, char **argv, const std::string &r rootCFG = rootcfg; rootcfg->set("paths", paths); process_options(rootcfg, options); + + //LOG(INFO) << "CONFIG: " << config["vision_default"]; + CHECK_EQ( &config, config_index["ftl://utu.fi"] ); + return rootcfg; }