summaryrefslogtreecommitdiff
path: root/src/lib/disk_writer_messages.cc
blob: e42e80ec628c27c463a7d6dc8bf63f4027c9e4d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
    Copyright (C) 2023 Carl Hetherington <cth@carlh.net>

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/


#include "dcpomatic_assert.h"
#include "disk_writer_messages.h"
#include "nanomsg.h"


using boost::optional;


boost::optional<DiskWriterBackEndResponse>
DiskWriterBackEndResponse::read_from_nanomsg(Nanomsg& nanomsg, int timeout)
{
	auto s = nanomsg.receive(timeout);
	if (!s) {
		return {};
	}
	if (*s == DISK_WRITER_OK) {
		return DiskWriterBackEndResponse::ok();
	} else if (*s == DISK_WRITER_ERROR) {
		auto const m = nanomsg.receive(500);
		auto const n = nanomsg.receive(500);
		return DiskWriterBackEndResponse::error(m.get_value_or(""), dcp::locale_convert<int>(n.get_value_or("0")));
	} else if (*s == DISK_WRITER_PONG) {
		return DiskWriterBackEndResponse::pong();
	} else if (*s == DISK_WRITER_FORMAT_PROGRESS) {
		auto progress = nanomsg.receive(500);
		return DiskWriterBackEndResponse::format_progress(dcp::locale_convert<float>(progress.get_value_or("0")));
	} else if (*s == DISK_WRITER_COPY_PROGRESS) {
		auto progress = nanomsg.receive(500);
		return DiskWriterBackEndResponse::copy_progress(dcp::locale_convert<float>(progress.get_value_or("0")));
	} else if (*s == DISK_WRITER_VERIFY_PROGRESS) {
		auto progress = nanomsg.receive(500);
		return DiskWriterBackEndResponse::verify_progress(dcp::locale_convert<float>(progress.get_value_or("0")));
	} else {
		DCPOMATIC_ASSERT(false);
	}

	return {};
}