Remove file_id entirely
[platform/upstream/libxkbcommon.git] / src / context.h
1 /*
2  * Copyright © 2012 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Author: Daniel Stone <daniel@fooishbar.org>
24  */
25
26 #ifndef CONTEXT_H
27 #define CONTEXT_H
28
29 #include "atom.h"
30
31 unsigned int
32 xkb_context_num_failed_include_paths(struct xkb_context *ctx);
33
34 const char *
35 xkb_context_failed_include_path_get(struct xkb_context *ctx,
36                                     unsigned int idx);
37
38 /*
39  * Returns XKB_ATOM_NONE if @string was not previously interned,
40  * otherwise returns the atom.
41  */
42 xkb_atom_t
43 xkb_atom_lookup(struct xkb_context *ctx, const char *string);
44
45 xkb_atom_t
46 xkb_atom_intern(struct xkb_context *ctx, const char *string);
47
48 /**
49  * If @string is dynamically allocated, free'd immediately after
50  * being interned, and not used afterwards, use this function
51  * instead of xkb_atom_intern to avoid some unnecessary allocations.
52  * The caller should not use or free the passed in string afterwards.
53  */
54 xkb_atom_t
55 xkb_atom_steal(struct xkb_context *ctx, char *string);
56
57 char *
58 xkb_atom_strdup(struct xkb_context *ctx, xkb_atom_t atom);
59
60 const char *
61 xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);
62
63 char *
64 xkb_context_get_buffer(struct xkb_context *ctx, size_t size);
65
66 ATTR_PRINTF(3, 4) void
67 xkb_log(struct xkb_context *ctx, enum xkb_log_level level,
68         const char *fmt, ...);
69
70 #define xkb_log_cond_level(ctx, level, ...) do { \
71     if (xkb_context_get_log_level(ctx) >= (level)) \
72     xkb_log((ctx), (level), __VA_ARGS__); \
73 } while (0)
74
75 #define xkb_log_cond_verbosity(ctx, level, vrb, ...) do { \
76     if (xkb_context_get_log_verbosity(ctx) >= (vrb)) \
77     xkb_log_cond_level((ctx), (level), __VA_ARGS__); \
78 } while (0)
79
80 /*
81  * The format is not part of the argument list in order to avoid the
82  * "ISO C99 requires rest arguments to be used" warning when only the
83  * format is supplied without arguments. Not supplying it would still
84  * result in an error, though.
85  */
86 #define log_dbg(ctx, ...) \
87     xkb_log_cond_level((ctx), XKB_LOG_LEVEL_DEBUG, __VA_ARGS__)
88 #define log_info(ctx, ...) \
89     xkb_log_cond_level((ctx), XKB_LOG_LEVEL_INFO, __VA_ARGS__)
90 #define log_warn(ctx, ...) \
91     xkb_log_cond_level((ctx), XKB_LOG_LEVEL_WARNING, __VA_ARGS__)
92 #define log_err(ctx, ...) \
93     xkb_log_cond_level((ctx), XKB_LOG_LEVEL_ERROR, __VA_ARGS__)
94 #define log_wsgo(ctx, ...) \
95     xkb_log_cond_level((ctx), XKB_LOG_LEVEL_CRITICAL, __VA_ARGS__)
96 #define log_vrb(ctx, vrb, ...) \
97     xkb_log_cond_verbosity((ctx), XKB_LOG_LEVEL_WARNING, (vrb), __VA_ARGS__)
98
99 /*
100  * Variants which are prefixed by the name of the function they're
101  * called from.
102  * Here we must have the silly 1 variant.
103  */
104 #define log_err_func(ctx, fmt, ...) \
105     log_err(ctx, "%s: " fmt, __func__, __VA_ARGS__)
106 #define log_err_func1(ctx, fmt) \
107     log_err(ctx, "%s: " fmt, __func__)
108
109 #endif