From b09eed77ec297dd05c112f4e93d6db5641053fe1 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 11 Jan 2023 16:32:23 +0100 Subject: [PATCH] Use DiskWriterBackEndResponse, and add some more information to the unmount error. --- src/lib/copy_to_drive_job.cc | 40 ++++++++++++++++-------------------- src/tools/dcpomatic_disk.cc | 16 +++++++++------ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/lib/copy_to_drive_job.cc b/src/lib/copy_to_drive_job.cc index c6f9c84b0..9d3a6721a 100644 --- a/src/lib/copy_to_drive_job.cc +++ b/src/lib/copy_to_drive_job.cc @@ -97,44 +97,40 @@ CopyToDriveJob::run () } state = SETUP; while (true) { - optional s = _nanomsg.receive (10000); - if (!s) { + auto response = DiskWriterBackEndResponse::read_from_nanomsg(_nanomsg, 10000); + if (!response) { continue; } - if (*s == DISK_WRITER_OK) { + + switch (response->type()) { + case DiskWriterBackEndResponse::Type::OK: set_state (FINISHED_OK); return; - } else if (*s == DISK_WRITER_ERROR) { - auto const m = _nanomsg.receive (500); - auto const n = _nanomsg.receive (500); - throw CopyError (m.get_value_or("Unknown"), raw_convert(n.get_value_or("0"))); - } else if (*s == DISK_WRITER_FORMAT_PROGRESS) { + case DiskWriterBackEndResponse::Type::PONG: + break; + case DiskWriterBackEndResponse::Type::ERROR: + throw CopyError(response->error_message(), response->error_number()); + case DiskWriterBackEndResponse::Type::FORMAT_PROGRESS: if (state == SETUP) { sub (_("Formatting drive")); state = FORMAT; } - auto progress = _nanomsg.receive (500); - if (progress) { - set_progress (raw_convert(*progress)); - } - } else if (*s == DISK_WRITER_COPY_PROGRESS) { + set_progress(response->progress()); + break; + case DiskWriterBackEndResponse::Type::COPY_PROGRESS: if (state == FORMAT) { sub (_("Copying DCP")); state = COPY; } - auto progress = _nanomsg.receive (500); - if (progress) { - set_progress (raw_convert(*progress)); - } - } else if (*s == DISK_WRITER_VERIFY_PROGRESS) { + set_progress(response->progress()); + break; + case DiskWriterBackEndResponse::Type::VERIFY_PROGRESS: if (state == COPY) { sub (_("Verifying copied files")); state = VERIFY; } - auto progress = _nanomsg.receive (500); - if (progress) { - set_progress (raw_convert(*progress)); - } + set_progress(response->progress()); + break; } } } diff --git a/src/tools/dcpomatic_disk.cc b/src/tools/dcpomatic_disk.cc index a6ae58c8d..28799013f 100644 --- a/src/tools/dcpomatic_disk.cc +++ b/src/tools/dcpomatic_disk.cc @@ -284,11 +284,11 @@ private: auto ping = [this](int attempt) { if (_nanomsg.send(DISK_WRITER_PING "\n", 1000)) { - auto reply = _nanomsg.receive (1000); - if (reply && *reply == DISK_WRITER_PONG) { + auto reply = DiskWriterBackEndResponse::read_from_nanomsg(_nanomsg, 1000); + if (reply && reply->type() == DiskWriterBackEndResponse::Type::PONG) { return true; } else if (reply) { - LOG_DISK("Unexpected response %1 to ping received (attempt %2)", *reply, attempt); + LOG_DISK("Unexpected response %1 to ping received (attempt %2)", static_cast(reply->type()), attempt); } else { LOG_DISK("No reply received from ping (attempt %1)", attempt); } @@ -348,12 +348,16 @@ private: throw CommunicationFailedError (); } /* The reply may have to wait for the user to authenticate, so let's wait a while */ - auto reply = _nanomsg.receive (30000); - if (!reply || *reply != DISK_WRITER_OK) { + auto const reply = DiskWriterBackEndResponse::read_from_nanomsg(_nanomsg, 30000); + if (!reply || reply->type() != DiskWriterBackEndResponse::Type::OK) { auto m = make_wx( this, _("DCP-o-matic Disk Writer"), - wxString::Format(_("The drive %s could not be unmounted.\nClose any application that is using it, then try again."), std_to_wx(drive.description())) + wxString::Format( + _("The drive %s could not be unmounted.\nClose any application that is using it, then try again. (%s)"), + std_to_wx(drive.description()), + reply->error_message() + ) ); m->ShowModal (); return; -- 2.30.2