Support CPL metadata.
[libdcp.git] / src / exceptions.h
1 /*
2     Copyright (C) 2012-2020 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
95 /** @class ReadError
96  *  @brief Any error that occurs when reading data from a DCP.
97  */
98 class ReadError : public std::runtime_error
99 {
100 public:
101         explicit ReadError (std::string message)
102                 : std::runtime_error(message)
103                 , _message(message)
104         {}
105
106         ReadError (std::string message, std::string detail);
107
108         ~ReadError() throw () {}
109
110         std::string message () const {
111                 return _message;
112         }
113
114         boost::optional<std::string> detail () const {
115                 return _detail;
116         }
117
118 private:
119         std::string _message;
120         boost::optional<std::string> _detail;
121 };
122
123
124 /** @class J2KDecompressionError
125  *  @brief An error that occurs during decompression of JPEG2000 data.
126  */
127 class J2KDecompressionError : public ReadError
128 {
129 public:
130         explicit J2KDecompressionError (std::string message)
131                 : ReadError (message)
132         {}
133 };
134
135
136 class BadContentKindError : public ReadError
137 {
138 public:
139         BadContentKindError (std::string content_kind);
140 };
141
142 /** @class XMLError
143  *  @brief An XML error
144  */
145 class XMLError : public std::runtime_error
146 {
147 public:
148         explicit XMLError (std::string message)
149                 : std::runtime_error (message)
150         {}
151 };
152
153 /** @class UnresolvedRefError
154  *  @brief An exception caused by a reference (by UUID) to something which is not known
155  */
156 class UnresolvedRefError : public std::runtime_error
157 {
158 public:
159         explicit UnresolvedRefError (std::string id);
160 };
161
162 /** @class TimeFormatError
163  *  @brief A an error with a string passed to LocalTime.
164  */
165 class TimeFormatError : public std::runtime_error
166 {
167 public:
168         explicit TimeFormatError (std::string bad_time);
169 };
170
171 /** @class NotEncryptedError
172  *  @brief An error raised when creating a DecryptedKDM object for assets that are not
173  *  encrypted.
174  */
175 class NotEncryptedError : public std::runtime_error
176 {
177 public:
178         explicit NotEncryptedError (std::string const & what);
179         ~NotEncryptedError () throw () {}
180 };
181
182 /** @class ProgrammingError
183  *  @brief An exception thrown when a DCP_ASSERT fails; something that should not happen.
184  */
185 class ProgrammingError : public std::runtime_error
186 {
187 public:
188         ProgrammingError (std::string file, int line);
189 };
190
191 class KDMDecryptionError : public std::runtime_error
192 {
193 public:
194         KDMDecryptionError (std::string message, int cipher_length, int modulus_dmax);
195 };
196
197 class KDMFormatError : public std::runtime_error
198 {
199 public:
200         KDMFormatError (std::string message);
201 };
202
203 class CertificateChainError : public std::runtime_error
204 {
205 public:
206         CertificateChainError (std::string message);
207 };
208
209 class MissingSubtitleImageError : public std::runtime_error
210 {
211 public:
212         MissingSubtitleImageError (std::string id);
213 };
214
215 class BadKDMDateError : public std::runtime_error
216 {
217 public:
218         BadKDMDateError (bool starts_too_early);
219
220         bool starts_too_early () const {
221                 return _starts_too_early;
222         }
223
224 private:
225         bool _starts_too_early;
226 };
227
228
229 class StartCompressionError : public std::runtime_error
230 {
231 public:
232         explicit StartCompressionError (boost::optional<int> code = boost::optional<int>());
233         ~StartCompressionError () throw () {}
234
235         boost::optional<int> code () const {
236                 return _code;
237         }
238
239 private:
240         boost::optional<int> _code;
241 };
242
243
244 class CombineError : public std::runtime_error
245 {
246 public:
247         explicit CombineError (std::string message);
248 };
249
250
251 class LanguageTagError : public std::runtime_error
252 {
253 public:
254         LanguageTagError (std::string message);
255 };
256
257
258 class BadSettingError : public std::runtime_error
259 {
260 public:
261         BadSettingError (std::string message);
262 };
263
264
265 class DuplicateIdError : public std::runtime_error
266 {
267 public:
268         DuplicateIdError (std::string message);
269 };
270
271
272 class MainSoundConfigurationError : public std::runtime_error
273 {
274 public:
275         MainSoundConfigurationError (std::string s);
276 };
277
278
279 }
280
281 #endif