From dd843519ce437120eb3b487886a02e2558740fff Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 22 May 2020 14:08:13 +0200 Subject: [PATCH] Rename PluginParameters to GroupReuqest --- src/common/serialization.cpp | 2 +- src/common/serialization.h | 8 +++---- src/plugin/plugin-bridge.cpp | 4 ++++ src/wine-host/bridges/group.cpp | 37 ++++++++++++++++++--------------- src/wine-host/bridges/group.h | 10 ++++----- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/common/serialization.cpp b/src/common/serialization.cpp index c16b0142..4a5e14d4 100644 --- a/src/common/serialization.cpp +++ b/src/common/serialization.cpp @@ -109,6 +109,6 @@ AEffect& update_aeffect(AEffect& plugin, const AEffect& updated_plugin) { return plugin; } -bool PluginParameters::operator==(const PluginParameters& rhs) const { +bool GroupRequest::operator==(const GroupRequest& rhs) const { return plugin_path == rhs.plugin_path && socket_path == rhs.socket_path; } diff --git a/src/common/serialization.h b/src/common/serialization.h index b0810dc7..63b596c5 100644 --- a/src/common/serialization.h +++ b/src/common/serialization.h @@ -577,11 +577,11 @@ struct AudioBuffers { * group process. These are the exact same options that would have been passed * to `yabridge-host.exe` were the plugin to be hosted individually. */ -struct PluginParameters { +struct GroupRequest { std::string plugin_path; std::string socket_path; - bool operator==(const PluginParameters& rhs) const; + bool operator==(const GroupRequest& rhs) const; template void serialize(S& s) { @@ -591,8 +591,8 @@ struct PluginParameters { }; template <> -struct std::hash { - std::size_t operator()(PluginParameters const& params) const noexcept { +struct std::hash { + std::size_t operator()(GroupRequest const& params) const noexcept { std::hash hasher{}; return hasher(params.plugin_path) ^ (hasher(params.socket_path) << 1); diff --git a/src/plugin/plugin-bridge.cpp b/src/plugin/plugin-bridge.cpp index fc9f64af..be74e2f3 100644 --- a/src/plugin/plugin-bridge.cpp +++ b/src/plugin/plugin-bridge.cpp @@ -49,6 +49,10 @@ PluginBridge& get_bridge_instance(const AEffect& plugin) { return *static_cast(plugin.ptr3); } +// TODO: It would be nice to have a better way to encapsulate the small +// differences in behavior when using plugin groups, i.e. everywhere where +// we check for `config.group.has_value()` + PluginBridge::PluginBridge(audioMasterCallback host_callback) : config(Configuration::load_for(get_this_file_location())), vst_plugin_path(find_vst_plugin()), diff --git a/src/wine-host/bridges/group.cpp b/src/wine-host/bridges/group.cpp index 5a84136c..fa7f651b 100644 --- a/src/wine-host/bridges/group.cpp +++ b/src/wine-host/bridges/group.cpp @@ -31,13 +31,17 @@ namespace fs = boost::filesystem; */ std::string create_logger_prefix(const fs::path& socket_path); -// CreateThread() is great and allows you to pass a single value to the -// function, so we'll use this to pass both `this` and the parameters to the -// below thread function so it can do its thing. -using handle_host_plugin_parameters = std::pair; - uint32_t WINAPI handle_host_plugin_proxy(void* param); +/** + * CreateThread() is great and allows you to pass a single value to the + * function, so we'll use this to pass both `this` and the parameters to the + * below thread function so it can do its thing. + * + * @relates handle_host_plugin_proxy + */ +using handle_host_plugin_parameters = std::pair; + StdIoCapture::StdIoCapture(boost::asio::io_context& io_context, int file_descriptor) : pipe(io_context), @@ -76,24 +80,23 @@ GroupBridge::GroupBridge(boost::filesystem::path group_socket_path) async_log_pipe_lines(stderr_redirect.pipe, stderr_buffer, "[STDERR] "); } -void GroupBridge::handle_host_plugin(const PluginParameters parameters) { +void GroupBridge::handle_host_plugin(const GroupRequest request) { // At this point the `active_plugins` map will already contain a copy of // `parameters` along with this thread's handle // The initialization process for a plugin is identical to that in // `../individual-host.cpp` - logger.log("Received request to host '" + parameters.plugin_path + - "' using socket '" + parameters.socket_path + "'"); + logger.log("Received request to host '" + request.plugin_path + + "' using socket '" + request.socket_path + "'"); try { - Vst2Bridge bridge(parameters.plugin_path, parameters.socket_path); - logger.log("Finished initializing '" + parameters.plugin_path + "'"); + Vst2Bridge bridge(request.plugin_path, request.socket_path); + logger.log("Finished initializing '" + request.plugin_path + "'"); // Blocks the main thread until the plugin shuts down bridge.handle_dispatch(); - logger.log("" + parameters.plugin_path + "' has exited"); + logger.log("" + request.plugin_path + "' has exited"); } catch (const std::runtime_error& error) { - logger.log("Error while initializing '" + parameters.plugin_path + - "':"); + logger.log("Error while initializing '" + request.plugin_path + "':"); logger.log(error.what()); } @@ -102,7 +105,7 @@ void GroupBridge::handle_host_plugin(const PluginParameters parameters) { // plugins. If no active plugins remain, then we'll terminate std::lock_guard lock(active_plugins_mutex); - active_plugins.erase(parameters); + active_plugins.erase(request); if (active_plugins.size() == 0) { logger.log("All plugins have exited, shutting down the group process"); io_context.stop(); @@ -140,7 +143,7 @@ void GroupBridge::accept_requests() { // still active so we can terminate early if it is not, but in this // case the yabridge instance has to determine that this process is // still running. - const auto parameters = read_object(socket); + const auto parameters = read_object(socket); // Collisions in the generated socket names should be very rare, but // it could in theory happen @@ -149,7 +152,7 @@ void GroupBridge::accept_requests() { // CreateThread() doesn't support multiple arguments and requires // manualy memory management. handle_host_plugin_parameters* thread_params = - new std::pair(this, parameters); + new std::pair(this, parameters); active_plugins[parameters] = Win32Thread(handle_host_plugin_proxy, &thread_params); @@ -209,7 +212,7 @@ uint32_t WINAPI handle_host_plugin_proxy(void* param) { // need to use manual memory management. auto thread_params = static_cast(param); GroupBridge* instance = thread_params->first; - PluginParameters parameters = thread_params->second; + GroupRequest parameters = thread_params->second; delete thread_params; instance->handle_host_plugin(parameters); diff --git a/src/wine-host/bridges/group.h b/src/wine-host/bridges/group.h index e68a7177..33b79b99 100644 --- a/src/wine-host/bridges/group.h +++ b/src/wine-host/bridges/group.h @@ -128,15 +128,15 @@ class GroupBridge { * `active_plugins` map. If this causes the vector to become empty, we will * terminate this process. * - * @param parameters Information about the plugin to launch, i.e. the path - * to the plugin and the path of the socket endpoint that will be used for + * @param request Information about the plugin to launch, i.e. the path to + * the plugin and the path of the socket endpoint that will be used for * communication. * * @note In the case that the process starts but no plugin gets initiated, * then the process will never exit on its own. This should not happen * though. */ - void handle_host_plugin(const PluginParameters parameters); + void handle_host_plugin(const GroupRequest request); /** * Listen for new requests to spawn plugins within this process and handle @@ -148,7 +148,7 @@ class GroupBridge { /** * Listen on the group socket for incoming requests to host a new plugin * within this group process. This will asynchronously listen on the socket, - * and for any connection made it will retrieve a `PluginParameters` object + * and for any connection made it will retrieve a `GroupRequest` object * containing information about the plugin to host and then spawn a new * thread to start hosting that plugin. * @@ -208,7 +208,7 @@ class GroupBridge { * the amount of plugins currently running with their associated thread * handles. */ - std::unordered_map active_plugins; + std::unordered_map active_plugins; /** * A mutex to prevent two threads from simultaneously accessing the plugins * map, and also to prevent `handle_host_plugin()` from terminating the