summaryrefslogtreecommitdiff
path: root/src/lib/disk_writer_messages.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-01-11 16:31:56 +0100
committerCarl Hetherington <cth@carlh.net>2023-01-29 20:58:25 +0100
commit50314d71c36895cab87c44be772589fafea894f8 (patch)
treed7ee9c95e85e08b45e0a5992e0acae418808f75b /src/lib/disk_writer_messages.cc
parent7aab34abcab28ca38a5354dec075b56d430e82db (diff)
Add DiskWriterBackEndResponse.
Diffstat (limited to 'src/lib/disk_writer_messages.cc')
-rw-r--r--src/lib/disk_writer_messages.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/lib/disk_writer_messages.cc b/src/lib/disk_writer_messages.cc
new file mode 100644
index 000000000..e42e80ec6
--- /dev/null
+++ b/src/lib/disk_writer_messages.cc
@@ -0,0 +1,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 {};
+}
+