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 #include "error.h"
00023 #include <sstream>
00024 #include <string.h>
00025
00026 using namespace std;
00027
00028 namespace Barry {
00029
00030
00031
00032
00033 BadSize::BadSize(const char *msg, unsigned int data_size,
00034 unsigned int required_size)
00035 : Barry::Error(GetMsg(msg, data_size, required_size))
00036 , m_packet_size(0)
00037 , m_data_buf_size(data_size)
00038 , m_required_size(required_size)
00039 {
00040 }
00041
00042 BadSize::BadSize(unsigned int packet_size,
00043 unsigned int data_buf_size,
00044 unsigned int required_size)
00045 : Barry::Error(GetMsg(packet_size, data_buf_size, required_size))
00046 , m_packet_size(packet_size)
00047 , m_data_buf_size(data_buf_size)
00048 , m_required_size(required_size)
00049 {
00050 }
00051
00052 std::string BadSize::GetMsg(const char *msg, unsigned int d, unsigned int r)
00053 {
00054 std::ostringstream oss;
00055 oss << msg << ": Bad packet size, not enough data: DataSize(): " << d
00056 << ". Required size: " << r;
00057 return oss.str();
00058 }
00059
00060 std::string BadSize::GetMsg(unsigned int p, unsigned int d, unsigned int r)
00061 {
00062 std::ostringstream oss;
00063 oss << "Bad packet size. Packet: " << p
00064 << ". DataSize(): " << d
00065 << ". Required size: " << r;
00066 return oss.str();
00067 }
00068
00069
00070
00071
00072
00073 ErrnoError::ErrnoError(const std::string &msg)
00074 : Barry::Error(msg)
00075 , m_errno(0)
00076 {
00077 }
00078
00079 ErrnoError::ErrnoError(const std::string &msg, int err)
00080 : Barry::Error(GetMsg(msg, err))
00081 , m_errno(err)
00082 {
00083 }
00084
00085 std::string ErrnoError::GetMsg(const std::string &msg, int err)
00086 {
00087 std::ostringstream oss;
00088 oss << msg << ": (errno " << err << ") " << strerror(err);
00089 return oss.str();
00090 }
00091
00092 }
00093