6ed5b3b64f70230733abc227c3850b51e1aa984b
[lttng-modules.git] / lib / ringbuffer / iterator.h
1 #ifndef _LIB_RING_BUFFER_ITERATOR_H
2 #define _LIB_RING_BUFFER_ITERATOR_H
3
4 /*
5 * lib/ringbuffer/iterator.h
6 *
7 * Ring buffer and channel iterators.
8 *
9 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; only
14 * version 2.1 of the License.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 * Author:
26 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
27 */
28
29 #include <wrapper/ringbuffer/backend.h>
30 #include <wrapper/ringbuffer/frontend.h>
31 #include <wrapper/ringbuffer/vfs.h>
32
33 /*
34 * lib_ring_buffer_get_next_record advances the buffer read position to the next
35 * record. It returns either the size of the next record, -EAGAIN if there is
36 * currently no data available, or -ENODATA if no data is available and buffer
37 * is finalized.
38 */
39 extern ssize_t lib_ring_buffer_get_next_record(struct channel *chan,
40 struct lib_ring_buffer *buf);
41
42 /*
43 * channel_get_next_record advances the buffer read position to the next record.
44 * It returns either the size of the next record, -EAGAIN if there is currently
45 * no data available, or -ENODATA if no data is available and buffer is
46 * finalized.
47 * Returns the current buffer in ret_buf.
48 */
49 extern ssize_t channel_get_next_record(struct channel *chan,
50 struct lib_ring_buffer **ret_buf);
51
52 /**
53 * read_current_record - copy the buffer current record into dest.
54 * @buf: ring buffer
55 * @dest: destination where the record should be copied
56 *
57 * dest should be large enough to contain the record. Returns the number of
58 * bytes copied.
59 */
60 static inline size_t read_current_record(struct lib_ring_buffer *buf, void *dest)
61 {
62 return lib_ring_buffer_read(&buf->backend, buf->iter.read_offset,
63 dest, buf->iter.payload_len);
64 }
65
66 extern int lib_ring_buffer_iterator_open(struct lib_ring_buffer *buf);
67 extern void lib_ring_buffer_iterator_release(struct lib_ring_buffer *buf);
68 extern int channel_iterator_open(struct channel *chan);
69 extern void channel_iterator_release(struct channel *chan);
70
71 extern const struct file_operations channel_payload_file_operations;
72 extern const struct file_operations lib_ring_buffer_payload_file_operations;
73
74 /*
75 * Used internally.
76 */
77 int channel_iterator_init(struct channel *chan);
78 void channel_iterator_unregister_notifiers(struct channel *chan);
79 void channel_iterator_free(struct channel *chan);
80 void channel_iterator_reset(struct channel *chan);
81 void lib_ring_buffer_iterator_reset(struct lib_ring_buffer *buf);
82
83 #endif /* _LIB_RING_BUFFER_ITERATOR_H */
This page took 0.03329 seconds and 3 git commands to generate.