Marius Vlad | e0a858a | 2019-06-25 12:48:56 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2019 Collabora Ltd |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
| 24 | */ |
| 25 | #ifndef WESTON_LOG_INTERNAL_H |
| 26 | #define WESTON_LOG_INTERNAL_H |
| 27 | |
| 28 | #include "wayland-util.h" |
| 29 | |
Marius Vlad | 5ae0e62 | 2019-07-11 17:44:50 +0300 | [diff] [blame] | 30 | struct weston_log_subscription; |
| 31 | |
Marius Vlad | e0a858a | 2019-06-25 12:48:56 +0300 | [diff] [blame] | 32 | /** Subscriber allows each type of stream to customize or to provide its own |
| 33 | * methods to manipulate the underlying storage. It follows also an |
| 34 | * object-oriented approach, contains the ops callbacks and a list of |
| 35 | * subcriptions of type weston_log_subscription. Each subscription created will |
| 36 | * be both added to this subscription list and that of the weston_log_scope. |
| 37 | * |
| 38 | * A kind of stream can inherit the subscriber class and provide its own callbacks: |
| 39 | * @code |
| 40 | * struct weston_log_data_stream { |
| 41 | * struct weston_log_subscriber base; |
| 42 | * struct weston_data_stream opaque; |
| 43 | * }; |
| 44 | * @endcode |
| 45 | * |
| 46 | * Passing the base class will require container retrieval type of methods |
| 47 | * to be allowed to reach the opaque type (i.e., container_of()). |
| 48 | * |
Marius Vlad | 8b8b803 | 2019-06-27 18:34:03 +0300 | [diff] [blame] | 49 | * @ingroup internal-log |
Marius Vlad | e0a858a | 2019-06-25 12:48:56 +0300 | [diff] [blame] | 50 | * |
| 51 | */ |
| 52 | struct weston_log_subscriber { |
| 53 | /** write the data pointed by @param data */ |
| 54 | void (*write)(struct weston_log_subscriber *sub, const char *data, size_t len); |
Leandro Ribeiro | 1ded661 | 2020-02-06 16:43:51 -0300 | [diff] [blame] | 55 | /** For destroying the subscriber */ |
| 56 | void (*destroy)(struct weston_log_subscriber *sub); |
Marius Vlad | e0a858a | 2019-06-25 12:48:56 +0300 | [diff] [blame] | 57 | /** For the type of streams that required additional destroy operation |
| 58 | * for destroying the stream */ |
Leandro Ribeiro | 8c02ea1 | 2020-02-06 15:41:32 -0300 | [diff] [blame] | 59 | void (*destroy_subscription)(struct weston_log_subscriber *sub); |
Marius Vlad | e0a858a | 2019-06-25 12:48:56 +0300 | [diff] [blame] | 60 | /** For the type of streams that can inform the 'consumer' part that |
| 61 | * write operation has been terminated/finished and should close the |
| 62 | * stream. |
| 63 | */ |
| 64 | void (*complete)(struct weston_log_subscriber *sub); |
| 65 | struct wl_list subscription_list; /**< weston_log_subscription::owner_link */ |
| 66 | }; |
| 67 | |
Marius Vlad | 5ae0e62 | 2019-07-11 17:44:50 +0300 | [diff] [blame] | 68 | void |
Marius Vlad | e0a858a | 2019-06-25 12:48:56 +0300 | [diff] [blame] | 69 | weston_log_subscription_create(struct weston_log_subscriber *owner, |
Marius Vlad | 5ae0e62 | 2019-07-11 17:44:50 +0300 | [diff] [blame] | 70 | struct weston_log_scope *scope); |
Marius Vlad | e0a858a | 2019-06-25 12:48:56 +0300 | [diff] [blame] | 71 | |
| 72 | void |
| 73 | weston_log_subscription_destroy(struct weston_log_subscription *sub); |
| 74 | |
Marius Vlad | e0a858a | 2019-06-25 12:48:56 +0300 | [diff] [blame] | 75 | void |
| 76 | weston_log_subscription_add(struct weston_log_scope *scope, |
| 77 | struct weston_log_subscription *sub); |
| 78 | void |
| 79 | weston_log_subscription_remove(struct weston_log_subscription *sub); |
| 80 | |
Marius Vlad | 69e7571 | 2019-06-25 13:29:57 +0300 | [diff] [blame] | 81 | void |
Leandro Ribeiro | 23491cd | 2020-02-03 22:59:16 -0300 | [diff] [blame] | 82 | weston_log_subscriber_release(struct weston_log_subscriber *subscriber); |
| 83 | |
| 84 | void |
Marius Vlad | 69e7571 | 2019-06-25 13:29:57 +0300 | [diff] [blame] | 85 | weston_log_bind_weston_debug(struct wl_client *client, |
| 86 | void *data, uint32_t version, uint32_t id); |
| 87 | |
Marius Vlad | 8f329e2 | 2019-06-21 14:57:02 +0300 | [diff] [blame] | 88 | struct weston_log_scope * |
| 89 | weston_log_get_scope(struct weston_log_context *log_ctx, const char *name); |
| 90 | |
| 91 | void |
Marius Vlad | 0c7beb0 | 2019-07-25 11:46:44 +0300 | [diff] [blame] | 92 | weston_log_run_cb_new_subscription(struct weston_log_subscription *sub); |
Marius Vlad | 8f329e2 | 2019-06-21 14:57:02 +0300 | [diff] [blame] | 93 | |
| 94 | void |
| 95 | weston_debug_protocol_advertise_scopes(struct weston_log_context *log_ctx, |
| 96 | struct wl_resource *res); |
Marius Vlad | 4e03629 | 2019-07-09 00:36:20 +0300 | [diff] [blame] | 97 | |
| 98 | int |
| 99 | weston_vlog(const char *fmt, va_list ap); |
| 100 | int |
| 101 | weston_vlog_continue(const char *fmt, va_list ap); |
Marius Vlad | 8f329e2 | 2019-06-21 14:57:02 +0300 | [diff] [blame] | 102 | |
Marius Vlad | 410d0bc | 2019-07-29 12:05:29 +0300 | [diff] [blame] | 103 | void * |
| 104 | weston_log_subscription_get_data(struct weston_log_subscription *sub); |
| 105 | |
| 106 | void |
| 107 | weston_log_subscription_set_data(struct weston_log_subscription *sub, void *data); |
| 108 | |
Marius Vlad | da104eb | 2019-09-05 14:31:01 +0300 | [diff] [blame] | 109 | void |
| 110 | weston_timeline_create_subscription(struct weston_log_subscription *sub, |
| 111 | void *user_data); |
| 112 | |
| 113 | void |
| 114 | weston_timeline_destroy_subscription(struct weston_log_subscription *sub, |
| 115 | void *user_data); |
| 116 | |
Marius Vlad | e0a858a | 2019-06-25 12:48:56 +0300 | [diff] [blame] | 117 | #endif /* WESTON_LOG_INTERNAL_H */ |