Line data Source code
1 : /*
2 : error.h - wraps a gpgme error
3 : Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB
4 :
5 : This file is part of GPGME++.
6 :
7 : GPGME++ is free software; you can redistribute it and/or
8 : modify it under the terms of the GNU Library General Public
9 : License as published by the Free Software Foundation; either
10 : version 2 of the License, or (at your option) any later version.
11 :
12 : GPGME++ is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU Library General Public License for more details.
16 :
17 : You should have received a copy of the GNU Library General Public License
18 : along with GPGME++; see the file COPYING.LIB. If not, write to the
19 : Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 : Boston, MA 02110-1301, USA.
21 : */
22 :
23 : // -*- c++ -*-
24 : #ifndef __GPGMEPP_ERROR_H__
25 : #define __GPGMEPP_ERROR_H__
26 :
27 : #include "global.h"
28 :
29 : #include <string>
30 : #include <iosfwd>
31 :
32 : #include <gpg-error.h>
33 :
34 : #ifndef GPGMEPP_ERR_SOURCE_DEFAULT
35 : # define GPGMEPP_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_USER_1
36 : #endif
37 :
38 : namespace GpgME
39 : {
40 :
41 994 : class GPGMEPP_EXPORT Error
42 : {
43 : public:
44 217 : Error() : mErr(0), mMessage() {}
45 149 : explicit Error(unsigned int e) : mErr(e), mMessage() {}
46 :
47 : const char *source() const;
48 : const char *asString() const;
49 :
50 : int code() const;
51 : int sourceID() const;
52 :
53 : bool isCanceled() const;
54 :
55 28 : unsigned int encodedError() const
56 : {
57 28 : return mErr;
58 : }
59 : int toErrno() const;
60 :
61 : static bool hasSystemError();
62 : static Error fromSystemError(unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT);
63 : static void setSystemError(gpg_err_code_t err);
64 : static void setErrno(int err);
65 : static Error fromErrno(int err, unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT);
66 : static Error fromCode(unsigned int err, unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT);
67 :
68 214 : GPGMEPP_MAKE_SAFE_BOOL_OPERATOR(mErr &&!isCanceled())
69 : private:
70 : unsigned int mErr;
71 : mutable std::string mMessage;
72 : };
73 :
74 : GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Error &err);
75 :
76 : } // namespace GpgME
77 :
78 : #endif /* __GPGMEPP_ERROR_H__ */
|