doc: updated bio man page with new cstore output mode
[barry.git] / src / error.h
blob23e1fdfecbb745e21d161789db57d93dbe1b0c8e
1 ///
2 /// \file error.h
3 /// Common exception classes for the Barry library
4 ///
6 /*
7 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_ERROR_H__
23 #define __BARRY_ERROR_H__
25 #include "dll.h"
26 #include <stdexcept>
27 #include <stdint.h>
29 namespace Barry {
31 /// \addtogroup exceptions
32 /// @{
35 // Error class
37 /// The base class for any future derived exceptions.
38 /// Can be thrown on any protocol error.
39 ///
40 class BXEXPORT Error : public std::runtime_error
42 public:
43 Error(const std::string &str) : std::runtime_error(str) {}
48 // BadPassword
50 /// A bad or unknown password when talking to the device.
51 /// Can be thrown in the following instances:
52 ///
53 /// - no password provided and the device requests one
54 /// - device rejected the available password
55 /// - too few remaining tries left... Barry will refuse to keep
56 /// trying passwords if there are fewer than
57 /// BARRY_MIN_PASSWORD_TRIES tries remaining. In this case,
58 /// out_of_tries() will return true.
59 ///
60 ///
61 class BXEXPORT BadPassword : public Barry::Error
63 int m_remaining_tries;
64 bool m_out_of_tries;
66 public:
67 BadPassword(const std::string &str, int remaining_tries,
68 bool out_of_tries)
69 : Barry::Error(str),
70 m_remaining_tries(remaining_tries),
71 m_out_of_tries(out_of_tries)
73 int remaining_tries() const { return m_remaining_tries; }
74 bool out_of_tries() const { return m_out_of_tries; }
78 // BadData
80 /// Thrown by record classes if their data is invalid and cannot be
81 /// uploaded to the Blackberry.
82 ///
83 class BXEXPORT BadData : public Barry::Error
85 public:
86 BadData(const std::string &str)
87 : Barry::Error(str)
92 // BadSize
94 /// Unexpected packet size, or not enough data.
95 ///
96 class BXEXPORT BadSize : public Barry::Error
98 unsigned int m_packet_size,
99 m_data_buf_size,
100 m_required_size;
102 BXLOCAL static std::string GetMsg(const char *msg, unsigned int d, unsigned int r);
103 BXLOCAL static std::string GetMsg(unsigned int p, unsigned int d, unsigned int r);
105 public:
106 BadSize(const char *msg, unsigned int data_size, unsigned int required_size);
107 BadSize(unsigned int packet_size,
108 unsigned int data_buf_size,
109 unsigned int required_size);
110 unsigned int packet_size() const { return m_packet_size; }
111 unsigned int data_buf_size() const { return m_data_buf_size; }
112 unsigned int required_size() const { return m_required_size; }
116 // ErrnoError
118 /// System error that provides an errno error code.
120 class BXEXPORT ErrnoError : public Barry::Error
122 int m_errno;
124 BXLOCAL static std::string GetMsg(const std::string &msg, int err);
126 protected:
127 ErrnoError(const std::string &msg); // for derived classes
129 public:
130 ErrnoError(const std::string &msg, int err);
132 int error_code() const { return m_errno; }
136 // ConfigFileError
138 /// Thrown by the ConfigFile class when encountering a serious system
139 /// error while loading the global config file for a given PIN.
141 class BXEXPORT ConfigFileError : public Barry::ErrnoError
143 public:
144 ConfigFileError(const char *msg) : Barry::ErrnoError(msg) {}
145 ConfigFileError(const char *msg, int err)
146 : Barry::ErrnoError(msg, err)
151 // BadPackedFormat
153 /// Thrown by record classes that don't recognize a given packed format code.
154 /// This exception is mostly handled internally, but is published here
155 /// just in case it escapes.
157 class BXEXPORT BadPackedFormat : public Barry::Error
159 uint8_t m_format;
161 public:
162 BadPackedFormat(uint8_t format)
163 : Barry::Error("Bad packed format - internal exception")
164 , m_format(format)
167 uint8_t format() const { return m_format; }
171 // BadPacket
173 /// Thrown by the socket class if a packet command's response indicates
174 /// an error. Some commands may be able to recover inside the library,
175 /// so a special exception is used, that includes the response code.
177 class BXEXPORT BadPacket : public Barry::Error
179 uint8_t m_response;
181 public:
182 BadPacket(uint8_t response, const std::string &msg)
183 : Barry::Error(msg)
184 , m_response(response)
187 uint8_t response() const { return m_response; }
191 // ConvertError
193 /// Thrown by the vformat related barrysync library classes.
195 class BXEXPORT ConvertError : public Barry::Error
197 public:
198 ConvertError(const std::string &msg) : Barry::Error(msg) {}
202 // BackupError
204 /// Thrown by the Backup parser class when there is a problem with the
205 /// low level file operation.
207 class BXEXPORT BackupError : public Barry::Error
209 public:
210 BackupError(const std::string &str) : Error(str) {}
214 // RestoreError
216 /// Thrown by the Restore builder class when there is a problem with the
217 /// low level file operation.
219 class BXEXPORT RestoreError : public Barry::Error
221 public:
222 RestoreError(const std::string &str) : Error(str) {}
225 /// @}
227 } // namespace Barry
229 #endif