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"
61 // Additional error number (a platform-specific error from lwext4)
63 // the drive is being formatted, 40% done
64 #define DISK_WRITER_FORMAT_PROGRESS "F"
67 // data is being copied, 30% done
68 #define DISK_WRITER_COPY_PROGRESS "C"
71 // data is being verified, 60% done
72 #define DISK_WRITER_VERIFY_PROGRESS "V"
79 #define DISK_WRITER_QUIT "Q"
82 /* REQUEST TO UNMOUNT A DRIVE */
85 #define DISK_WRITER_UNMOUNT "U"
86 // XML representation of Drive object to unmount
94 class DiskWriterBackEndResponse
106 static DiskWriterBackEndResponse ok() {
107 return DiskWriterBackEndResponse(Type::OK);
110 static DiskWriterBackEndResponse error(std::string message, int ext4_number, int platform_number) {
111 auto r = DiskWriterBackEndResponse(Type::ERROR);
112 r._error_message = message;
113 r._ext4_error_number = ext4_number;
114 r._platform_error_number = platform_number;
118 static DiskWriterBackEndResponse pong() {
119 return DiskWriterBackEndResponse(Type::PONG);
122 static DiskWriterBackEndResponse format_progress(float p) {
123 auto r = DiskWriterBackEndResponse(Type::FORMAT_PROGRESS);
128 static DiskWriterBackEndResponse copy_progress(float p) {
129 auto r = DiskWriterBackEndResponse(Type::COPY_PROGRESS);
134 static DiskWriterBackEndResponse verify_progress(float p) {
135 auto r = DiskWriterBackEndResponse(Type::VERIFY_PROGRESS);
140 static boost::optional<DiskWriterBackEndResponse> read_from_nanomsg(Nanomsg& nanomsg, int timeout);
142 bool write_to_nanomsg(Nanomsg& nanomsg, int timeout) const;
148 std::string error_message() const {
149 return _error_message;
152 int ext4_error_number() const {
153 return _ext4_error_number;
156 int platform_error_number() const {
157 return _platform_error_number;
160 float progress() const {
165 DiskWriterBackEndResponse(Type type)
170 std::string _error_message;
171 int _ext4_error_number = 0;
172 int _platform_error_number = 0;