1 | /* |
2 | assuanresult.cpp - wraps a gpgme assuan result |
3 | Copyright (C) 2009 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 | #include <gpgme++/config-gpgme++.h> |
24 | |
25 | #include <gpgme++/assuanresult.h> |
26 | #include "result_p.h" |
27 | |
28 | #include <gpgme.h> |
29 | |
30 | #include <istream> |
31 | |
32 | using namespace GpgME; |
33 | |
34 | #ifdef HAVE_GPGME_ASSUAN_ENGINE |
35 | class AssuanResult::Private { |
36 | public: |
37 | explicit Private( const gpgme_assuan_result_t r ) { |
38 | if ( !r ) { |
39 | return; |
40 | } |
41 | error = r->err; |
42 | } |
43 | |
44 | gpgme_error_t error; |
45 | }; |
46 | #endif |
47 | |
48 | AssuanResult::AssuanResult( gpgme_ctx_t ctx, int error ) |
49 | : Result( error ), d() |
50 | { |
51 | init( ctx ); |
52 | } |
53 | |
54 | AssuanResult::AssuanResult( gpgme_ctx_t ctx, const Error & error ) |
55 | : Result( error ), d() |
56 | { |
57 | init( ctx ); |
58 | } |
59 | |
60 | void AssuanResult::init( gpgme_ctx_t ctx ) { |
61 | (void)ctx; |
62 | #ifdef HAVE_GPGME_ASSUAN_ENGINE |
63 | if ( !ctx ) { |
64 | return; |
65 | } |
66 | gpgme_assuan_result_t res = gpgme_op_assuan_result( ctx ); |
67 | if ( !res ) { |
68 | return; |
69 | } |
70 | d.reset( new Private( res ) ); |
71 | #endif |
72 | } |
73 | |
74 | make_standard_stuff(AssuanResult) |
75 | |
76 | Error AssuanResult::assuanError() const { |
77 | #ifdef HAVE_GPGME_ASSUAN_ENGINE |
78 | if ( d ) { |
79 | return Error( d->error ); |
80 | } |
81 | #endif |
82 | return Error(); |
83 | } |
84 | |
85 | std::ostream & GpgME::operator<<( std::ostream & os, const AssuanResult & result ) { |
86 | os << "GpgME::AssuanResult(" ; |
87 | if ( !result.isNull() ) { |
88 | os << "\n error: " << result.error() |
89 | << "\n assuanError: " << result.assuanError() |
90 | << "\n" ; |
91 | } |
92 | return os << ')'; |
93 | } |
94 | |