2 Copyright (C) 2019-2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "compose.hpp"
23 #include "copy_to_drive_job.h"
24 #include "dcpomatic_log.h"
25 #include "disk_writer_messages.h"
26 #include "exceptions.h"
27 #include <dcp/raw_convert.h>
28 #include <nanomsg/nn.h>
41 using std::shared_ptr;
43 using boost::optional;
44 using dcp::raw_convert;
47 CopyToDriveJob::CopyToDriveJob(std::vector<boost::filesystem::path> const& dcps, Drive drive, Nanomsg& nanomsg)
48 : Job (shared_ptr<Film>())
58 CopyToDriveJob::name () const
60 if (_dcps.size() == 1) {
61 return String::compose(_("Copying %1\nto %2"), _dcps[0].filename().string(), _drive.description());
64 return String::compose(_("Copying DCPs to %1"), _drive.description());
69 CopyToDriveJob::json_name () const
75 CopyToDriveJob::run ()
77 LOG_DISK("Sending write requests to disk %1 for:", _drive.device());
78 for (auto dcp: _dcps) {
79 LOG_DISK("%1", dcp.string());
82 string request = String::compose(DISK_WRITER_WRITE "\n%1\n", _drive.device());
83 for (auto dcp: _dcps) {
84 request += String::compose("%1\n", dcp.string());
87 if (!_nanomsg.send(request, 2000)) {
88 LOG_DISK_NC("Failed to send write request.");
89 throw CommunicationFailedError ();
100 optional<string> s = _nanomsg.receive (10000);
104 if (*s == DISK_WRITER_OK) {
105 set_state (FINISHED_OK);
107 } else if (*s == DISK_WRITER_ERROR) {
108 auto const m = _nanomsg.receive (500);
109 auto const n = _nanomsg.receive (500);
110 throw CopyError (m.get_value_or("Unknown"), raw_convert<int>(n.get_value_or("0")));
111 } else if (*s == DISK_WRITER_FORMAT_PROGRESS) {
112 if (state == SETUP) {
113 sub (_("Formatting drive"));
116 auto progress = _nanomsg.receive (500);
118 set_progress (raw_convert<float>(*progress));
120 } else if (*s == DISK_WRITER_COPY_PROGRESS) {
121 if (state == FORMAT) {
122 sub (_("Copying DCP"));
125 auto progress = _nanomsg.receive (500);
127 set_progress (raw_convert<float>(*progress));
129 } else if (*s == DISK_WRITER_VERIFY_PROGRESS) {
131 sub (_("Verifying copied files"));
134 auto progress = _nanomsg.receive (500);
136 set_progress (raw_convert<float>(*progress));