error.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __BARRY_ERROR_H__
00023 #define __BARRY_ERROR_H__
00024
00025 #include "dll.h"
00026 #include "pin.h"
00027 #include <stdexcept>
00028 #include <stdint.h>
00029
00030 namespace Barry {
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class BXEXPORT Error : public std::runtime_error
00042 {
00043 public:
00044 Error(const std::string &str) : std::runtime_error(str) {}
00045 };
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 class BXEXPORT BadPassword : public Barry::Error
00063 {
00064 int m_remaining_tries;
00065 bool m_out_of_tries;
00066
00067 public:
00068 BadPassword(const std::string &str, int remaining_tries,
00069 bool out_of_tries)
00070 : Barry::Error(str),
00071 m_remaining_tries(remaining_tries),
00072 m_out_of_tries(out_of_tries)
00073 {}
00074 int remaining_tries() const { return m_remaining_tries; }
00075 bool out_of_tries() const { return m_out_of_tries; }
00076 };
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 class BXEXPORT PinNotFound : public Barry::Error
00087 {
00088 Barry::Pin m_pin;
00089 int m_probe_count;
00090
00091 public:
00092 PinNotFound(Barry::Pin pin, int probe_count)
00093 : Barry::Error("PIN not found: " + pin.Str())
00094 , m_pin(pin)
00095 , m_probe_count(probe_count)
00096 {}
00097
00098 const Barry::Pin& pin() const { return m_pin; }
00099 int probe_count() const { return m_probe_count; }
00100 };
00101
00102
00103
00104
00105
00106
00107
00108 class BXEXPORT BadData : public Barry::Error
00109 {
00110 public:
00111 BadData(const std::string &str)
00112 : Barry::Error(str)
00113 {}
00114 };
00115
00116
00117
00118
00119
00120
00121 class BXEXPORT BadSize : public Barry::Error
00122 {
00123 unsigned int m_packet_size,
00124 m_data_buf_size,
00125 m_required_size;
00126
00127 BXLOCAL static std::string GetMsg(const char *msg, unsigned int d, unsigned int r);
00128 BXLOCAL static std::string GetMsg(unsigned int p, unsigned int d, unsigned int r);
00129
00130 public:
00131 BadSize(const char *msg, unsigned int data_size, unsigned int required_size);
00132 BadSize(unsigned int packet_size,
00133 unsigned int data_buf_size,
00134 unsigned int required_size);
00135 unsigned int packet_size() const { return m_packet_size; }
00136 unsigned int data_buf_size() const { return m_data_buf_size; }
00137 unsigned int required_size() const { return m_required_size; }
00138 };
00139
00140
00141
00142
00143
00144
00145 class BXEXPORT ErrnoError : public Barry::Error
00146 {
00147 int m_errno;
00148
00149 BXLOCAL static std::string GetMsg(const std::string &msg, int err);
00150
00151 protected:
00152 ErrnoError(const std::string &msg);
00153
00154 public:
00155 ErrnoError(const std::string &msg, int err);
00156
00157 int error_code() const { return m_errno; }
00158 };
00159
00160
00161
00162
00163
00164
00165
00166 class BXEXPORT ConfigFileError : public Barry::ErrnoError
00167 {
00168 public:
00169 ConfigFileError(const char *msg) : Barry::ErrnoError(msg) {}
00170 ConfigFileError(const char *msg, int err)
00171 : Barry::ErrnoError(msg, err)
00172 {}
00173 };
00174
00175
00176
00177
00178
00179
00180
00181
00182 class BXEXPORT BadPackedFormat : public Barry::Error
00183 {
00184 uint8_t m_format;
00185
00186 public:
00187 BadPackedFormat(uint8_t format)
00188 : Barry::Error("Bad packed format - internal exception")
00189 , m_format(format)
00190 {}
00191
00192 uint8_t format() const { return m_format; }
00193 };
00194
00195
00196
00197
00198
00199
00200
00201
00202 class BXEXPORT BadPacket : public Barry::Error
00203 {
00204 uint8_t m_response;
00205
00206 public:
00207 BadPacket(uint8_t response, const std::string &msg)
00208 : Barry::Error(msg)
00209 , m_response(response)
00210 {}
00211
00212 uint8_t response() const { return m_response; }
00213 };
00214
00215
00216
00217
00218
00219
00220 class BXEXPORT ConvertError : public Barry::Error
00221 {
00222 public:
00223 ConvertError(const std::string &msg) : Barry::Error(msg) {}
00224 };
00225
00226
00227
00228
00229
00230
00231
00232 class BXEXPORT BackupError : public Barry::Error
00233 {
00234 public:
00235 BackupError(const std::string &str) : Error(str) {}
00236 };
00237
00238
00239
00240
00241
00242
00243
00244 class BXEXPORT RestoreError : public Barry::Error
00245 {
00246 public:
00247 RestoreError(const std::string &str) : Error(str) {}
00248 };
00249
00250
00251
00252 }
00253
00254 #endif
00255