More player debugging for butler video-full states.
[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         /** @param f File that we were trying to open.
107          *  @param error Code of error that occurred.
108          *  @param reading true if we were opening to read, false if opening to write.
109          */
110         OpenFileError (boost::filesystem::path f, int error, bool reading);
111 };
112
113 /** @class ReadFileError.
114  *  @brief Indicates that some error occurred when trying to read from a file
115  */
116 class ReadFileError : public FileError
117 {
118 public:
119         /** @param f File that we were trying to read from.
120          *  @param e errno value, or 0.
121          */
122         ReadFileError (boost::filesystem::path f, int e = 0);
123 };
124
125 /** @class WriteFileError.
126  *  @brief Indicates that some error occurred when trying to write to a file
127  */
128 class WriteFileError : public FileError
129 {
130 public:
131         /** @param f File that we were trying to write to.
132          *  @param e errno value, or 0.
133          */
134         WriteFileError (boost::filesystem::path f, int e);
135 };
136
137 /** @class SettingError.
138  *  @brief Indicates that something is wrong with a setting.
139  */
140 class SettingError : public std::runtime_error
141 {
142 public:
143         /** @param s Name of setting that was required.
144          *  @param m Message.
145          */
146         SettingError (std::string s, std::string m)
147                 : std::runtime_error (m)
148                 , _setting (s)
149         {}
150
151         virtual ~SettingError () throw () {}
152
153         /** @return name of setting in question */
154         std::string setting () const {
155                 return _setting;
156         }
157
158 private:
159         std::string _setting;
160 };
161
162 /** @class MissingSettingError.
163  *  @brief Indicates that a Film is missing a setting that is required for some operation.
164  */
165 class MissingSettingError : public SettingError
166 {
167 public:
168         /** @param s Name of setting that was required */
169         explicit MissingSettingError (std::string s);
170 };
171
172 /** @class BadSettingError
173  *  @brief Indicates that a setting is bad in some way.
174  */
175 class BadSettingError : public SettingError
176 {
177 public:
178         /** @param s Name of setting that is bad.
179          *  @param m Error message.
180          */
181         BadSettingError (std::string s, std::string m)
182                 : SettingError (s, m)
183         {}
184 };
185
186 /** @class NetworkError
187  *  @brief Indicates some problem with communication on the network.
188  */
189 class NetworkError : public std::runtime_error
190 {
191 public:
192         explicit NetworkError (std::string s)
193                 : std::runtime_error (s)
194         {}
195 };
196
197 /** @class KDMError
198  *  @brief A problem with a KDM.
199  */
200 class KDMError : public std::runtime_error
201 {
202 public:
203         KDMError (std::string s, std::string d);
204         ~KDMError () throw() {}
205
206         std::string summary () const {
207                 return _summary;
208         }
209
210         std::string detail () const {
211                 return _detail;
212         }
213
214 private:
215         std::string _summary;
216         std::string _detail;
217 };
218
219 /** @class PixelFormatError
220  *  @brief A problem with an unsupported pixel format.
221  */
222 class PixelFormatError : public std::runtime_error
223 {
224 public:
225         PixelFormatError (std::string o, AVPixelFormat f);
226 };
227
228 /** @class TextSubtitleError
229  *  @brief An error that occurs while parsing a TextSubtitleError file.
230  */
231 class TextSubtitleError : public FileError
232 {
233 public:
234         TextSubtitleError (std::string, std::string, boost::filesystem::path);
235 };
236
237 class DCPError : public std::runtime_error
238 {
239 public:
240         explicit DCPError (std::string s)
241                 : std::runtime_error (s)
242         {}
243 };
244
245 class InvalidSignerError : public std::runtime_error
246 {
247 public:
248         InvalidSignerError ();
249         explicit InvalidSignerError (std::string reason);
250 };
251
252 class ProgrammingError : public std::runtime_error
253 {
254 public:
255         ProgrammingError (std::string file, int line, std::string message = "");
256 };
257
258 class TextEncodingError : public std::runtime_error
259 {
260 public:
261         explicit TextEncodingError (std::string s)
262                 : std::runtime_error (s)
263         {}
264 };
265
266 class MetadataError : public std::runtime_error
267 {
268 public:
269         explicit MetadataError (std::string s)
270                 : std::runtime_error (s)
271         {}
272 };
273
274 class OldFormatError : public std::runtime_error
275 {
276 public:
277         explicit OldFormatError (std::string s)
278                 : std::runtime_error (s)
279         {}
280 };
281
282 class KDMAsContentError : public std::runtime_error
283 {
284 public:
285         KDMAsContentError ();
286 };
287
288 #endif