Check that all image data is present after loading a SMPTE subtitle asset.
[libdcp.git] / src / exceptions.h
1 /*
2     Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34 #ifndef LIBDCP_EXCEPTIONS_H
35 #define LIBDCP_EXCEPTIONS_H
36
37 #include <boost/filesystem.hpp>
38 #include <boost/optional.hpp>
39
40 /** @file  src/exceptions.h
41  *  @brief Exceptions thrown by libdcp.
42  */
43
44 namespace dcp
45 {
46
47 /** @class FileError
48  *  @brief An exception related to a file
49  */
50 class FileError : public std::runtime_error
51 {
52 public:
53         FileError (std::string message, boost::filesystem::path filename, int number);
54         ~FileError () throw () {}
55
56         /** @return filename of file that was involved */
57         boost::filesystem::path filename () const {
58                 return _filename;
59         }
60
61         /** @return error number of the error */
62         int number () const {
63                 return _number;
64         }
65
66 private:
67         /** filename of file that was involved */
68         boost::filesystem::path _filename;
69         int _number;
70 };
71
72 /** @class MXFFileError
73  *  @brief An exception related to an MXF file
74  */
75 class MXFFileError : public FileError
76 {
77 public:
78         MXFFileError (std::string message, boost::filesystem::path filename, int number)
79                 : FileError (message, filename, number)
80         {}
81 };
82
83 /** @class MiscError
84  *  @brief A miscellaneous exception
85  */
86 class MiscError : public std::runtime_error
87 {
88 public:
89         explicit MiscError (std::string message)
90                 : std::runtime_error (message)
91         {}
92 };
93
94 /** @class DCPReadError
95  *  @brief A DCP read exception
96  */
97 class DCPReadError : public std::runtime_error
98 {
99 public:
100         explicit DCPReadError (std::string message)
101                 : std::runtime_error(message)
102                 , _message(message)
103         {}
104
105         DCPReadError (std::string message, std::string detail);
106
107         ~DCPReadError() throw () {}
108
109         std::string message () const {
110                 return _message;
111         }
112
113         boost::optional<std::string> detail () const {
114                 return _detail;
115         }
116
117 private:
118         std::string _message;
119         boost::optional<std::string> _detail;
120 };
121
122 /** @class MissingAssetError
123  *  @brief An error of a missing asset.
124  */
125 class MissingAssetError : public DCPReadError
126 {
127 public:
128         enum AssetType {
129                 MAIN_PICTURE,  //< main picture is missing
130                 MAIN_SOUND,    //< main sound is missing
131                 MAIN_SUBTITLE, //< main subtitle is missing
132                 UNKNOWN        //< something is missing but we don't know what
133         };
134
135         MissingAssetError (boost::filesystem::path, AssetType = UNKNOWN);
136         ~MissingAssetError () throw () {}
137
138         boost::filesystem::path path () const {
139                 return _path;
140         }
141
142 private:
143         boost::filesystem::path _path;
144 };
145
146 class BadContentKindError : public DCPReadError
147 {
148 public:
149         BadContentKindError (std::string content_kind);
150 };
151
152 /** @class XMLError
153  *  @brief An XML error
154  */
155 class XMLError : public std::runtime_error
156 {
157 public:
158         explicit XMLError (std::string message)
159                 : std::runtime_error (message)
160         {}
161 };
162
163 /** @class UnresolvedRefError
164  *  @brief An exception caused by a reference (by UUID) to something which is not known
165  */
166 class UnresolvedRefError : public std::runtime_error
167 {
168 public:
169         explicit UnresolvedRefError (std::string id);
170 };
171
172 /** @class TimeFormatError
173  *  @brief A an error with a string passed to LocalTime.
174  */
175 class TimeFormatError : public std::runtime_error
176 {
177 public:
178         explicit TimeFormatError (std::string bad_time);
179 };
180
181 /** @class NotEncryptedError
182  *  @brief An error raised when creating a DecryptedKDM object for assets that are not
183  *  encrypted.
184  */
185 class NotEncryptedError : public std::runtime_error
186 {
187 public:
188         explicit NotEncryptedError (std::string const & what);
189         ~NotEncryptedError () throw () {}
190 };
191
192 /** @class ProgrammingError
193  *  @brief An exception thrown when a DCP_ASSERT fails; something that should not happen.
194  */
195 class ProgrammingError : public std::runtime_error
196 {
197 public:
198         ProgrammingError (std::string file, int line);
199 };
200
201 class MismatchedStandardError : public DCPReadError
202 {
203 public:
204         MismatchedStandardError ();
205 };
206
207 class KDMDecryptionError : public std::runtime_error
208 {
209 public:
210         KDMDecryptionError (std::string message, int cipher_length, int modulus_dmax);
211 };
212
213 class KDMFormatError : public std::runtime_error
214 {
215 public:
216         KDMFormatError (std::string message);
217 };
218
219 class CertificateChainError : public std::runtime_error
220 {
221 public:
222         CertificateChainError (std::string message);
223 };
224
225 class MissingSubtitleImageError : public std::runtime_error
226 {
227 public:
228         MissingSubtitleImageError (std::string id);
229 };
230
231 }
232
233 #endif