commit 059dabc10dced9b687e8ac7e355ca47715922097
parent 03828f497987726fec84017413c0f96707b67fff
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date: Sun, 8 Aug 2021 01:57:00 +0200
More work
Diffstat:
4 files changed, 40 insertions(+), 41 deletions(-)
diff --git a/examples/gui/application.cc b/examples/gui/application.cc
@@ -8,6 +8,10 @@
Application::Application(int argc, char **argv)
: QGuiApplication(argc, argv), quickView_(new QQuickView()) {
+ bool waitForDebbugger = true;
+ while (waitForDebbugger)
+ ;
+
QCommandLineParser parser;
QCommandLineOption qmlOpt("qml", tr("path to the QML skin"), tr("path"));
@@ -24,12 +28,12 @@ Application::Application(int argc, char **argv)
auto socket = parser.value(socketOpt).toULongLong();
socketReadNotifier_ = new QSocketNotifier(socket, QSocketNotifier::Read, this);
- connect(
- socketReadNotifier_,
- &QSocketNotifier::activated,
- [this](QSocketDescriptor socket, QSocketNotifier::Type type) {
- printf("ON READ\n");
- remoteChannel_->onRead(); });
+ connect(socketReadNotifier_,
+ &QSocketNotifier::activated,
+ [this](QSocketDescriptor socket, QSocketNotifier::Type type) {
+ printf("ON READ\n");
+ remoteChannel_->onRead();
+ });
socketWriteNotifier_ = new QSocketNotifier(socket, QSocketNotifier::Write, this);
connect(
@@ -60,6 +64,7 @@ void Application::modifyFd(clap_fd_flags flags) {
}
void Application::onMessage(const clap::RemoteChannel::Message &msg) {
+ printf("ON MESSAGE\n");
switch (msg.type) {
case clap::messages::kDefineParameterRequest: {
clap::messages::DefineParameterRequest rq;
@@ -80,9 +85,6 @@ void Application::onMessage(const clap::RemoteChannel::Message &msg) {
}
case clap::messages::kShowRequest: {
- clap::messages::ShowRequest rq;
- msg.get(rq);
-
quickView_->show();
clap::messages::ShowResponse rp;
remoteChannel_->sendMessageAsync(rp);
@@ -90,9 +92,6 @@ void Application::onMessage(const clap::RemoteChannel::Message &msg) {
}
case clap::messages::kHideRequest: {
- clap::messages::HideRequest rq;
- msg.get(rq);
-
quickView_->hide();
clap::messages::HideResponse rp;
remoteChannel_->sendMessageAsync(rp);
@@ -100,9 +99,6 @@ void Application::onMessage(const clap::RemoteChannel::Message &msg) {
}
case clap::messages::kSizeRequest: {
- clap::messages::SizeRequest rq;
- msg.get(rq);
-
clap::messages::SizeResponse rp;
rp.width = quickView_->width();
rp.height = quickView_->height();
diff --git a/examples/io/buffer.hh b/examples/io/buffer.hh
@@ -16,26 +16,33 @@ namespace clap {
Buffer<T, CAPACITY> &operator=(const Buffer<T, CAPACITY> &) = delete;
Buffer<T, CAPACITY> &operator=(Buffer<T, CAPACITY> &&) = delete;
- const T *readData() const noexcept { return &data_[roff_]; }
+ const T *readPtr() const noexcept { return &data_[roff_]; }
size_t readAvail() const noexcept { return woff_ - roff_; }
- void read(size_t bytes) noexcept {
- roff_ += bytes;
+
+ T *writePtr() noexcept { return &data_[woff_]; }
+ size_t writeAvail() const noexcept { return CAPACITY - woff_; }
+
+ /* Consume nbytes from the buffer */
+ void read(size_t nbytes) noexcept {
+ roff_ += nbytes;
+ assert(checkInvariants());
+ }
+
+ /* Produce nbytes into the buffer */
+ void wrote(size_t nbytes) noexcept {
+ woff_ += nbytes;
assert(checkInvariants());
}
void write(const T *&data, size_t &size) {
- auto avail = std::min(size, writeAvail());
+ size_t avail = writeAvail();
+ avail = std::min(size, avail);
auto end = data + avail;
- std::copy(data, data + avail, writeData());
+ std::copy(data, end, writePtr());
+ wrote(size);
data = end;
size -= avail;
}
- T *writeData() noexcept { return &data_[woff_]; }
- size_t writeAvail() const noexcept { return CAPACITY - woff_; }
- void wrote(size_t bytes) noexcept {
- woff_ += bytes;
- assert(checkInvariants());
- }
void rewind() noexcept {
if (woff_ == 0)
@@ -43,7 +50,7 @@ namespace clap {
// this is inefficient but simple
// TODO: use scatter/gather IO
- auto rptr = readData();
+ auto rptr = readPtr();
auto avail = readAvail();
std::copy(rptr, rptr + avail, &data_[0]);
diff --git a/examples/io/remote-channel.cc b/examples/io/remote-channel.cc
@@ -23,7 +23,7 @@ namespace clap {
RemoteChannel::~RemoteChannel() { close(); }
void RemoteChannel::onRead() {
- ssize_t nbytes = ::read(socket_, inputBuffer_.writeData(), inputBuffer_.writeAvail());
+ ssize_t nbytes = ::read(socket_, inputBuffer_.writePtr(), inputBuffer_.writeAvail());
if (nbytes < 0) {
if (errno == EWOULDBLOCK || errno == EAGAIN || errno == EINTR)
return;
@@ -64,9 +64,8 @@ namespace clap {
while (!outputBuffers_.empty()) {
auto &buffer = outputBuffers_.front();
- auto avail = buffer.readAvail();
- while (avail > 0) {
- auto nbytes = ::write(socket_, buffer.readData(), avail);
+ for (auto avail = buffer.readAvail(); avail > 0; avail = buffer.readAvail()) {
+ auto nbytes = ::write(socket_, buffer.readPtr(), avail);
if (nbytes == -1) {
if (errno == EWOULDBLOCK || errno == EAGAIN || errno == EINTR) {
modifyFd(CLAP_FD_READ | CLAP_FD_WRITE);
@@ -77,9 +76,7 @@ namespace clap {
return;
}
- buffer.wrote(nbytes);
- avail -= nbytes;
- assert(avail == buffer.readAvail());
+ buffer.read(nbytes);
}
outputBuffers_.pop();
@@ -110,8 +107,8 @@ namespace clap {
}
void RemoteChannel::processInput() {
- while (inputBuffer_.readAvail() > 12) {
- const auto *data = inputBuffer_.readData();
+ while (inputBuffer_.readAvail() >= 12) {
+ const auto *data = inputBuffer_.readPtr();
Message msg;
std::memcpy(&msg.type, data, 4);
@@ -173,7 +170,7 @@ namespace clap {
pfd.events = POLLIN | (ioFlags_ & CLAP_FD_WRITE ? POLLOUT : 0);
pfd.revents = 0;
- int ret = ::poll(&pfd, 1, 0);
+ int ret = ::poll(&pfd, 1, -1);
if (ret < 1)
// TODO error handling
return;
@@ -184,4 +181,4 @@ namespace clap {
onRead();
#endif
}
-} // namespace clap
-\ No newline at end of file
+} // namespace clap
diff --git a/examples/io/remote-channel.hh b/examples/io/remote-channel.hh
@@ -115,8 +115,8 @@ namespace clap {
const bool cookieHalf_;
uint32_t nextCookie_ = 0;
- const MessageHandler &handler_;
- std::unordered_map<uint32_t /* cookie */, const MessageHandler &> syncHandlers_;
+ MessageHandler handler_;
+ std::unordered_map<uint32_t /* cookie */, const MessageHandler&> syncHandlers_;
EventControl &evControl_;
clap_fd socket_;
clap_fd_flags ioFlags_ = 0;