X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fcontext.h;h=d5fa117b22b03b09ec54fdd1188cf47380bf1872;hb=ef81d04eef4b1a60ff42bd9ccbe2918b0a5420ec;hp=fb3150a10142f9b8f1ec17dafd0be80269bbb4d7;hpb=0dd40125c555ccfc6b018eda8107fa1aa101c43e;p=platform%2Fupstream%2Flibxkbcommon.git diff --git a/src/context.h b/src/context.h index fb3150a..d5fa117 100644 --- a/src/context.h +++ b/src/context.h @@ -27,9 +27,38 @@ #define CONTEXT_H #include "atom.h" +#include "messages-codes.h" -unsigned -xkb_context_take_file_id(struct xkb_context *ctx); +struct xkb_context { + int refcnt; + + ATTR_PRINTF(3, 0) void (*log_fn)(struct xkb_context *ctx, + enum xkb_log_level level, + const char *fmt, va_list args); + enum xkb_log_level log_level; + int log_verbosity; + void *user_data; + + struct xkb_rule_names names_dflt; + + darray(char *) includes; + darray(char *) failed_includes; + + struct atom_table *atom_table; + + /* Used and allocated by xkbcommon-x11, free()d with the context. */ + void *x11_atom_cache; + + /* Buffer for the *Text() functions. */ + char text_buffer[2048]; + size_t text_next; + + unsigned int use_environment_names : 1; + unsigned int use_secure_getenv : 1; +}; + +char * +xkb_context_getenv(struct xkb_context *ctx, const char *name); unsigned int xkb_context_num_failed_include_paths(struct xkb_context *ctx); @@ -38,6 +67,12 @@ const char * xkb_context_failed_include_path_get(struct xkb_context *ctx, unsigned int idx); +const char * +xkb_context_include_path_get_extra_path(struct xkb_context *ctx); + +const char * +xkb_context_include_path_get_system_path(struct xkb_context *ctx); + /* * Returns XKB_ATOM_NONE if @string was not previously interned, * otherwise returns the atom. @@ -46,36 +81,33 @@ xkb_atom_t xkb_atom_lookup(struct xkb_context *ctx, const char *string); xkb_atom_t -xkb_atom_intern(struct xkb_context *ctx, const char *string); +xkb_atom_intern(struct xkb_context *ctx, const char *string, size_t len); + +#define xkb_atom_intern_literal(ctx, literal) \ + xkb_atom_intern((ctx), (literal), sizeof(literal) - 1) /** - * If @string is dynamically allocated, free'd immediately after - * being interned, and not used afterwards, use this function + * If @string is dynamically allocated, NUL-terminated, free'd immediately + * after being interned, and not used afterwards, use this function * instead of xkb_atom_intern to avoid some unnecessary allocations. * The caller should not use or free the passed in string afterwards. */ xkb_atom_t xkb_atom_steal(struct xkb_context *ctx, char *string); -char * -xkb_atom_strdup(struct xkb_context *ctx, xkb_atom_t atom); - const char * xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom); -ATTR_PRINTF(3, 4) void -xkb_log(struct xkb_context *ctx, enum xkb_log_level level, - const char *fmt, ...); +char * +xkb_context_get_buffer(struct xkb_context *ctx, size_t size); -#define xkb_log_cond_level(ctx, level, ...) do { \ - if (xkb_context_get_log_level(ctx) >= (level)) \ - xkb_log((ctx), (level), __VA_ARGS__); \ -} while (0) +ATTR_PRINTF(4, 5) void +xkb_log(struct xkb_context *ctx, enum xkb_log_level level, int verbosity, + const char *fmt, ...); -#define xkb_log_cond_verbosity(ctx, level, vrb, ...) do { \ - if (xkb_context_get_log_verbosity(ctx) >= (vrb)) \ - xkb_log_cond_level((ctx), (level), __VA_ARGS__); \ -} while (0) +void +xkb_context_sanitize_rule_names(struct xkb_context *ctx, + struct xkb_rule_names *rmlvo); /* * The format is not part of the argument list in order to avoid the @@ -83,17 +115,42 @@ xkb_log(struct xkb_context *ctx, enum xkb_log_level level, * format is supplied without arguments. Not supplying it would still * result in an error, though. */ +#define xkb_log_with_code(ctx, level, verbosity, msg_id, fmt, ...) \ + xkb_log(ctx, level, verbosity, "[XKB-%03d] " fmt, \ + msg_id, ##__VA_ARGS__) +#define log_dbg_with_code(ctx, id, ...) \ + xkb_log_with_code((ctx), XKB_LOG_LEVEL_DEBUG, 0, (id), __VA_ARGS__) #define log_dbg(ctx, ...) \ - xkb_log_cond_level((ctx), XKB_LOG_LEVEL_DEBUG, __VA_ARGS__) + xkb_log((ctx), XKB_LOG_LEVEL_DEBUG, 0, __VA_ARGS__) +#define log_info_with_code(ctx, id, ...) \ + xkb_log_with_code((ctx), XKB_LOG_LEVEL_INFO, 0, (id), __VA_ARGS__) #define log_info(ctx, ...) \ - xkb_log_cond_level((ctx), XKB_LOG_LEVEL_INFO, __VA_ARGS__) + xkb_log((ctx), XKB_LOG_LEVEL_INFO, 0, __VA_ARGS__) +#define log_warn_with_code(ctx, id, ...) \ + xkb_log_with_code((ctx), XKB_LOG_LEVEL_WARNING, 0, (id), __VA_ARGS__) #define log_warn(ctx, ...) \ - xkb_log_cond_level((ctx), XKB_LOG_LEVEL_WARNING, __VA_ARGS__) + xkb_log((ctx), XKB_LOG_LEVEL_WARNING, 0, __VA_ARGS__) +#define log_err_with_code(ctx, id, ...) \ + xkb_log_with_code((ctx), XKB_LOG_LEVEL_ERROR, 0, (id), __VA_ARGS__) #define log_err(ctx, ...) \ - xkb_log_cond_level((ctx), XKB_LOG_LEVEL_ERROR, __VA_ARGS__) + xkb_log((ctx), XKB_LOG_LEVEL_ERROR, 0, __VA_ARGS__) +#define log_wsgo_with_code(ctx, id, ...) \ + xkb_log_with_code((ctx), XKB_LOG_LEVEL_CRITICAL, 0, (id), __VA_ARGS__) #define log_wsgo(ctx, ...) \ - xkb_log_cond_level((ctx), XKB_LOG_LEVEL_CRITICAL, __VA_ARGS__) + xkb_log((ctx), XKB_LOG_LEVEL_CRITICAL, 0, __VA_ARGS__) +#define log_vrb_with_code(ctx, vrb, id, ...) \ + xkb_log_with_code((ctx), XKB_LOG_LEVEL_WARNING, (vrb), (id), __VA_ARGS__) #define log_vrb(ctx, vrb, ...) \ - xkb_log_cond_verbosity((ctx), XKB_LOG_LEVEL_WARNING, (vrb), __VA_ARGS__) + xkb_log((ctx), XKB_LOG_LEVEL_WARNING, (vrb), __VA_ARGS__) + +/* + * Variants which are prefixed by the name of the function they're + * called from. + * Here we must have the silly 1 variant. + */ +#define log_err_func(ctx, fmt, ...) \ + log_err(ctx, "%s: " fmt, __func__, __VA_ARGS__) +#define log_err_func1(ctx, fmt) \ + log_err(ctx, "%s: " fmt, __func__) #endif