xref: /aosp_15_r20/external/libxkbcommon/src/context.h (revision 2b949d0487e80d67f1fda82db69e101e761f8064)
1*2b949d04SAndroid Build Coastguard Worker /*
2*2b949d04SAndroid Build Coastguard Worker  * Copyright © 2012 Intel Corporation
3*2b949d04SAndroid Build Coastguard Worker  *
4*2b949d04SAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a
5*2b949d04SAndroid Build Coastguard Worker  * copy of this software and associated documentation files (the "Software"),
6*2b949d04SAndroid Build Coastguard Worker  * to deal in the Software without restriction, including without limitation
7*2b949d04SAndroid Build Coastguard Worker  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*2b949d04SAndroid Build Coastguard Worker  * and/or sell copies of the Software, and to permit persons to whom the
9*2b949d04SAndroid Build Coastguard Worker  * Software is furnished to do so, subject to the following conditions:
10*2b949d04SAndroid Build Coastguard Worker  *
11*2b949d04SAndroid Build Coastguard Worker  * The above copyright notice and this permission notice (including the next
12*2b949d04SAndroid Build Coastguard Worker  * paragraph) shall be included in all copies or substantial portions of the
13*2b949d04SAndroid Build Coastguard Worker  * Software.
14*2b949d04SAndroid Build Coastguard Worker  *
15*2b949d04SAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*2b949d04SAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*2b949d04SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*2b949d04SAndroid Build Coastguard Worker  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*2b949d04SAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*2b949d04SAndroid Build Coastguard Worker  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*2b949d04SAndroid Build Coastguard Worker  * DEALINGS IN THE SOFTWARE.
22*2b949d04SAndroid Build Coastguard Worker  *
23*2b949d04SAndroid Build Coastguard Worker  * Author: Daniel Stone <[email protected]>
24*2b949d04SAndroid Build Coastguard Worker  */
25*2b949d04SAndroid Build Coastguard Worker 
26*2b949d04SAndroid Build Coastguard Worker #ifndef CONTEXT_H
27*2b949d04SAndroid Build Coastguard Worker #define CONTEXT_H
28*2b949d04SAndroid Build Coastguard Worker 
29*2b949d04SAndroid Build Coastguard Worker #include "atom.h"
30*2b949d04SAndroid Build Coastguard Worker 
31*2b949d04SAndroid Build Coastguard Worker struct xkb_context {
32*2b949d04SAndroid Build Coastguard Worker     int refcnt;
33*2b949d04SAndroid Build Coastguard Worker 
34*2b949d04SAndroid Build Coastguard Worker     ATTR_PRINTF(3, 0) void (*log_fn)(struct xkb_context *ctx,
35*2b949d04SAndroid Build Coastguard Worker                                      enum xkb_log_level level,
36*2b949d04SAndroid Build Coastguard Worker                                      const char *fmt, va_list args);
37*2b949d04SAndroid Build Coastguard Worker     enum xkb_log_level log_level;
38*2b949d04SAndroid Build Coastguard Worker     int log_verbosity;
39*2b949d04SAndroid Build Coastguard Worker     void *user_data;
40*2b949d04SAndroid Build Coastguard Worker 
41*2b949d04SAndroid Build Coastguard Worker     struct xkb_rule_names names_dflt;
42*2b949d04SAndroid Build Coastguard Worker 
43*2b949d04SAndroid Build Coastguard Worker     darray(char *) includes;
44*2b949d04SAndroid Build Coastguard Worker     darray(char *) failed_includes;
45*2b949d04SAndroid Build Coastguard Worker 
46*2b949d04SAndroid Build Coastguard Worker     struct atom_table *atom_table;
47*2b949d04SAndroid Build Coastguard Worker 
48*2b949d04SAndroid Build Coastguard Worker     /* Used and allocated by xkbcommon-x11, free()d with the context. */
49*2b949d04SAndroid Build Coastguard Worker     void *x11_atom_cache;
50*2b949d04SAndroid Build Coastguard Worker 
51*2b949d04SAndroid Build Coastguard Worker     /* Buffer for the *Text() functions. */
52*2b949d04SAndroid Build Coastguard Worker     char text_buffer[2048];
53*2b949d04SAndroid Build Coastguard Worker     size_t text_next;
54*2b949d04SAndroid Build Coastguard Worker 
55*2b949d04SAndroid Build Coastguard Worker     unsigned int use_environment_names : 1;
56*2b949d04SAndroid Build Coastguard Worker };
57*2b949d04SAndroid Build Coastguard Worker 
58*2b949d04SAndroid Build Coastguard Worker unsigned int
59*2b949d04SAndroid Build Coastguard Worker xkb_context_num_failed_include_paths(struct xkb_context *ctx);
60*2b949d04SAndroid Build Coastguard Worker 
61*2b949d04SAndroid Build Coastguard Worker const char *
62*2b949d04SAndroid Build Coastguard Worker xkb_context_failed_include_path_get(struct xkb_context *ctx,
63*2b949d04SAndroid Build Coastguard Worker                                     unsigned int idx);
64*2b949d04SAndroid Build Coastguard Worker 
65*2b949d04SAndroid Build Coastguard Worker const char *
66*2b949d04SAndroid Build Coastguard Worker xkb_context_include_path_get_extra_path(struct xkb_context *ctx);
67*2b949d04SAndroid Build Coastguard Worker 
68*2b949d04SAndroid Build Coastguard Worker const char *
69*2b949d04SAndroid Build Coastguard Worker xkb_context_include_path_get_system_path(struct xkb_context *ctx);
70*2b949d04SAndroid Build Coastguard Worker 
71*2b949d04SAndroid Build Coastguard Worker /*
72*2b949d04SAndroid Build Coastguard Worker  * Returns XKB_ATOM_NONE if @string was not previously interned,
73*2b949d04SAndroid Build Coastguard Worker  * otherwise returns the atom.
74*2b949d04SAndroid Build Coastguard Worker  */
75*2b949d04SAndroid Build Coastguard Worker xkb_atom_t
76*2b949d04SAndroid Build Coastguard Worker xkb_atom_lookup(struct xkb_context *ctx, const char *string);
77*2b949d04SAndroid Build Coastguard Worker 
78*2b949d04SAndroid Build Coastguard Worker xkb_atom_t
79*2b949d04SAndroid Build Coastguard Worker xkb_atom_intern(struct xkb_context *ctx, const char *string, size_t len);
80*2b949d04SAndroid Build Coastguard Worker 
81*2b949d04SAndroid Build Coastguard Worker #define xkb_atom_intern_literal(ctx, literal) \
82*2b949d04SAndroid Build Coastguard Worker     xkb_atom_intern((ctx), (literal), sizeof(literal) - 1)
83*2b949d04SAndroid Build Coastguard Worker 
84*2b949d04SAndroid Build Coastguard Worker /**
85*2b949d04SAndroid Build Coastguard Worker  * If @string is dynamically allocated, NUL-terminated, free'd immediately
86*2b949d04SAndroid Build Coastguard Worker  * after being interned, and not used afterwards, use this function
87*2b949d04SAndroid Build Coastguard Worker  * instead of xkb_atom_intern to avoid some unnecessary allocations.
88*2b949d04SAndroid Build Coastguard Worker  * The caller should not use or free the passed in string afterwards.
89*2b949d04SAndroid Build Coastguard Worker  */
90*2b949d04SAndroid Build Coastguard Worker xkb_atom_t
91*2b949d04SAndroid Build Coastguard Worker xkb_atom_steal(struct xkb_context *ctx, char *string);
92*2b949d04SAndroid Build Coastguard Worker 
93*2b949d04SAndroid Build Coastguard Worker const char *
94*2b949d04SAndroid Build Coastguard Worker xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);
95*2b949d04SAndroid Build Coastguard Worker 
96*2b949d04SAndroid Build Coastguard Worker char *
97*2b949d04SAndroid Build Coastguard Worker xkb_context_get_buffer(struct xkb_context *ctx, size_t size);
98*2b949d04SAndroid Build Coastguard Worker 
99*2b949d04SAndroid Build Coastguard Worker ATTR_PRINTF(4, 5) void
100*2b949d04SAndroid Build Coastguard Worker xkb_log(struct xkb_context *ctx, enum xkb_log_level level, int verbosity,
101*2b949d04SAndroid Build Coastguard Worker         const char *fmt, ...);
102*2b949d04SAndroid Build Coastguard Worker 
103*2b949d04SAndroid Build Coastguard Worker void
104*2b949d04SAndroid Build Coastguard Worker xkb_context_sanitize_rule_names(struct xkb_context *ctx,
105*2b949d04SAndroid Build Coastguard Worker                                 struct xkb_rule_names *rmlvo);
106*2b949d04SAndroid Build Coastguard Worker 
107*2b949d04SAndroid Build Coastguard Worker /*
108*2b949d04SAndroid Build Coastguard Worker  * The format is not part of the argument list in order to avoid the
109*2b949d04SAndroid Build Coastguard Worker  * "ISO C99 requires rest arguments to be used" warning when only the
110*2b949d04SAndroid Build Coastguard Worker  * format is supplied without arguments. Not supplying it would still
111*2b949d04SAndroid Build Coastguard Worker  * result in an error, though.
112*2b949d04SAndroid Build Coastguard Worker  */
113*2b949d04SAndroid Build Coastguard Worker #define log_dbg(ctx, ...) \
114*2b949d04SAndroid Build Coastguard Worker     xkb_log((ctx), XKB_LOG_LEVEL_DEBUG, 0, __VA_ARGS__)
115*2b949d04SAndroid Build Coastguard Worker #define log_info(ctx, ...) \
116*2b949d04SAndroid Build Coastguard Worker     xkb_log((ctx), XKB_LOG_LEVEL_INFO, 0, __VA_ARGS__)
117*2b949d04SAndroid Build Coastguard Worker #define log_warn(ctx, ...) \
118*2b949d04SAndroid Build Coastguard Worker     xkb_log((ctx), XKB_LOG_LEVEL_WARNING, 0,  __VA_ARGS__)
119*2b949d04SAndroid Build Coastguard Worker #define log_err(ctx, ...) \
120*2b949d04SAndroid Build Coastguard Worker     xkb_log((ctx), XKB_LOG_LEVEL_ERROR, 0,  __VA_ARGS__)
121*2b949d04SAndroid Build Coastguard Worker #define log_wsgo(ctx, ...) \
122*2b949d04SAndroid Build Coastguard Worker     xkb_log((ctx), XKB_LOG_LEVEL_CRITICAL, 0, __VA_ARGS__)
123*2b949d04SAndroid Build Coastguard Worker #define log_vrb(ctx, vrb, ...) \
124*2b949d04SAndroid Build Coastguard Worker     xkb_log((ctx), XKB_LOG_LEVEL_WARNING, (vrb), __VA_ARGS__)
125*2b949d04SAndroid Build Coastguard Worker 
126*2b949d04SAndroid Build Coastguard Worker /*
127*2b949d04SAndroid Build Coastguard Worker  * Variants which are prefixed by the name of the function they're
128*2b949d04SAndroid Build Coastguard Worker  * called from.
129*2b949d04SAndroid Build Coastguard Worker  * Here we must have the silly 1 variant.
130*2b949d04SAndroid Build Coastguard Worker  */
131*2b949d04SAndroid Build Coastguard Worker #define log_err_func(ctx, fmt, ...) \
132*2b949d04SAndroid Build Coastguard Worker     log_err(ctx, "%s: " fmt, __func__, __VA_ARGS__)
133*2b949d04SAndroid Build Coastguard Worker #define log_err_func1(ctx, fmt) \
134*2b949d04SAndroid Build Coastguard Worker     log_err(ctx, "%s: " fmt, __func__)
135*2b949d04SAndroid Build Coastguard Worker 
136*2b949d04SAndroid Build Coastguard Worker #endif
137