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 | |
| 30 | /** Subscriber allows each type of stream to customize or to provide its own |
| 31 | * methods to manipulate the underlying storage. It follows also an |
| 32 | * object-oriented approach, contains the ops callbacks and a list of |
| 33 | * subcriptions of type weston_log_subscription. Each subscription created will |
| 34 | * be both added to this subscription list and that of the weston_log_scope. |
| 35 | * |
| 36 | * A kind of stream can inherit the subscriber class and provide its own callbacks: |
| 37 | * @code |
| 38 | * struct weston_log_data_stream { |
| 39 | * struct weston_log_subscriber base; |
| 40 | * struct weston_data_stream opaque; |
| 41 | * }; |
| 42 | * @endcode |
| 43 | * |
| 44 | * Passing the base class will require container retrieval type of methods |
| 45 | * to be allowed to reach the opaque type (i.e., container_of()). |
| 46 | * |
| 47 | * @internal |
| 48 | * |
| 49 | */ |
| 50 | struct weston_log_subscriber { |
| 51 | /** write the data pointed by @param data */ |
| 52 | void (*write)(struct weston_log_subscriber *sub, const char *data, size_t len); |
| 53 | /** For the type of streams that required additional destroy operation |
| 54 | * for destroying the stream */ |
| 55 | void (*destroy)(struct weston_log_subscriber *sub); |
| 56 | /** For the type of streams that can inform the 'consumer' part that |
| 57 | * write operation has been terminated/finished and should close the |
| 58 | * stream. |
| 59 | */ |
| 60 | void (*complete)(struct weston_log_subscriber *sub); |
| 61 | struct wl_list subscription_list; /**< weston_log_subscription::owner_link */ |
| 62 | }; |
| 63 | |
| 64 | struct weston_log_subscription * |
| 65 | weston_log_subscription_create(struct weston_log_subscriber *owner, |
| 66 | const char *scope_name); |
| 67 | |
| 68 | void |
| 69 | weston_log_subscription_destroy(struct weston_log_subscription *sub); |
| 70 | |
| 71 | struct weston_log_subscription * |
| 72 | weston_log_subscriber_get_only_subscription(struct weston_log_subscriber *subscriber); |
| 73 | |
| 74 | void |
| 75 | weston_log_subscription_add(struct weston_log_scope *scope, |
| 76 | struct weston_log_subscription *sub); |
| 77 | void |
| 78 | weston_log_subscription_remove(struct weston_log_subscription *sub); |
| 79 | |
| 80 | #endif /* WESTON_LOG_INTERNAL_H */ |