| 1 | /* |
| 2 | * Copyright (C) 2020 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef LTTNG_LOG_LEVEL_RULE_H |
| 9 | #define LTTNG_LOG_LEVEL_RULE_H |
| 10 | |
| 11 | #include <lttng/lttng-export.h> |
| 12 | |
| 13 | #ifdef __cplusplus |
| 14 | extern "C" { |
| 15 | #endif |
| 16 | |
| 17 | struct lttng_log_level_rule; |
| 18 | |
| 19 | enum lttng_log_level_rule_type { |
| 20 | LTTNG_LOG_LEVEL_RULE_TYPE_UNKNOWN = -1, |
| 21 | LTTNG_LOG_LEVEL_RULE_TYPE_EXACTLY = 0, |
| 22 | LTTNG_LOG_LEVEL_RULE_TYPE_AT_LEAST_AS_SEVERE_AS = 1, |
| 23 | }; |
| 24 | |
| 25 | enum lttng_log_level_rule_status { |
| 26 | LTTNG_LOG_LEVEL_RULE_STATUS_OK = 0, |
| 27 | LTTNG_LOG_LEVEL_RULE_STATUS_ERROR = -1, |
| 28 | LTTNG_LOG_LEVEL_RULE_STATUS_INVALID = -3, |
| 29 | }; |
| 30 | |
| 31 | /* |
| 32 | * Returns the type of the log level rule `rule`, or: |
| 33 | * |
| 34 | * `LTTNG_LOG_LEVEL_RULE_TYPE_UNKNOWN`: |
| 35 | * `rule` is `NULL`. |
| 36 | */ |
| 37 | LTTNG_EXPORT extern enum lttng_log_level_rule_type |
| 38 | lttng_log_level_rule_get_type(const struct lttng_log_level_rule *rule); |
| 39 | |
| 40 | /* |
| 41 | * Creates a log level rule for which a log level must match exactly `level` to |
| 42 | * be considered. |
| 43 | * |
| 44 | * Returns `NULL` if: |
| 45 | * |
| 46 | * * There's a memory error. |
| 47 | * |
| 48 | * The returned log level rule must be destroyed using |
| 49 | * lttng_log_level_rule_destroy(). |
| 50 | */ |
| 51 | LTTNG_EXPORT extern struct lttng_log_level_rule *lttng_log_level_rule_exactly_create(int level); |
| 52 | |
| 53 | /* |
| 54 | * Sets `level` to the level of the "exactly" log level rule `rule`. |
| 55 | * |
| 56 | * Returns: |
| 57 | * |
| 58 | * `LTTNG_LOG_LEVEL_RULE_STATUS_OK`: |
| 59 | * Success. |
| 60 | * |
| 61 | * `LTTNG_LOG_LEVEL_RULE_STATUS_INVALID`: |
| 62 | * * `rule` is NULL. |
| 63 | * * `level` is NULL. |
| 64 | * * The type of `rule` is not `LTTNG_LOG_LEVEL_RULE_TYPE_EXACTLY`. |
| 65 | */ |
| 66 | LTTNG_EXPORT extern enum lttng_log_level_rule_status |
| 67 | lttng_log_level_rule_exactly_get_level(const struct lttng_log_level_rule *rule, int *level); |
| 68 | |
| 69 | /* |
| 70 | * Creates a log level rule for which a log level must be at least as severe as |
| 71 | * `level` to be considered. |
| 72 | * |
| 73 | * Returns `NULL` if: |
| 74 | * |
| 75 | * * There's a memory error. |
| 76 | * |
| 77 | * The returned log level rule must be destroyed using |
| 78 | * lttng_log_level_rule_destroy(). |
| 79 | */ |
| 80 | LTTNG_EXPORT extern struct lttng_log_level_rule * |
| 81 | lttng_log_level_rule_at_least_as_severe_as_create(int level); |
| 82 | |
| 83 | /* |
| 84 | * Sets `level` to the level of the "at least as severe as" log level rule |
| 85 | * `rule`. |
| 86 | * |
| 87 | * Returns: |
| 88 | * |
| 89 | * `LTTNG_LOG_LEVEL_RULE_STATUS_OK`: |
| 90 | * Success. |
| 91 | * |
| 92 | * `LTTNG_LOG_LEVEL_RULE_STATUS_INVALID`: |
| 93 | * * `rule` is NULL. |
| 94 | * * `level` is NULL. |
| 95 | * * The type of `rule` is not |
| 96 | * `LTTNG_LOG_LEVEL_RULE_TYPE_AT_LEAST_AS_SEVERE_AS`. |
| 97 | */ |
| 98 | LTTNG_EXPORT extern enum lttng_log_level_rule_status |
| 99 | lttng_log_level_rule_at_least_as_severe_as_get_level(const struct lttng_log_level_rule *rule, |
| 100 | int *level); |
| 101 | |
| 102 | /* |
| 103 | * Destroy the log level rule `log_level_rule` if not `NULL`. |
| 104 | */ |
| 105 | LTTNG_EXPORT extern void lttng_log_level_rule_destroy(struct lttng_log_level_rule *log_level_rule); |
| 106 | |
| 107 | #ifdef __cplusplus |
| 108 | } |
| 109 | #endif |
| 110 | |
| 111 | #endif /* LTTNG_LOG_LEVEL_RULE_H */ |