Commit | Line | Data |
---|---|---|
f3bc08c5 MD |
1 | #ifndef _LINUX_RING_BUFFER_ITERATOR_H |
2 | #define _LINUX_RING_BUFFER_ITERATOR_H | |
3 | ||
4 | /* | |
5 | * linux/ringbuffer/iterator.h | |
6 | * | |
7 | * (C) Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * | |
9 | * Ring buffer and channel iterators. | |
10 | * | |
11 | * Author: | |
12 | * Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
13 | * | |
14 | * Dual LGPL v2.1/GPL v2 license. | |
15 | */ | |
16 | ||
17 | #include "../../wrapper/ringbuffer/backend.h" | |
18 | #include "../../wrapper/ringbuffer/frontend.h" | |
19 | ||
20 | /* | |
21 | * lib_ring_buffer_get_next_record advances the buffer read position to the next | |
22 | * record. It returns either the size of the next record, -EAGAIN if there is | |
23 | * currently no data available, or -ENODATA if no data is available and buffer | |
24 | * is finalized. | |
25 | */ | |
26 | extern ssize_t lib_ring_buffer_get_next_record(struct channel *chan, | |
27 | struct lib_ring_buffer *buf); | |
28 | ||
29 | /* | |
30 | * channel_get_next_record advances the buffer read position to the next record. | |
31 | * It returns either the size of the next record, -EAGAIN if there is currently | |
32 | * no data available, or -ENODATA if no data is available and buffer is | |
33 | * finalized. | |
34 | * Returns the current buffer in ret_buf. | |
35 | */ | |
36 | extern ssize_t channel_get_next_record(struct channel *chan, | |
37 | struct lib_ring_buffer **ret_buf); | |
38 | ||
39 | /** | |
40 | * read_current_record - copy the buffer current record into dest. | |
41 | * @buf: ring buffer | |
42 | * @dest: destination where the record should be copied | |
43 | * | |
44 | * dest should be large enough to contain the record. Returns the number of | |
45 | * bytes copied. | |
46 | */ | |
47 | static inline size_t read_current_record(struct lib_ring_buffer *buf, void *dest) | |
48 | { | |
49 | return lib_ring_buffer_read(&buf->backend, buf->iter.read_offset, | |
50 | dest, buf->iter.payload_len); | |
51 | } | |
52 | ||
53 | extern int lib_ring_buffer_iterator_open(struct lib_ring_buffer *buf); | |
54 | extern void lib_ring_buffer_iterator_release(struct lib_ring_buffer *buf); | |
55 | extern int channel_iterator_open(struct channel *chan); | |
56 | extern void channel_iterator_release(struct channel *chan); | |
57 | ||
58 | extern const struct file_operations channel_payload_file_operations; | |
59 | extern const struct file_operations lib_ring_buffer_payload_file_operations; | |
60 | ||
61 | /* | |
62 | * Used internally. | |
63 | */ | |
64 | int channel_iterator_init(struct channel *chan); | |
65 | void channel_iterator_unregister_notifiers(struct channel *chan); | |
66 | void channel_iterator_free(struct channel *chan); | |
67 | void channel_iterator_reset(struct channel *chan); | |
68 | void lib_ring_buffer_iterator_reset(struct lib_ring_buffer *buf); | |
69 | ||
70 | #endif /* _LINUX_RING_BUFFER_ITERATOR_H */ |