From 3e6bf3adfdb8ba76b3b6d08fbbf0d35976a0bd91 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 20 May 2021 14:46:10 +0200 Subject: [PATCH] Allow overriding sending behaviour for VST2 events Now we can implement mutual recursion for VST2 plugins. Wish we didn't have to. --- src/common/communication/vst2.cpp | 7 +++++++ src/common/communication/vst2.h | 19 ++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/common/communication/vst2.cpp b/src/common/communication/vst2.cpp index a478094a..2f7fc2a3 100644 --- a/src/common/communication/vst2.cpp +++ b/src/common/communication/vst2.cpp @@ -70,3 +70,10 @@ intptr_t DefaultDataConverter::return_value(const int /*opcode*/, const intptr_t original) const { return original; } + +EventResult DefaultDataConverter::send_event( + boost::asio::local::stream_protocol::socket& socket, + const Event& event) const { + write_object(socket, event); + return read_object(socket); +} diff --git a/src/common/communication/vst2.h b/src/common/communication/vst2.h index cad92732..51bf3efe 100644 --- a/src/common/communication/vst2.h +++ b/src/common/communication/vst2.h @@ -76,6 +76,16 @@ class DefaultDataConverter { */ virtual intptr_t return_value(const int opcode, const intptr_t original) const; + + /** + * Send an event over the socket. The default implementation will just send + * the event over the socket, and then wait for the response to be sent + * back. This can be overridden to use `MutualRecursionHelper::fork()` for + * specific opcodes to allow mutually recursive calling sequences. + */ + virtual EventResult send_event( + boost::asio::local::stream_protocol::socket& socket, + const Event& event) const; }; /** @@ -185,11 +195,14 @@ class Vst2EventHandler : public AdHocSocketHandler { // A socket only handles a single request at a time as to prevent // messages from arriving out of order. `AdHocSocketHandler::send()` // will either use a long-living primary socket, or if that's currently - // in use it will spawn a new socket for us. + // in use it will spawn a new socket for us. We'll then use + // `DefaultDataConverter::send_event()` to actually write and read data + // from the socket, so we can override this for specific function calls + // that potentially need to have their responses handled on the same + // calling thread (i.e. mutual recursion). const EventResult response = this->send( [&](boost::asio::local::stream_protocol::socket& socket) { - write_object(socket, event); - return read_object(socket); + return data_converter.send_event(socket, event); }); if (logging) {