Split communication/vst2.h into common and VST2

So we can reuse the generic bits for our VST3 implementation.
This commit is contained in:
Robbert van der Helm
2020-11-29 13:54:33 +01:00
parent 46bc0301af
commit 2fbd14908a
8 changed files with 366 additions and 344 deletions
+38
View File
@@ -0,0 +1,38 @@
#include "common.h"
#include <random>
#include "../utils.h"
namespace fs = boost::filesystem;
/**
* Used for generating random identifiers.
*/
constexpr char alphanumeric_characters[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
boost::filesystem::path generate_endpoint_base(const std::string& plugin_name) {
fs::path temp_directory = get_temporary_directory();
std::random_device random_device;
std::mt19937 rng(random_device());
fs::path candidate_endpoint;
do {
std::string random_id;
std::sample(
alphanumeric_characters,
alphanumeric_characters + strlen(alphanumeric_characters) - 1,
std::back_inserter(random_id), 8, rng);
// We'll get rid of the file descriptors immediately after accepting the
// sockets, so putting them inside of a subdirectory would only leave
// behind an empty directory
std::ostringstream socket_name;
socket_name << "yabridge-" << plugin_name << "-" << random_id;
candidate_endpoint = temp_directory / socket_name.str();
} while (fs::exists(candidate_endpoint));
return candidate_endpoint;
}