clap

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

commit 73ca1b6144ccb1628ed8573fe8041e3adda5f519
parent 158197351681ae692be73811b98aa4ab7114e268
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Tue, 29 Jun 2021 12:33:11 +0200

Much easier without boost

Diffstat:
Mexamples/plugins/CMakeLists.txt | 2++
Aexamples/plugins/remote-channel.cc | 21+++++++++++++++++++++
Aexamples/plugins/remote-channel.hh | 20++++++++++++++++++++
Mexamples/plugins/remote-gui.cc | 45++++++++++++++++++++++++++++++++++++++++++---
Mexamples/plugins/remote-gui.hh | 17+++++++++++++----
5 files changed, 98 insertions(+), 7 deletions(-)

diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt @@ -13,6 +13,8 @@ add_library( abstract-gui.hh remote-gui.hh remote-gui.cc + remote-channel.hh + remote-channel.cc dc-offset/dc-offset.hh dc-offset/dc-offset.cc diff --git a/examples/plugins/remote-channel.cc b/examples/plugins/remote-channel.cc @@ -0,0 +1,20 @@ +#ifdef __unix__ +# include <unistd.h> +#endif + +#include "remote-channel.hh" + +namespace clap { + + RemoteChannel::RemoteChannel(int socket) : socket_(socket) {} + + RemoteChannel::~RemoteChannel() { close(); } + + void RemoteChannel::close() { + if (socket_ == -1) + return; + + ::close(socket_); + socket_ = -1; + } +} // namespace clap +\ No newline at end of file diff --git a/examples/plugins/remote-channel.hh b/examples/plugins/remote-channel.hh @@ -0,0 +1,19 @@ +#pragma once + +namespace clap { + class RemoteChannel final { + public: + RemoteChannel(int socket); + ~RemoteChannel(); + + RemoteChannel(const RemoteChannel&) = delete; + RemoteChannel(RemoteChannel&&) = delete; + RemoteChannel& operator=(const RemoteChannel&) = delete; + RemoteChannel& operator=(RemoteChannel&&) = delete; + + void close(); + + private: + int socket_; + }; +} // namespace clap +\ No newline at end of file diff --git a/examples/plugins/remote-gui.cc b/examples/plugins/remote-gui.cc @@ -1,12 +1,51 @@ +#ifdef __unix__ +# include <fcntl.h> +# include <sys/socket.h> +#endif + +#include <cassert> + #include "remote-gui.hh" namespace clap { bool RemoteGui::spawn() { - assert(!child_.running()); + assert(child_ == -1); + +#ifdef __unix__ + assert(!channel_); + + /* create a socket pair */ + int sockets[2]; + if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sockets)) { + return false; + } + + child_ = ::fork(); + if (child_ == -1) { + ::close(sockets[0]); + ::close(sockets[1]); + return false; + } + + if (child_ == 0) { + // Child + ::close(sockets[0]); + char socketStr[16]; + ::snprintf(socketStr, sizeof(socketStr), "%d", sockets[1]); + ::execl("clap-gui", "--socket", socketStr); + std::terminate(); + } else { + // Parent + ::close(sockets[1]); + } + + channel_.reset(new RemoteChannel(sockets[0])); - child_ = boost::process::child("clap-gui", boost::process::std_out = wpipe_); - return child_.running(); + return true; +#else + return false; +#endif } } // namespace clap \ No newline at end of file diff --git a/examples/plugins/remote-gui.hh b/examples/plugins/remote-gui.hh @@ -1,8 +1,13 @@ #pragma once -#include <boost/process.hpp> +#ifdef __unix__ +# include <sys/wait.h> +#endif + +#include <memory> #include "abstract-gui.hh" +#include "remote-channel.hh" namespace clap { class RemoteGui : public AbstractGui { @@ -23,8 +28,12 @@ namespace clap { void close() noexcept override; private: - boost::process::child child_; - boost::process::pipe wpipe_; - boost::process::pipe rpipe_; + std::unique_ptr<RemoteChannel> channel_; + +#ifdef __unix__ + pid_t child_ = -1; +#else + HANDLE socket_ = nullptr; +#endif }; } // namespace clap \ No newline at end of file