Build with FFmpeg 4.4 and switch to the new send/receive APIs.
[dcpomatic.git] / src / lib / exceptions.h
1 /*
2     Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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     DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 /** @file  src/lib/exceptions.h
22  *  @brief Our exceptions.
23  */
24
25 #ifndef DCPOMATIC_EXCEPTIONS_H
26 #define DCPOMATIC_EXCEPTIONS_H
27
28 #include "compose.hpp"
29 extern "C" {
30 #include <libavutil/pixfmt.h>
31 }
32 #include <boost/filesystem.hpp>
33 #include <boost/optional.hpp>
34 #include <stdexcept>
35 #include <cstring>
36
37 /** @class DecodeError
38  *  @brief A low-level problem with the decoder (possibly due to the nature
39  *  of a source file).
40  */
41 class DecodeError : public std::runtime_error
42 {
43 public:
44         explicit DecodeError (std::string s)
45                 : std::runtime_error (s)
46         {}
47
48         explicit DecodeError (std::string function, std::string caller)
49                 : std::runtime_error (String::compose("%1 failed [%2", function, caller))
50         {}
51
52         explicit DecodeError (std::string function, std::string caller, int error)
53                 : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error))
54         {}
55 };
56
57 class CryptoError : public std::runtime_error
58 {
59 public:
60         explicit CryptoError (std::string s)
61                 : std::runtime_error (s)
62         {}
63 };
64
65
66 /** @class EncodeError
67  *  @brief A low-level problem with an encoder.
68  */
69 class EncodeError : public std::runtime_error
70 {
71 public:
72         explicit EncodeError (std::string s)
73                 : std::runtime_error (s)
74         {}
75
76         explicit EncodeError (std::string function, std::string caller)
77                 : std::runtime_error (String::compose("%1 failed [%2]", function, caller))
78         {}
79
80         explicit EncodeError (std::string function, std::string caller, int error)
81                 : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error))
82         {}
83 };
84
85
86 /** @class FileError.
87  *  @brief Parent class for file-related errors.
88  */
89 class FileError : public std::runtime_error
90 {
91 public:
92         /** @param m Error message.
93          *  @param f Name of the file that this exception concerns.
94          */
95         FileError (std::string m, boost::filesystem::path f)
96                 : std::runtime_error (String::compose("%1 with %2", m, f.string()))
97                 , _file (f)
98         {}
99
100         virtual ~FileError () throw () {}
101
102         /** @return name of the file that this exception concerns */
103         boost::filesystem::path file () const {
104                 return _file;
105         }
106
107 private:
108         /** name of the file that this exception concerns */
109         boost::filesystem::path _file;
110 };
111
112 class JoinError : public std::runtime_error
113 {
114 public:
115         explicit JoinError (std::string s)
116                 : std::runtime_error (s)
117         {}
118 };
119
120 /** @class OpenFileError.
121  *  @brief Indicates that some error occurred when trying to open a file.
122  */
123 class OpenFileError : public FileError
124 {
125 public:
126         enum Mode {
127                 READ,
128                 WRITE,
129                 READ_WRITE
130         };
131
132         /** @param f File that we were trying to open.
133          *  @param error Code of error that occurred.
134          *  @param mode Mode that we tried to open the file in.
135          */
136         OpenFileError (boost::filesystem::path f, int error, Mode mode);
137 };
138
139 class FileNotFoundError : public std::runtime_error
140 {
141 public:
142         FileNotFoundError (boost::filesystem::path f);
143         virtual ~FileNotFoundError () throw () {}
144
145         /** @return name of the file that this exception concerns */
146         boost::filesystem::path file () const {
147                 return _file;
148         }
149
150 private:
151         /** name of the file that this exception concerns */
152         boost::filesystem::path _file;
153 };
154
155 /** @class ReadFileError.
156  *  @brief Indicates that some error occurred when trying to read from a file
157  */
158 class ReadFileError : public FileError
159 {
160 public:
161         /** @param f File that we were trying to read from.
162          *  @param e errno value, or 0.
163          */
164         ReadFileError (boost::filesystem::path f, int e = 0);
165 };
166
167 /** @class WriteFileError.
168  *  @brief Indicates that some error occurred when trying to write to a file
169  */
170 class WriteFileError : public FileError
171 {
172 public:
173         /** @param f File that we were trying to write to.
174          *  @param e errno value, or 0.
175          */
176         WriteFileError (boost::filesystem::path f, int e);
177 };
178
179 /** @class SettingError.
180  *  @brief Indicates that something is wrong with a setting.
181  */
182 class SettingError : public std::runtime_error
183 {
184 public:
185         /** @param s Name of setting that was required.
186          *  @param m Message.
187          */
188         SettingError (std::string s, std::string m)
189                 : std::runtime_error (m)
190                 , _setting (s)
191         {}
192
193         virtual ~SettingError () throw () {}
194
195         /** @return name of setting in question */
196         std::string setting () const {
197                 return _setting;
198         }
199
200 private:
201         std::string _setting;
202 };
203
204 /** @class MissingSettingError.
205  *  @brief Indicates that a Film is missing a setting that is required for some operation.
206  */
207 class MissingSettingError : public SettingError
208 {
209 public:
210         /** @param s Name of setting that was required */
211         explicit MissingSettingError (std::string s);
212 };
213
214 /** @class BadSettingError
215  *  @brief Indicates that a setting is bad in some way.
216  */
217 class BadSettingError : public SettingError
218 {
219 public:
220         /** @param s Name of setting that is bad.
221          *  @param m Error message.
222          */
223         BadSettingError (std::string s, std::string m)
224                 : SettingError (s, m)
225         {}
226 };
227
228 /** @class NetworkError
229  *  @brief Indicates some problem with communication on the network.
230  */
231 class NetworkError : public std::runtime_error
232 {
233 public:
234         explicit NetworkError (std::string s)
235                 : std::runtime_error (s)
236         {}
237 };
238
239 /** @class KDMError
240  *  @brief A problem with a KDM.
241  */
242 class KDMError : public std::runtime_error
243 {
244 public:
245         KDMError (std::string s, std::string d);
246         ~KDMError () throw() {}
247
248         std::string summary () const {
249                 return _summary;
250         }
251
252         std::string detail () const {
253                 return _detail;
254         }
255
256 private:
257         std::string _summary;
258         std::string _detail;
259 };
260
261 /** @class PixelFormatError
262  *  @brief A problem with an unsupported pixel format.
263  */
264 class PixelFormatError : public std::runtime_error
265 {
266 public:
267         PixelFormatError (std::string o, AVPixelFormat f);
268 };
269
270 /** @class TextSubtitleError
271  *  @brief An error that occurs while parsing a TextSubtitleError file.
272  */
273 class TextSubtitleError : public FileError
274 {
275 public:
276         TextSubtitleError (std::string, std::string, boost::filesystem::path);
277 };
278
279 class DCPError : public std::runtime_error
280 {
281 public:
282         explicit DCPError (std::string s)
283                 : std::runtime_error (s)
284         {}
285 };
286
287
288 /** @class ProjectFolderError
289  *  @brief An attempt has been made to read a DCP from a directory, but it looks
290  *  like the directory actually contains a DCP-o-matic project.
291  */
292 class ProjectFolderError : public DCPError
293 {
294 public:
295         /* Code which catches this exception will provide their own message */
296         ProjectFolderError ()
297                 : DCPError ("dummy")
298         {}
299 };
300
301
302 class InvalidSignerError : public std::runtime_error
303 {
304 public:
305         InvalidSignerError ();
306         explicit InvalidSignerError (std::string reason);
307 };
308
309 class ProgrammingError : public std::runtime_error
310 {
311 public:
312         ProgrammingError (std::string file, int line, std::string message = "");
313 };
314
315 class TextEncodingError : public std::runtime_error
316 {
317 public:
318         explicit TextEncodingError (std::string s)
319                 : std::runtime_error (s)
320         {}
321 };
322
323 class MetadataError : public std::runtime_error
324 {
325 public:
326         explicit MetadataError (std::string s)
327                 : std::runtime_error (s)
328         {}
329 };
330
331 class OldFormatError : public std::runtime_error
332 {
333 public:
334         explicit OldFormatError (std::string s)
335                 : std::runtime_error (s)
336         {}
337 };
338
339 class KDMAsContentError : public std::runtime_error
340 {
341 public:
342         KDMAsContentError ();
343 };
344
345 class GLError : public std::runtime_error
346 {
347 public:
348         GLError (char const * last, int e);
349 };
350
351 /** @class CopyError
352  *  @brief An error which occurs when copying a DCP to a distribution drive.
353  */
354 class CopyError : public std::runtime_error
355 {
356 public:
357         CopyError (std::string s, boost::optional<int> n = boost::optional<int>());
358         virtual ~CopyError () throw () {}
359
360         std::string message () const {
361                 return _message;
362         }
363
364         boost::optional<int> number () const {
365                 return _number;
366         }
367
368 private:
369         std::string _message;
370         boost::optional<int> _number;
371 };
372
373
374 /** @class CommunicationFailedError
375  *  @brief Communcation between dcpomatic2_disk and _disk_writer failed somehow.
376  */
377 class CommunicationFailedError : public CopyError
378 {
379 public:
380         CommunicationFailedError ();
381 };
382
383
384 /** @class VerifyError
385  *  @brief An error which occurs when verifying a DCP that we copied to a distribution drive.
386  */
387 class VerifyError : public std::runtime_error
388 {
389 public:
390         VerifyError (std::string s, int n);
391         virtual ~VerifyError () throw () {}
392
393         std::string message () const {
394                 return _message;
395         }
396
397         int number () const {
398                 return _number;
399         }
400
401 private:
402         std::string _message;
403         int _number;
404 };
405
406
407 class PrivilegeError : public std::runtime_error
408 {
409 public:
410         explicit PrivilegeError (std::string s)
411                         : std::runtime_error (s)
412                 {}
413 };
414
415 #endif