--- /dev/null
+/*
+ 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 {};
+}
+
*/
+
+#include <boost/optional.hpp>
+#include <string>
+
+
+class Nanomsg;
+
+
/* We have the front-end application dcpomatic2_disk and the back-end
* dcpomatic2_disk_writer. The communication is line-based, separated
* by \n.
// or
// DISK_WRITER_ERROR
+
+class DiskWriterBackEndResponse
+{
+public:
+ enum class Type {
+ OK,
+ ERROR,
+ PONG,
+ FORMAT_PROGRESS,
+ COPY_PROGRESS,
+ VERIFY_PROGRESS
+ };
+
+ static DiskWriterBackEndResponse ok() {
+ return DiskWriterBackEndResponse(Type::OK);
+ }
+
+ static DiskWriterBackEndResponse error(std::string message, int number) {
+ auto r = DiskWriterBackEndResponse(Type::ERROR);
+ r._error_message = message;
+ r._error_number = number;
+ return r;
+ }
+
+ static DiskWriterBackEndResponse pong() {
+ return DiskWriterBackEndResponse(Type::PONG);
+ }
+
+ static DiskWriterBackEndResponse format_progress(float p) {
+ auto r = DiskWriterBackEndResponse(Type::FORMAT_PROGRESS);
+ r._progress = p;
+ return r;
+ }
+
+ static DiskWriterBackEndResponse copy_progress(float p) {
+ auto r = DiskWriterBackEndResponse(Type::COPY_PROGRESS);
+ r._progress = p;
+ return r;
+ }
+
+ static DiskWriterBackEndResponse verify_progress(float p) {
+ auto r = DiskWriterBackEndResponse(Type::VERIFY_PROGRESS);
+ r._progress = p;
+ return r;
+ }
+
+ static boost::optional<DiskWriterBackEndResponse> read_from_nanomsg(Nanomsg& nanomsg, int timeout);
+
+ Type type() const {
+ return _type;
+ }
+
+ std::string error_message() const {
+ return _error_message;
+ }
+
+ int error_number() const {
+ return _error_number;
+ }
+
+ float progress() const {
+ return _progress;
+ }
+
+private:
+ DiskWriterBackEndResponse(Type type)
+ : _type(type)
+ {}
+
+ Type _type;
+ std::string _error_message;
+ int _error_number = 0;
+ float _progress = 0;
+};
+