From 7e4e6be3628308b7b16c015e2f87b27e729258dc Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 12 Jan 2019 23:12:46 +0000 Subject: Move verify API away from strings towards error codes. --- src/verify.cc | 27 ++++++++++++++++++--------- src/verify.h | 48 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/verify.cc b/src/verify.cc index 2288200b..4a656874 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2018 Carl Hetherington + Copyright (C) 2018-2019 Carl Hetherington This file is part of libdcp. @@ -38,6 +38,7 @@ #include "reel_picture_asset.h" #include "reel_sound_asset.h" #include "exceptions.h" +#include "compose.hpp" #include #include #include @@ -108,9 +109,9 @@ dcp::verify (vector directories, functionread (true, &errors); } catch (DCPReadError& e) { - notes.push_back (VerificationNote (VerificationNote::VERIFY_ERROR, e.what ())); + notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::GENERAL_READ, string(e.what()))); } catch (XMLError& e) { - notes.push_back (VerificationNote (VerificationNote::VERIFY_ERROR, e.what ())); + notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::GENERAL_READ, string(e.what()))); } BOOST_FOREACH (shared_ptr cpl, dcp->cpls()) { @@ -120,7 +121,7 @@ dcp::verify (vector directories, function i, dcp->pkls()) { optional h = i->hash(cpl->id()); if (h && make_digest(Data(*cpl->file())) != *h) { - notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, "CPL hash is incorrect.")); + notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::CPL_HASH_INCORRECT)); } } @@ -136,17 +137,21 @@ dcp::verify (vector directories, functionmain_picture()->asset()->file()); Result const r = verify_asset (dcp, reel->main_picture(), progress); switch (r) { case RESULT_BAD: - notes.push_back (VerificationNote (VerificationNote::VERIFY_ERROR, "Picture asset hash is incorrect.")); + notes.push_back ( + VerificationNote( + VerificationNote::VERIFY_ERROR, VerificationNote::PICTURE_HASH_INCORRECT, *reel->main_picture()->asset()->file() + ) + ); break; case RESULT_CPL_PKL_DIFFER: - notes.push_back (VerificationNote (VerificationNote::VERIFY_ERROR, "PKL and CPL hashes differ for picture asset.")); + notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::PKL_CPL_PICTURE_HASHES_DISAGREE)); break; default: break; @@ -157,10 +162,14 @@ dcp::verify (vector directories, functionmain_sound(), progress); switch (r) { case RESULT_BAD: - notes.push_back (VerificationNote (VerificationNote::VERIFY_ERROR, "Sound asset hash is incorrect.")); + notes.push_back ( + VerificationNote( + VerificationNote::VERIFY_ERROR, VerificationNote::SOUND_HASH_INCORRECT, *reel->main_sound()->asset()->file() + ) + ); break; case RESULT_CPL_PKL_DIFFER: - notes.push_back (VerificationNote (VerificationNote::VERIFY_ERROR, "PKL and CPL hashes differ for sound asset.")); + notes.push_back (VerificationNote (VerificationNote::VERIFY_ERROR, VerificationNote::PKL_CPL_SOUND_HASHES_DISAGREE)); break; default: break; diff --git a/src/verify.h b/src/verify.h index f5b21763..4b967d1d 100644 --- a/src/verify.h +++ b/src/verify.h @@ -51,26 +51,64 @@ public: */ enum Type { VERIFY_ERROR, - VERIFY_WARNING, - VERIFY_NOTE + VERIFY_WARNING }; - VerificationNote (Type type, std::string note) + enum Code { + /** An error when reading the DCP. note contains (probably technical) details. */ + GENERAL_READ, + /** The hash of the CPL in the PKL does not agree with the CPL file */ + CPL_HASH_INCORRECT, + /** Frame rate given in a reel for the main picture is not 24, 25, 30, 48, 50 or 60 */ + INVALID_PICTURE_FRAME_RATE, + /** The hash of a main picture asset does not agree with the PKL file. file contains the picture asset filename. */ + PICTURE_HASH_INCORRECT, + /** The hash of a main picture is different in the CPL and PKL */ + PKL_CPL_PICTURE_HASHES_DISAGREE, + /** The hash of a main sound asset does not agree with the PKL file. file contains the sound asset filename. */ + SOUND_HASH_INCORRECT, + /** The hash of a main sound is different in the CPL and PKL */ + PKL_CPL_SOUND_HASHES_DISAGREE, + }; + + VerificationNote (Type type, Code code) + : _type (type) + , _code (code) + {} + + VerificationNote (Type type, Code code, std::string note) : _type (type) + , _code (code) , _note (note) {} + VerificationNote (Type type, Code code, boost::filesystem::path file) + : _type (type) + , _code (code) + , _file (file) + {} + Type type () const { return _type; } - std::string note () const { + Code code () const { + return _code; + } + + boost::optional note () const { return _note; } + boost::optional file () const { + return _file; + } + private: Type _type; - std::string _note; + Code _code; + boost::optional _note; + boost::optional _file; }; std::list verify ( -- cgit v1.2.3