Skip to content
Snippets Groups Projects
Commit 08f22c35 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Allow use of tags in URIs

parent 9a9eb50a
No related branches found
No related tags found
1 merge request!181Implements #240 custom shortcuts
Pipeline #16757 failed
......@@ -30,7 +30,7 @@ int main(int argc, char **argv) {
ftl::UUID peer = p->id();
auto cs = controller->getConfigurables(peer);
for (auto c : cs) {
LOG(INFO) << "NET CONFIG: " << c;
//LOG(INFO) << "NET CONFIG: " << c;
ftl::config::json_t *configuration = new ftl::config::json_t;
*configuration = controller->get(peer, c);
if (!configuration->empty()) {
......
......@@ -241,7 +241,7 @@ static void run(ftl::Configurable *root) {
//ftl::voxhash::SceneRep *scene = ftl::create<ftl::voxhash::SceneRep>(root, "voxelhash");
ftl::rgbd::Streamer *stream = ftl::create<ftl::rgbd::Streamer>(root, "stream", net);
ftl::rgbd::VirtualSource *virt = ftl::create<ftl::rgbd::VirtualSource>(root, "virtual");
root->set("tags", nlohmann::json::array({ root->getID()+"/virtual" }));
//root->set("tags", nlohmann::json::array({ root->getID()+"/virtual" }));
ftl::render::Triangular *splat = ftl::create<ftl::render::Triangular>(root, "renderer", &scene_B);
ftl::rgbd::Group *group = new ftl::rgbd::Group;
ftl::ILW *align = ftl::create<ftl::ILW>(root, "merge");
......
......@@ -229,6 +229,7 @@ void ftl::config::registerConfigurable(ftl::Configurable *cfg) {
auto tags = cfg->get<vector<string>>("tags");
if (tags) {
for (auto &t : *tags) {
//LOG(INFO) << "REGISTER TAG: " << t;
tag_index[t].push_back(cfg);
}
}
......@@ -237,22 +238,45 @@ void ftl::config::registerConfigurable(ftl::Configurable *cfg) {
json_t null_json;
/* To allow for custom tag format */
static std::string preprocessURI(const std::string &uri) {
if (uri[0] == '[') {
size_t closing = uri.find_last_of(']');
string tags = uri.substr(1, closing-1);
// TODO: Allow for multiple tags
const auto &cfgs = ftl::config::findByTag(tags);
// FIXME: Check for more than one tag result
if (cfgs.size() > 0) {
//LOG(INFO) << "PREPROC URI " << cfgs[0]->getID() + uri.substr(closing+1);
return cfgs[0]->getID() + uri.substr(closing+1);
} else {
return uri;
}
} else {
return uri;
}
}
bool ftl::config::update(const std::string &puri, const json_t &value) {
// Remove last component of URI
string tail = "";
string head = "";
size_t last_hash = puri.find_last_of('#');
string uri = preprocessURI(puri);
size_t last_hash = uri.find_last_of('#');
if (last_hash != string::npos) {
size_t last = puri.find_last_of('/');
size_t last = uri.find_last_of('/');
if (last != string::npos && last > last_hash) {
tail = puri.substr(last+1);
head = puri.substr(0, last);
tail = uri.substr(last+1);
head = uri.substr(0, last);
} else {
tail = puri.substr(last_hash+1);
head = puri.substr(0, last_hash);
tail = uri.substr(last_hash+1);
head = uri.substr(0, last_hash);
}
} else {
LOG(WARNING) << "Expected a # in an update URI: " << puri;
LOG(WARNING) << "Expected a # in an update URI: " << uri;
return false;
}
......@@ -289,18 +313,19 @@ 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('#');
string uri = preprocessURI(puri);
size_t last_hash = uri.find_last_of('#');
if (last_hash != string::npos) {
size_t last = puri.find_last_of('/');
size_t last = uri.find_last_of('/');
if (last != string::npos && last > last_hash) {
tail = puri.substr(last+1);
head = puri.substr(0, last);
tail = uri.substr(last+1);
head = uri.substr(0, last);
} else {
tail = puri.substr(last_hash+1);
head = puri.substr(0, last_hash);
tail = uri.substr(last_hash+1);
head = uri.substr(0, last_hash);
}
} else {
LOG(WARNING) << "Expected a # in an update URI: " << puri;
LOG(WARNING) << "Expected a # in an update URI: " << uri;
return null_json;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment