Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only) |
9f36eaed | 2 | * |
24591303 | 3 | * ringbuffer/iterator.h |
f3bc08c5 MD |
4 | * |
5 | * Ring buffer and channel iterators. | |
6 | * | |
886d51a3 | 7 | * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
f3bc08c5 MD |
8 | */ |
9 | ||
9f36eaed MJ |
10 | #ifndef _LIB_RING_BUFFER_ITERATOR_H |
11 | #define _LIB_RING_BUFFER_ITERATOR_H | |
12 | ||
24591303 MD |
13 | #include <ringbuffer/backend.h> |
14 | #include <ringbuffer/frontend.h> | |
15 | #include <ringbuffer/vfs.h> | |
f3bc08c5 MD |
16 | |
17 | /* | |
18 | * lib_ring_buffer_get_next_record advances the buffer read position to the next | |
19 | * record. It returns either the size of the next record, -EAGAIN if there is | |
20 | * currently no data available, or -ENODATA if no data is available and buffer | |
21 | * is finalized. | |
22 | */ | |
23 | extern ssize_t lib_ring_buffer_get_next_record(struct channel *chan, | |
24 | struct lib_ring_buffer *buf); | |
25 | ||
47d4b31d MD |
26 | /* |
27 | * Ensure that the current subbuffer is put after client code has read the | |
28 | * payload of the current record. Has an effect when the end of subbuffer is | |
29 | * reached. It is not required if get_next_record is called successively. | |
30 | * However, it should be invoked before returning data to user-space to ensure | |
31 | * that the get/put subbuffer state is quiescent. | |
32 | */ | |
33 | extern void lib_ring_buffer_put_current_record(struct lib_ring_buffer *buf); | |
34 | ||
f3bc08c5 MD |
35 | /* |
36 | * channel_get_next_record advances the buffer read position to the next record. | |
37 | * It returns either the size of the next record, -EAGAIN if there is currently | |
38 | * no data available, or -ENODATA if no data is available and buffer is | |
39 | * finalized. | |
40 | * Returns the current buffer in ret_buf. | |
41 | */ | |
42 | extern ssize_t channel_get_next_record(struct channel *chan, | |
43 | struct lib_ring_buffer **ret_buf); | |
44 | ||
45 | /** | |
46 | * read_current_record - copy the buffer current record into dest. | |
47 | * @buf: ring buffer | |
48 | * @dest: destination where the record should be copied | |
49 | * | |
50 | * dest should be large enough to contain the record. Returns the number of | |
51 | * bytes copied. | |
52 | */ | |
53 | static inline size_t read_current_record(struct lib_ring_buffer *buf, void *dest) | |
54 | { | |
55 | return lib_ring_buffer_read(&buf->backend, buf->iter.read_offset, | |
56 | dest, buf->iter.payload_len); | |
57 | } | |
58 | ||
59 | extern int lib_ring_buffer_iterator_open(struct lib_ring_buffer *buf); | |
60 | extern void lib_ring_buffer_iterator_release(struct lib_ring_buffer *buf); | |
61 | extern int channel_iterator_open(struct channel *chan); | |
62 | extern void channel_iterator_release(struct channel *chan); | |
63 | ||
64 | extern const struct file_operations channel_payload_file_operations; | |
65 | extern const struct file_operations lib_ring_buffer_payload_file_operations; | |
66 | ||
67 | /* | |
68 | * Used internally. | |
69 | */ | |
70 | int channel_iterator_init(struct channel *chan); | |
71 | void channel_iterator_unregister_notifiers(struct channel *chan); | |
72 | void channel_iterator_free(struct channel *chan); | |
73 | void channel_iterator_reset(struct channel *chan); | |
74 | void lib_ring_buffer_iterator_reset(struct lib_ring_buffer *buf); | |
75 | ||
886d51a3 | 76 | #endif /* _LIB_RING_BUFFER_ITERATOR_H */ |