- added pause to maintainer release script
[barry.git] / src / error.h
blobd07293bf66fda946f0c59360538d02176368f9fc
1 ///
2 /// \file error.h
3 /// Common exception classes for the Barry library
4 ///
6 /*
7 Copyright (C) 2005-2007, 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 <stdexcept>
27 namespace Barry {
29 /// \addtogroup exceptions
30 /// @{
33 // Error class
35 /// The base class for any future derived exceptions.
36 /// Can be thrown on any protocol error.
37 ///
38 class Error : public std::runtime_error
40 public:
41 Error(const std::string &str) : std::runtime_error(str) {}
46 // BadPassword
48 /// A bad or unknown password when talking to the device.
49 /// Can be thrown in the following instances:
50 ///
51 /// - no password provided and the device requests one
52 /// - device rejected the available password
53 /// - too few remaining tries left... Barry will refuse to keep
54 /// trying passwords if there are fewer than
55 /// 6 tries remaining. In this case, out_of_tries()
56 /// will return true.
57 ///
58 ///
59 class BadPassword : public Barry::Error
61 int m_remaining_tries;
62 bool m_out_of_tries;
64 public:
65 BadPassword(const std::string &str, int remaining_tries,
66 bool out_of_tries)
67 : Barry::Error(str),
68 m_remaining_tries(remaining_tries),
69 m_out_of_tries(out_of_tries)
71 int remaining_tries() const { return m_remaining_tries; }
72 bool out_of_tries() const { return m_out_of_tries; }
76 // BadSize
78 /// Unexpected packet size, or not enough data.
79 ///
80 class BadSize : public Barry::Error
82 unsigned int m_packet_size,
83 m_data_buf_size,
84 m_required_size;
86 static std::string GetMsg(unsigned int p, unsigned int d, unsigned int r);
88 public:
89 BadSize(unsigned int packet_size,
90 unsigned int data_buf_size,
91 unsigned int required_size)
92 : Barry::Error(GetMsg(packet_size, data_buf_size, required_size)),
93 m_packet_size(packet_size),
94 m_data_buf_size(data_buf_size),
95 m_required_size(required_size)
97 unsigned int packet_size() const { return m_packet_size; }
98 unsigned int data_buf_size() const { return m_data_buf_size; }
99 unsigned int required_size() const { return m_required_size; }
102 /// @}
104 } // namespace Barry
106 #endif