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 auto response = DiskWriterBackEndResponse::read_from_nanomsg(_nanomsg, 10000);
105 switch (response->type()) {
106 case DiskWriterBackEndResponse::Type::OK:
107 set_state (FINISHED_OK);
109 case DiskWriterBackEndResponse::Type::PONG:
111 case DiskWriterBackEndResponse::Type::ERROR:
112 throw CopyError(response->error_message(), response->ext4_error_number(), response->platform_error_number());
113 case DiskWriterBackEndResponse::Type::FORMAT_PROGRESS:
114 if (state == SETUP) {
115 sub (_("Formatting drive"));
118 set_progress(response->progress());
120 case DiskWriterBackEndResponse::Type::COPY_PROGRESS:
121 if (state == FORMAT) {
122 sub (_("Copying DCP"));
125 set_progress(response->progress());
127 case DiskWriterBackEndResponse::Type::VERIFY_PROGRESS:
129 sub (_("Verifying copied files"));
132 set_progress(response->progress());