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/>.
21 #include "disk_writer_messages.h"
22 #include "copy_to_drive_job.h"
23 #include "compose.hpp"
24 #include "exceptions.h"
25 #include "dcpomatic_log.h"
26 #include <dcp/raw_convert.h>
27 #include <nanomsg/nn.h>
40 using boost::shared_ptr;
41 using boost::optional;
42 using dcp::raw_convert;
44 CopyToDriveJob::CopyToDriveJob (boost::filesystem::path dcp, Drive drive, Nanomsg& nanomsg)
45 : Job (shared_ptr<Film>())
54 CopyToDriveJob::name () const
56 return String::compose (_("Copying %1 to %2"), _dcp.filename().string(), _drive.description());
60 CopyToDriveJob::json_name () const
66 CopyToDriveJob::run ()
68 LOG_DISK("Sending write request to disk writer for %1 %2", _dcp.string(), _drive.device_for_write());
69 if (!_nanomsg.send(String::compose(DISK_WRITER_WRITE "\n%1\n%2\n", _dcp.string(), _drive.device_for_write()), 2000)) {
70 throw CommunicationFailedError ();
73 bool formatting = false;
75 optional<string> s = _nanomsg.receive (10000);
79 if (*s == DISK_WRITER_OK) {
80 set_state (FINISHED_OK);
82 } else if (*s == DISK_WRITER_ERROR) {
83 optional<string> const m = _nanomsg.receive (500);
84 optional<string> const n = _nanomsg.receive (500);
85 throw CopyError (m.get_value_or("Unknown"), raw_convert<int>(n.get_value_or("0")));
86 } else if (*s == DISK_WRITER_FORMATTING) {
87 sub ("Formatting drive");
88 set_progress_unknown ();
90 } else if (*s == DISK_WRITER_PROGRESS) {
95 optional<string> progress = _nanomsg.receive (500);
97 set_progress (raw_convert<float>(*progress));