X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fcopy_to_drive_job.cc;h=c6f9c84b0cea67867ad9f6cc8835a6aae4cfea16;hb=ff639b3cf30afcc097bfd21d39c8d15f466cadd6;hp=173d286f5f54a499ca65468a46916e13b2d3285a;hpb=001ba1644fc6aa54f91fcaaa62ae7e5de2313bc1;p=dcpomatic.git diff --git a/src/lib/copy_to_drive_job.cc b/src/lib/copy_to_drive_job.cc index 173d286f5..c6f9c84b0 100644 --- a/src/lib/copy_to_drive_job.cc +++ b/src/lib/copy_to_drive_job.cc @@ -18,44 +18,53 @@ */ -#include "disk_writer_messages.h" -#include "copy_to_drive_job.h" + #include "compose.hpp" -#include "exceptions.h" +#include "copy_to_drive_job.h" #include "dcpomatic_log.h" +#include "disk_writer_messages.h" +#include "exceptions.h" #include #include -#include #include +#include +#include #include #include #include -#include #include "i18n.h" -using std::string; + using std::cout; using std::min; -using boost::shared_ptr; +using std::shared_ptr; +using std::string; using boost::optional; using dcp::raw_convert; -CopyToDriveJob::CopyToDriveJob (boost::filesystem::path dcp, Drive drive, Nanomsg& nanomsg) + +CopyToDriveJob::CopyToDriveJob(std::vector const& dcps, Drive drive, Nanomsg& nanomsg) : Job (shared_ptr()) - , _dcp (dcp) + , _dcps (dcps) , _drive (drive) , _nanomsg (nanomsg) { } + string CopyToDriveJob::name () const { - return String::compose (_("Copying %1 to %2"), _dcp.filename().string(), _drive.description()); + if (_dcps.size() == 1) { + return String::compose(_("Copying %1\nto %2"), _dcps[0].filename().string(), _drive.description()); + } + + return String::compose(_("Copying DCPs to %1"), _drive.description()); } + string CopyToDriveJob::json_name () const { @@ -65,12 +74,28 @@ CopyToDriveJob::json_name () const void CopyToDriveJob::run () { - LOG_DISK("Sending write request to disk writer for %1 %2", _dcp.string(), _drive.device_for_write()); - if (!_nanomsg.send(String::compose(DISK_WRITER_WRITE "\n%1\n%2\n", _dcp.string(), _drive.device_for_write()), 2000)) { + LOG_DISK("Sending write requests to disk %1 for:", _drive.device()); + for (auto dcp: _dcps) { + LOG_DISK("%1", dcp.string()); + } + + string request = String::compose(DISK_WRITER_WRITE "\n%1\n", _drive.device()); + for (auto dcp: _dcps) { + request += String::compose("%1\n", dcp.string()); + } + request += "\n"; + if (!_nanomsg.send(request, 2000)) { + LOG_DISK_NC("Failed to send write request."); throw CommunicationFailedError (); } - bool formatting = false; + enum State { + SETUP, + FORMAT, + COPY, + VERIFY + } state = SETUP; + while (true) { optional s = _nanomsg.receive (10000); if (!s) { @@ -80,19 +105,33 @@ CopyToDriveJob::run () set_state (FINISHED_OK); return; } else if (*s == DISK_WRITER_ERROR) { - optional const m = _nanomsg.receive (500); - optional const n = _nanomsg.receive (500); + 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_FORMATTING) { - sub ("Formatting drive"); - set_progress_unknown (); - formatting = true; - } else if (*s == DISK_WRITER_PROGRESS) { - if (formatting) { - sub ("Copying DCP"); - formatting = false; + } else if (*s == DISK_WRITER_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) { + 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) { + if (state == COPY) { + sub (_("Verifying copied files")); + state = VERIFY; } - optional progress = _nanomsg.receive (500); + auto progress = _nanomsg.receive (500); if (progress) { set_progress (raw_convert(*progress)); }