2 Copyright (C) 2023 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 "dcpomatic_assert.h"
23 #include "disk_writer_messages.h"
27 using boost::optional;
30 boost::optional<DiskWriterBackEndResponse>
31 DiskWriterBackEndResponse::read_from_nanomsg(Nanomsg& nanomsg, int timeout)
33 auto s = nanomsg.receive(timeout);
37 if (*s == DISK_WRITER_OK) {
38 return DiskWriterBackEndResponse::ok();
39 } else if (*s == DISK_WRITER_ERROR) {
40 auto const m = nanomsg.receive(500);
41 auto const n = nanomsg.receive(500);
42 return DiskWriterBackEndResponse::error(m.get_value_or(""), dcp::locale_convert<int>(n.get_value_or("0")));
43 } else if (*s == DISK_WRITER_PONG) {
44 return DiskWriterBackEndResponse::pong();
45 } else if (*s == DISK_WRITER_FORMAT_PROGRESS) {
46 auto progress = nanomsg.receive(500);
47 return DiskWriterBackEndResponse::format_progress(dcp::locale_convert<float>(progress.get_value_or("0")));
48 } else if (*s == DISK_WRITER_COPY_PROGRESS) {
49 auto progress = nanomsg.receive(500);
50 return DiskWriterBackEndResponse::copy_progress(dcp::locale_convert<float>(progress.get_value_or("0")));
51 } else if (*s == DISK_WRITER_VERIFY_PROGRESS) {
52 auto progress = nanomsg.receive(500);
53 return DiskWriterBackEndResponse::verify_progress(dcp::locale_convert<float>(progress.get_value_or("0")));
55 DCPOMATIC_ASSERT(false);