diff --git a/applications/gui/src/main.cpp b/applications/gui/src/main.cpp index 7875e52bb04afc59953ac1a728dafe64008b6d6c..64c65eb4e08df1713f37a2517fd2d2e4c3c93d96 100644 --- a/applications/gui/src/main.cpp +++ b/applications/gui/src/main.cpp @@ -25,10 +25,12 @@ int main(int argc, char **argv) { std::map<ftl::UUID, std::vector<ftl::NetConfigurable*>> peerConfigurables; + // FIXME: Move this elsewhere, it is not just for GUI net->onConnect([&controller, &peerConfigurables](ftl::net::Peer *p) { ftl::UUID peer = p->id(); auto cs = controller->getConfigurables(peer); for (auto c : cs) { + LOG(INFO) << "NET CONFIG: " << c; ftl::config::json_t *configuration = new ftl::config::json_t; *configuration = controller->get(peer, c); if (!configuration->empty()) { diff --git a/applications/gui/src/screen.cpp b/applications/gui/src/screen.cpp index cdc6934f117b0372f007a506addbe8256ab3627c..4fc879a8e84ec97d7400d0ffe41381d1d84b30ea 100644 --- a/applications/gui/src/screen.cpp +++ b/applications/gui/src/screen.cpp @@ -477,12 +477,12 @@ bool ftl::gui::Screen::keyboardEvent(int key, int scancode, int action, int modi std::string uri = (*s).value("uri",std::string("")); if (op == "toggle") { - auto v = ftl::config::resolve(uri, false); + auto v = ftl::config::get(uri); if (v.is_boolean()) { ftl::config::update(uri, !v.get<bool>()); } } else if (op == "+=") { - auto v = ftl::config::resolve(uri, false); + auto v = ftl::config::get(uri); if (v.is_number_float()) { ftl::config::update(uri, v.get<float>() + (*s).value("value",0.0f)); } diff --git a/components/common/cpp/include/ftl/configuration.hpp b/components/common/cpp/include/ftl/configuration.hpp index 9e4ba8aed4bcf8b5f2c8cec2c1079edb945359c3..18aaf89f9433911dd71ec3d3519ff2125317e78e 100644 --- a/components/common/cpp/include/ftl/configuration.hpp +++ b/components/common/cpp/include/ftl/configuration.hpp @@ -47,6 +47,8 @@ void removeConfigurable(Configurable *cfg); */ bool update(const std::string &puri, const json_t &value); +json_t &get(const std::string &puri); + /** * 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. diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp index aa236c8a06772e71d59edd3886ce7a9cb14e2eec..4c813914ade72d57944a2493632e4f6b9ba7b727 100644 --- a/components/common/cpp/src/configuration.cpp +++ b/components/common/cpp/src/configuration.cpp @@ -194,6 +194,7 @@ ftl::Configurable *ftl::config::find(const std::string &uri) { actual_uri = rootCFG->getID() + uri; } } + auto ix = config_instance.find(actual_uri); if (ix == config_instance.end()) return nullptr; else return (*ix).second; @@ -284,6 +285,34 @@ bool ftl::config::update(const std::string &puri, const json_t &value) { } } +json_t &ftl::config::get(const std::string &puri) { + // Remove last component of URI + string tail = ""; + string head = ""; + size_t last_hash = puri.find_last_of('#'); + if (last_hash != string::npos) { + size_t last = puri.find_last_of('/'); + if (last != string::npos && last > last_hash) { + tail = puri.substr(last+1); + head = puri.substr(0, last); + } else { + tail = puri.substr(last_hash+1); + head = puri.substr(0, last_hash); + } + } else { + LOG(WARNING) << "Expected a # in an update URI: " << puri; + return null_json; + } + + Configurable *cfg = find(head); + + if (cfg) { + return cfg->getConfig()[tail]; + } else { + return null_json; + } +} + json_t &ftl::config::resolve(const std::string &puri, bool eager) { string uri_str = puri;