766d3d8d5442f8cd2e2bb38580dcdafa8a853f68
[dcpomatic.git] / src / lib / exceptions.h
1 /*
2     Copyright (C) 2012-2014 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 extern "C" {
29 #include <libavutil/pixfmt.h>
30 }
31 #include <boost/filesystem.hpp>
32 #include <stdexcept>
33 #include <cstring>
34
35 /** @class DecodeError
36  *  @brief A low-level problem with the decoder (possibly due to the nature
37  *  of a source file).
38  */
39 class DecodeError : public std::runtime_error
40 {
41 public:
42         explicit DecodeError (std::string s)
43                 : std::runtime_error (s)
44         {}
45 };
46
47 class CryptoError : public std::runtime_error
48 {
49 public:
50         explicit CryptoError (std::string s)
51                 : std::runtime_error (s)
52         {}
53 };
54
55 /** @class EncodeError
56  *  @brief A low-level problem with an encoder.
57  */
58 class EncodeError : public std::runtime_error
59 {
60 public:
61         explicit EncodeError (std::string s)
62                 : std::runtime_error (s)
63         {}
64 };
65
66 /** @class FileError.
67  *  @brief Parent class for file-related errors.
68  */
69 class FileError : public std::runtime_error
70 {
71 public:
72         /** @param m Error message.
73          *  @param f Name of the file that this exception concerns.
74          */
75         FileError (std::string m, boost::filesystem::path f)
76                 : std::runtime_error (m)
77                 , _file (f)
78         {}
79
80         virtual ~FileError () throw () {}
81
82         /** @return name of the file that this exception concerns */
83         boost::filesystem::path file () const {
84                 return _file;
85         }
86
87 private:
88         /** name of the file that this exception concerns */
89         boost::filesystem::path _file;
90 };
91
92 class JoinError : public std::runtime_error
93 {
94 public:
95         explicit JoinError (std::string s)
96                 : std::runtime_error (s)
97         {}
98 };
99
100 /** @class OpenFileError.
101  *  @brief Indicates that some error occurred when trying to open a file.
102  */
103 class OpenFileError : public FileError
104 {
105 public:
106         enum Mode {
107                 READ,
108                 WRITE,
109                 READ_WRITE
110         };
111
112         /** @param f File that we were trying to open.
113          *  @param error Code of error that occurred.
114          *  @param mode Mode that we tried to open the file in.
115          */
116         OpenFileError (boost::filesystem::path f, int error, Mode mode);
117 };
118
119 /** @class ReadFileError.
120  *  @brief Indicates that some error occurred when trying to read from a file
121  */
122 class ReadFileError : public FileError
123 {
124 public:
125         /** @param f File that we were trying to read from.
126          *  @param e errno value, or 0.
127          */
128         ReadFileError (boost::filesystem::path f, int e = 0);
129 };
130
131 /** @class WriteFileError.
132  *  @brief Indicates that some error occurred when trying to write to a file
133  */
134 class WriteFileError : public FileError
135 {
136 public:
137         /** @param f File that we were trying to write to.
138          *  @param e errno value, or 0.
139          */
140         WriteFileError (boost::filesystem::path f, int e);
141 };
142
143 /** @class SettingError.
144  *  @brief Indicates that something is wrong with a setting.
145  */
146 class SettingError : public std::runtime_error
147 {
148 public:
149         /** @param s Name of setting that was required.
150          *  @param m Message.
151          */
152         SettingError (std::string s, std::string m)
153                 : std::runtime_error (m)
154                 , _setting (s)
155         {}
156
157         virtual ~SettingError () throw () {}
158
159         /** @return name of setting in question */
160         std::string setting () const {
161                 return _setting;
162         }
163
164 private:
165         std::string _setting;
166 };
167
168 /** @class MissingSettingError.
169  *  @brief Indicates that a Film is missing a setting that is required for some operation.
170  */
171 class MissingSettingError : public SettingError
172 {
173 public:
174         /** @param s Name of setting that was required */
175         explicit MissingSettingError (std::string s);
176 };
177
178 /** @class BadSettingError
179  *  @brief Indicates that a setting is bad in some way.
180  */
181 class BadSettingError : public SettingError
182 {
183 public:
184         /** @param s Name of setting that is bad.
185          *  @param m Error message.
186          */
187         BadSettingError (std::string s, std::string m)
188                 : SettingError (s, m)
189         {}
190 };
191
192 /** @class NetworkError
193  *  @brief Indicates some problem with communication on the network.
194  */
195 class NetworkError : public std::runtime_error
196 {
197 public:
198         explicit NetworkError (std::string s)
199                 : std::runtime_error (s)
200         {}
201 };
202
203 /** @class KDMError
204  *  @brief A problem with a KDM.
205  */
206 class KDMError : public std::runtime_error
207 {
208 public:
209         KDMError (std::string s, std::string d);
210         ~KDMError () throw() {}
211
212         std::string summary () const {
213                 return _summary;
214         }
215
216         std::string detail () const {
217                 return _detail;
218         }
219
220 private:
221         std::string _summary;
222         std::string _detail;
223 };
224
225 /** @class PixelFormatError
226  *  @brief A problem with an unsupported pixel format.
227  */
228 class PixelFormatError : public std::runtime_error
229 {
230 public:
231         PixelFormatError (std::string o, AVPixelFormat f);
232 };
233
234 /** @class TextSubtitleError
235  *  @brief An error that occurs while parsing a TextSubtitleError file.
236  */
237 class TextSubtitleError : public FileError
238 {
239 public:
240         TextSubtitleError (std::string, std::string, boost::filesystem::path);
241 };
242
243 class DCPError : public std::runtime_error
244 {
245 public:
246         explicit DCPError (std::string s)
247                 : std::runtime_error (s)
248         {}
249 };
250
251 class InvalidSignerError : public std::runtime_error
252 {
253 public:
254         InvalidSignerError ();
255         explicit InvalidSignerError (std::string reason);
256 };
257
258 class ProgrammingError : public std::runtime_error
259 {
260 public:
261         ProgrammingError (std::string file, int line, std::string message = "");
262 };
263
264 class TextEncodingError : public std::runtime_error
265 {
266 public:
267         explicit TextEncodingError (std::string s)
268                 : std::runtime_error (s)
269         {}
270 };
271
272 class MetadataError : public std::runtime_error
273 {
274 public:
275         explicit MetadataError (std::string s)
276                 : std::runtime_error (s)
277         {}
278 };
279
280 class OldFormatError : public std::runtime_error
281 {
282 public:
283         explicit OldFormatError (std::string s)
284                 : std::runtime_error (s)
285         {}
286 };
287
288 class KDMAsContentError : public std::runtime_error
289 {
290 public:
291         KDMAsContentError ();
292 };
293
294 #endif