X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdisk_writer_messages.h;h=8bd1837a83946c6882d55d1b70bbe0ec3e901394;hb=7bce98ec4c05081569cb66b68523e1466058ea76;hp=406afc61da866b36001582e5b374514ce19478f5;hpb=334d3cb564c72bd430a17c6e6f01aeb488fb191c;p=dcpomatic.git diff --git a/src/lib/disk_writer_messages.h b/src/lib/disk_writer_messages.h index 406afc61d..8bd1837a8 100644 --- a/src/lib/disk_writer_messages.h +++ b/src/lib/disk_writer_messages.h @@ -18,6 +18,14 @@ */ + +#include +#include + + +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. @@ -51,8 +59,9 @@ // Error message // Error number -// the drive is being formatted -#define DISK_WRITER_FORMATTING "F" +// the drive is being formatted, 40% done +#define DISK_WRITER_FORMAT_PROGRESS "F" +// 0.4\n // data is being copied, 30% done #define DISK_WRITER_COPY_PROGRESS "C" @@ -80,3 +89,80 @@ // 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 read_from_nanomsg(Nanomsg& nanomsg, int timeout); + + bool write_to_nanomsg(Nanomsg& nanomsg, int timeout) const; + + 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; +}; +