clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

commit 3ae01dda535bff34a94546c2c1d43b8d5699d9bf
parent 059dabc10dced9b687e8ac7e355ca47715922097
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Sun,  8 Aug 2021 11:18:26 +0200

Fix RPC's responses

Diffstat:
Mexamples/gui/application.cc | 14+++++++-------
Mexamples/io/remote-channel.cc | 5++---
Mexamples/io/remote-channel.hh | 10++++++++--
Mexamples/plugins/remote-gui.cc | 16++++++++--------
4 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/examples/gui/application.cc b/examples/gui/application.cc @@ -8,7 +8,7 @@ Application::Application(int argc, char **argv) : QGuiApplication(argc, argv), quickView_(new QQuickView()) { - bool waitForDebbugger = true; + bool waitForDebbugger = false; while (waitForDebbugger) ; @@ -80,29 +80,29 @@ void Application::onMessage(const clap::RemoteChannel::Message &msg) { quickView_->setParent(hostWindow_.get()); clap::messages::AttachResponse rp; - remoteChannel_->sendMessageAsync(rp); + remoteChannel_->sendResponseAsync(rp, msg.cookie); break; } case clap::messages::kShowRequest: { quickView_->show(); clap::messages::ShowResponse rp; - remoteChannel_->sendMessageAsync(rp); + remoteChannel_->sendResponseAsync(rp, msg.cookie); break; } case clap::messages::kHideRequest: { quickView_->hide(); clap::messages::HideResponse rp; - remoteChannel_->sendMessageAsync(rp); + remoteChannel_->sendResponseAsync(rp, msg.cookie); break; } case clap::messages::kSizeRequest: { clap::messages::SizeResponse rp; - rp.width = quickView_->width(); - rp.height = quickView_->height(); - remoteChannel_->sendMessageAsync(rp); + rp.width = 400; //quickView_->width(); + rp.height = 500; //quickView_->height(); + remoteChannel_->sendResponseAsync(rp, msg.cookie); break; } } diff --git a/examples/io/remote-channel.cc b/examples/io/remote-channel.cc @@ -34,6 +34,7 @@ namespace clap { inputBuffer_.wrote(nbytes); processInput(); + inputBuffer_.rewind(); } void RemoteChannel::write(const void *_data, size_t size) { @@ -123,15 +124,13 @@ namespace clap { auto it = syncHandlers_.find(msg.cookie); if (it != syncHandlers_.end()) { it->second(msg); - syncHandlers_.erase(msg.cookie); + syncHandlers_.erase(it); } else { handler_(msg); } inputBuffer_.read(totalSize); } - - inputBuffer_.rewind(); } bool RemoteChannel::sendMessageAsync(const Message &msg) { diff --git a/examples/io/remote-channel.hh b/examples/io/remote-channel.hh @@ -53,6 +53,7 @@ namespace clap { void set(const T &msg) noexcept { type = T::type; data = &msg; + size = sizeof (T); } }; @@ -72,12 +73,17 @@ namespace clap { uint32_t computeNextCookie() noexcept; template <typename Request> - bool sendMessageAsync(const Request &request) { + bool sendRequestAsync(const Request &request) { return sendMessageAsync(RemoteChannel::Message(request, computeNextCookie())); } + template <typename Response> + bool sendResponseAsync(const Response &response, uint32_t cookie) { + return sendMessageAsync(RemoteChannel::Message(response, cookie)); + } + template <typename Request, typename Response> - bool sendMessageSync(const Request &request, Response &response) { + bool sendRequestSync(const Request &request, Response &response) { sendMessageSync(RemoteChannel::Message(request, computeNextCookie()), [&response](const RemoteChannel::Message &m) { m.get(response); }); return true; diff --git a/examples/plugins/remote-gui.cc b/examples/plugins/remote-gui.cc @@ -84,14 +84,14 @@ namespace clap { } void RemoteGui::defineParameter(const clap_param_info &info) noexcept { - channel_->sendMessageAsync(messages::DefineParameterRequest{info}); + channel_->sendRequestAsync(messages::DefineParameterRequest{info}); } bool RemoteGui::size(uint32_t *width, uint32_t *height) noexcept { messages::SizeRequest request; messages::SizeResponse response; - if (!channel_->sendMessageSync(request, response)) + if (!channel_->sendRequestSync(request, response)) return false; *width = response.width; @@ -100,21 +100,21 @@ namespace clap { } void RemoteGui::setScale(double scale) noexcept { - channel_->sendMessageAsync(messages::SetScaleRequest{scale}); + channel_->sendRequestAsync(messages::SetScaleRequest{scale}); } bool RemoteGui::show() noexcept { messages::ShowRequest request; messages::ShowResponse response; - return channel_->sendMessageSync(request, response); + return channel_->sendRequestSync(request, response); } bool RemoteGui::hide() noexcept { messages::HideRequest request; messages::HideResponse response; - return channel_->sendMessageSync(request, response); + return channel_->sendRequestSync(request, response); } void RemoteGui::destroy() noexcept { @@ -124,7 +124,7 @@ namespace clap { messages::DestroyRequest request; messages::DestroyResponse response; - channel_->sendMessageSync(request, response); + channel_->sendRequestSync(request, response); plugin_.hostEventLoop_->unregister_fd(plugin_.host_, channel_->fd()); channel_.reset(); } @@ -138,7 +138,7 @@ namespace clap { messages::AttachWin32Request request{window}; messages::AttachResponse response; - return channel_->sendMessageSync(request, response); + return channel_->sendRequestSync(request, response); } bool RemoteGui::attachX11(const char *display_name, unsigned long window) noexcept { @@ -148,7 +148,7 @@ namespace clap { request.window = window; std::snprintf(request.display, sizeof(request.display), "%s", display_name); - return channel_->sendMessageSync(request, response); + return channel_->sendRequestSync(request, response); } } // namespace clap \ No newline at end of file