summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorLuciano Iam <lucianito@gmail.com>2020-04-11 09:31:06 +0200
committerRobin Gareus <robin@gareus.org>2020-04-11 22:30:40 +0200
commite82171ea1954c3e80040c063c401ceb0913b4dd3 (patch)
tree90a675dde486971dc8f1c220f617e72756a3b8a1 /libs
parent420137ea9d36be85f73a42f1a551df98930911af (diff)
WebSockets: improve surface manifest format and loader
Diffstat (limited to 'libs')
-rw-r--r--libs/surfaces/websockets/manifest.cc33
-rw-r--r--libs/surfaces/websockets/manifest.h6
-rw-r--r--libs/surfaces/websockets/resources.cc14
3 files changed, 31 insertions, 22 deletions
diff --git a/libs/surfaces/websockets/manifest.cc b/libs/surfaces/websockets/manifest.cc
index 80c900ecf7..be5ac342be 100644
--- a/libs/surfaces/websockets/manifest.cc
+++ b/libs/surfaces/websockets/manifest.cc
@@ -18,15 +18,21 @@
#include <iostream>
#include <sstream>
+
+#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
#include "pbd/xml++.h"
#include "manifest.h"
-SurfaceManifest::SurfaceManifest (std::string xml_path)
+static const char* const manifest_filename = "manifest.xml";
+
+SurfaceManifest::SurfaceManifest (std::string path)
+ : _path (path)
{
XMLTree tree;
+ std::string xml_path = Glib::build_filename (_path, manifest_filename);
if (!tree.read (xml_path.c_str())) {
#ifndef NDEBUG
@@ -44,25 +50,18 @@ SurfaceManifest::SurfaceManifest (std::string xml_path)
node->get_property ("value", value);
- if (name == "Id") {
- _id = value;
- } else if (name == "Name") {
+ if (name == "Name") {
_name = value;
} else if (name == "Description") {
_description = value;
}
}
-#ifndef NDEBUG
if (_name.empty () || _description.empty ()) {
+#ifndef NDEBUG
std::cerr << "SurfaceManifest: missing properties in " << xml_path << std::endl;
- return;
- }
#endif
-
- if (_id.empty ()) {
- // default to manifest subdirectory name
- _id = Glib::path_get_basename (Glib::path_get_dirname (xml_path));
+ return;
}
_valid = true;
@@ -73,11 +72,21 @@ SurfaceManifest::to_json ()
{
std::stringstream ss;
+ std::string rel_path = Glib::path_get_basename (Glib::path_get_dirname (_path));
+
ss << "{"
- << "\"id\":\"" << _id << "\""
+ << "\"diskPath\":\"" << _path << "\""
+ << ",\"path\":\"" << rel_path << "\""
<< ",\"name\":\"" << _name << "\""
<< ",\"description\":\"" << _description << "\""
<< "}";
return ss.str ();
}
+
+bool
+SurfaceManifest::exists_at_path (std::string path)
+{
+ std::string xml_path = Glib::build_filename (path, manifest_filename);
+ return Glib::file_test (xml_path, Glib::FILE_TEST_EXISTS);
+}
diff --git a/libs/surfaces/websockets/manifest.h b/libs/surfaces/websockets/manifest.h
index 19e6ba943e..5c776639c3 100644
--- a/libs/surfaces/websockets/manifest.h
+++ b/libs/surfaces/websockets/manifest.h
@@ -29,16 +29,18 @@ public:
bool valid () { return _valid; }
- std::string id () { return _id; }
+ std::string path () { return _path; }
std::string name () { return _name; }
std::string description () { return _description; }
std::string to_json ();
+ static bool exists_at_path (std::string);
+
private:
bool _valid;
- std::string _id;
+ std::string _path;
std::string _name;
std::string _description;
};
diff --git a/libs/surfaces/websockets/resources.cc b/libs/surfaces/websockets/resources.cc
index 6cd41cd2ba..428128638a 100644
--- a/libs/surfaces/websockets/resources.cc
+++ b/libs/surfaces/websockets/resources.cc
@@ -30,7 +30,7 @@
static const char* const data_dir_env_var = "ARDOUR_WEBSURFACES_PATH";
static const char* const data_dir_name = "web_surfaces";
static const char* const builtin_dir_name = "builtin";
-static const char* const manifest_filename = "manifest.xml";
+static const char* const user_dir_name = "user";
static bool
dir_filter (const std::string &str, void* /*arg*/)
@@ -80,7 +80,7 @@ ServerResources::scan ()
{
std::stringstream ss;
- ss << "{\"builtin\":[";
+ ss << "[{\"path\":\"" << builtin_dir_name << "\",\"surfaces\":[";
SurfaceManifestVector builtin = read_manifests (builtin_dir ());
@@ -91,7 +91,7 @@ ServerResources::scan ()
}
}
- ss << "],\"user\":[";
+ ss << "]},{\"path\":\"" << user_dir_name << "\",\"surfaces\":[";
SurfaceManifestVector user = read_manifests (user_dir ());
@@ -102,7 +102,7 @@ ServerResources::scan ()
}
}
- ss << "]}";
+ ss << "]}]";
return ss.str ();
}
@@ -143,13 +143,11 @@ ServerResources::read_manifests (std::string dir)
0 /*arg*/, true /*pass_fullpath*/, true /*return_fullpath*/, false /*recurse*/);
for (std::vector<std::string>::const_iterator it = subdirs.begin (); it != subdirs.end (); ++it) {
- std::string xml_path = Glib::build_filename (*it, manifest_filename);
-
- if (!Glib::file_test (xml_path, Glib::FILE_TEST_EXISTS)) {
+ if (!SurfaceManifest::exists_at_path (*it)) {
continue;
}
- SurfaceManifest manifest (xml_path);
+ SurfaceManifest manifest (*it);
if (manifest.valid ()) {
result.push_back (manifest);