2 Copyright (C) 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 <boost/optional.hpp>
29 /* We have the front-end application dcpomatic2_disk and the back-end
30 * dcpomatic2_disk_writer. The communication is line-based, separated
38 #define DISK_WRITER_PING "P"
42 #define DISK_WRITER_PONG "O"
44 /* REQUEST TO WRITE DCP */
48 #define DISK_WRITER_WRITE "W"
50 // Internal name of the drive to write to
55 #define DISK_WRITER_OK "D"
58 #define DISK_WRITER_ERROR "E"
62 // the drive is being formatted, 40% done
63 #define DISK_WRITER_FORMAT_PROGRESS "F"
66 // data is being copied, 30% done
67 #define DISK_WRITER_COPY_PROGRESS "C"
70 // data is being verified, 60% done
71 #define DISK_WRITER_VERIFY_PROGRESS "V"
78 #define DISK_WRITER_QUIT "Q"
81 /* REQUEST TO UNMOUNT A DRIVE */
84 #define DISK_WRITER_UNMOUNT "U"
85 // XML representation of Drive object to unmount
93 class DiskWriterBackEndResponse
105 static DiskWriterBackEndResponse ok() {
106 return DiskWriterBackEndResponse(Type::OK);
109 static DiskWriterBackEndResponse error(std::string message, int number) {
110 auto r = DiskWriterBackEndResponse(Type::ERROR);
111 r._error_message = message;
112 r._error_number = number;
116 static DiskWriterBackEndResponse pong() {
117 return DiskWriterBackEndResponse(Type::PONG);
120 static DiskWriterBackEndResponse format_progress(float p) {
121 auto r = DiskWriterBackEndResponse(Type::FORMAT_PROGRESS);
126 static DiskWriterBackEndResponse copy_progress(float p) {
127 auto r = DiskWriterBackEndResponse(Type::COPY_PROGRESS);
132 static DiskWriterBackEndResponse verify_progress(float p) {
133 auto r = DiskWriterBackEndResponse(Type::VERIFY_PROGRESS);
138 static boost::optional<DiskWriterBackEndResponse> read_from_nanomsg(Nanomsg& nanomsg, int timeout);
144 std::string error_message() const {
145 return _error_message;
148 int error_number() const {
149 return _error_number;
152 float progress() const {
157 DiskWriterBackEndResponse(Type type)
162 std::string _error_message;
163 int _error_number = 0;