X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fcopy_to_drive_job.cc;h=9ddedfe62dfc8c946f38a1fd7a65755bf8bccd7d;hb=b1e22dff981fb86ae04b12bb5a064e61030793a8;hp=fe35daba6c4b0b1b6061617945fd44ed1719e568;hpb=a16523af5f70b60f4890f198f6214177077a9c1d;p=dcpomatic.git diff --git a/src/lib/copy_to_drive_job.cc b/src/lib/copy_to_drive_job.cc index fe35daba6..9ddedfe62 100644 --- a/src/lib/copy_to_drive_job.cc +++ b/src/lib/copy_to_drive_job.cc @@ -22,6 +22,7 @@ #include "copy_to_drive_job.h" #include "compose.hpp" #include "exceptions.h" +#include "dcpomatic_log.h" #include #include #include @@ -36,7 +37,8 @@ using std::string; using std::cout; using std::min; -using boost::shared_ptr; +using std::shared_ptr; +using boost::optional; using dcp::raw_convert; CopyToDriveJob::CopyToDriveJob (boost::filesystem::path dcp, Drive drive, Nanomsg& nanomsg) @@ -51,7 +53,7 @@ CopyToDriveJob::CopyToDriveJob (boost::filesystem::path dcp, Drive drive, Nanoms string CopyToDriveJob::name () const { - return String::compose (_("Copying %1 to %2"), _dcp.filename().string(), _drive.description()); + return String::compose (_("Copying %1\nto %2"), _dcp.filename().string(), _drive.description()); } string @@ -63,30 +65,58 @@ CopyToDriveJob::json_name () const void CopyToDriveJob::run () { - if (!_nanomsg.nonblocking_send(String::compose(DISK_WRITER_WRITE "\n%1\n%2\n", _dcp.string(), _drive.internal_name()))) { - throw CopyError ("Could not communicate with writer process", 0); + LOG_DISK("Sending write request to disk writer for %1 %2", _dcp.string(), _drive.device()); + if (!_nanomsg.send(String::compose(DISK_WRITER_WRITE "\n%1\n%2\n", _dcp.string(), _drive.device()), 2000)) { + LOG_DISK_NC("Failed to send write request."); + throw CommunicationFailedError (); } - bool formatting = false; + enum State { + SETUP, + FORMAT, + COPY, + VERIFY + } state = SETUP; + while (true) { - string s = _nanomsg.blocking_get (); - if (s == DISK_WRITER_OK) { + optional s = _nanomsg.receive (10000); + if (!s) { + continue; + } + if (*s == DISK_WRITER_OK) { set_state (FINISHED_OK); return; - } else if (s == DISK_WRITER_ERROR) { - string const m = _nanomsg.blocking_get (); - string const n = _nanomsg.blocking_get (); - throw CopyError (m, raw_convert(n)); - } 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_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) { + 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; + } + auto progress = _nanomsg.receive (500); + if (progress) { + set_progress (raw_convert(*progress)); } - set_progress (raw_convert(_nanomsg.blocking_get())); } } }