13
0

WebSockets: improve surface manifest format and loader

This commit is contained in:
Luciano Iam 2020-04-11 09:31:06 +02:00 committed by Robin Gareus
parent 420137ea9d
commit e82171ea19
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 31 additions and 22 deletions

View File

@ -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);
}

View File

@ -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;
};

View File

@ -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);