minimal build
[platform/upstream/gcr.git] / gcr / gcr-debug.h
1 /*
2  * Copyright (C) 2007 Nokia Corporation
3  * Copyright (C) 2007-2011 Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 #ifndef GCR_DEBUG_H
21 #define GCR_DEBUG_H
22
23 #include "config.h"
24
25 #include <glib.h>
26
27 G_BEGIN_DECLS
28
29 /* Please keep this enum in sync with #keys in gcr-debug.c */
30 typedef enum {
31         GCR_DEBUG_LIBRARY = 1 << 1,
32         GCR_DEBUG_CERTIFICATE_CHAIN = 1 << 2,
33         GCR_DEBUG_PARSE = 1 << 3,
34         GCR_DEBUG_GNUPG = 1 << 4,
35         GCR_DEBUG_TRUST = 1 << 5,
36         GCR_DEBUG_IMPORT = 1 << 6,
37         GCR_DEBUG_KEY = 1 << 7,
38         GCR_DEBUG_PROMPT = 1 << 8,
39         GCR_DEBUG_SECRET_EXCHANGE = 1 << 9,
40 } GcrDebugFlags;
41
42 gboolean           _gcr_debug_flag_is_set              (GcrDebugFlags flag);
43
44 void               _gcr_debug_set_flags                (const gchar *flags_string);
45
46 void               _gcr_debug_message                  (GcrDebugFlags flag,
47                                                         const gchar *format,
48                                                         ...) G_GNUC_PRINTF (2, 3);
49
50 G_END_DECLS
51
52 #endif /* GCR_DEBUG_H */
53
54 /* -----------------------------------------------------------------------------
55  * Below this point is outside the GCR_DEBUG_H guard - so it can take effect
56  * more than once. So you can do:
57  *
58  * #define DEBUG_FLAG GCR_DEBUG_ONE_THING
59  * #include "gcr-debug.h"
60  * ...
61  * DEBUG ("if we're debugging one thing");
62  * ...
63  * #undef DEBUG_FLAG
64  * #define DEBUG_FLAG GCR_DEBUG_OTHER_THING
65  * #include "gcr-debug.h"
66  * ...
67  * DEBUG ("if we're debugging the other thing");
68  * ...
69  */
70
71 #ifdef DEBUG_FLAG
72 #ifdef WITH_DEBUG
73
74 #undef _gcr_debug
75 #define _gcr_debug(format, ...) \
76         _gcr_debug_message (DEBUG_FLAG, "%s: " format, G_STRFUNC, ##__VA_ARGS__)
77
78 #undef _gcr_debugging
79 #define _gcr_debugging \
80         _gcr_debug_flag_is_set (DEBUG_FLAG)
81
82 #else /* !defined (WITH_DEBUG) */
83
84 #undef _gcr_debug
85 #define _gcr_debug(format, ...) \
86         do {} while (0)
87
88 #undef _gcr_debugging
89 #define _gcr_debugging 0
90
91 #endif /* !defined (WITH_DEBUG) */
92
93 #endif /* defined (DEBUG_FLAG) */