source: lib/wandio.h @ 29d4438

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 29d4438 was 29d4438, checked in by Perry Lorier <perry@…>, 12 years ago

Support an "undocumented" libtraceio debug interface

  • Property mode set to 100644
File size: 8.6 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton,
5 * New Zealand.
6 *
7 * Authors: Daniel Lawson
8 *          Perry Lorier
9 *          Shane Alcock
10 *         
11 * All rights reserved.
12 *
13 * This code has been developed by the University of Waikato WAND
14 * research group. For further information please see http://www.wand.net.nz/
15 *
16 * libtrace is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * libtrace is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with libtrace; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29 *
30 * $Id$
31 *
32 */
33
34#ifndef IO_H
35#define IO_H 1
36#include <sys/types.h>
37#include <stdio.h>
38#include <inttypes.h>
39
40/** @file
41 *
42 * @brief Header file dealing with the Libtrace IO sub-system
43 *
44 * @author Perry Lorier
45 * @author Shane Alcock
46 *
47 * @version $Id$
48 */
49
50typedef struct io_t io_t;
51typedef struct iow_t iow_t;
52
53/** Structure defining a supported compression method */
54struct compression_type {
55        /** Name of the compression method */
56        const char *name;
57        /** Extension to add to the filename of files written using this
58         *  method */
59        const char *ext;
60        /** Internal type identifying the compression method */
61        int compress_flag;
62};
63
64/** The list of supported compression methods */
65extern struct compression_type compression_type[];
66
67/** Structure defining a libtrace IO reader module */
68typedef struct {
69        /** Module name */
70        const char *name;
71
72        /** Reads from the IO source into the provided buffer.
73         *
74         * @param io            The IO reader
75         * @param buffer        The buffer to read into
76         * @param len           The amount of space available in the buffer
77         * @return The amount of bytes read, 0 if end of file is reached, -1
78         * if an error occurs
79         */
80        off_t (*read)(io_t *io, void *buffer, off_t len);
81
82        /** Reads from the IO source into the provided buffer but does not
83         *  advance the read pointer.
84         *
85         * @param io            The IO reader
86         * @param buffer        The buffer to read into
87         * @param len           The amount of space available in the buffer
88         * @return The amount of bytes read, 0 if end of file is reached, -1
89         * if an error occurs
90         */
91        off_t (*peek)(io_t *io, void *buffer, off_t len);
92
93        /** Returns the current offset of the read pointer for an IO source.
94         *
95         * @param io            The IO reader to get the read offset for
96         * @return The offset of the read pointer, or -1 if an error occurs
97         */
98        off_t (*tell)(io_t *io);
99       
100        /** Moves the read pointer for an IO source.
101         *
102         * @param io            The IO reader to move the read pointer for
103         * @param offset        The new read pointer offset
104         * @param whence        Where to start counting the new offset from.
105         *                      whence can be one of three values: SEEK_SET,
106         *                      SEEK_CUR and SEEK_END. See the lseek(2) manpage
107         *                      for more details as to what these mean.
108         * @return The value of the new read pointer, or -1 if an error occurs
109         */
110        off_t (*seek)(io_t *io, off_t offset, int whence);
111       
112        /** Closes an IO reader. This function should free the IO reader.
113         *
114         * @param io            The IO reader to close
115         */
116        void (*close)(io_t *io);
117} io_source_t;
118
119/** Structure defining a libtrace IO writer module */
120typedef struct {
121        /** The name of the module */
122        const char *name;
123       
124        /** Writes the contents of a buffer using an IO writer.
125         *
126         * @param iow           The IO writer to write the data with
127         * @param buffer        The buffer to be written
128         * @param len           The amount of writable data in the buffer
129         * @return The amount of data written, or -1 if an error occurs
130         */
131        off_t (*write)(iow_t *iow, const char *buffer, off_t len);
132
133        /** Closes an IO writer. This function should free the IO writer.
134         *
135         * @param iow           The IO writer to close
136         */
137        void (*close)(iow_t *iow);
138} iow_source_t;
139
140/** A libtrace IO reader */
141struct io_t {
142        /** The IO module that is used by the reader */
143        io_source_t *source;
144        /** Generic pointer to data required by the IO module */
145        void *data;
146};
147
148/** A libtrace IO writer */
149struct iow_t {
150        /** The IO module that is used by the writer */
151        iow_source_t *source;
152        /** Generic pointer to data required by the IO module */
153        void *data;
154};
155
156/** Enumeration of all supported compression methods */
157enum {
158        /** No compression */
159        WANDIO_COMPRESS_NONE    = 0,
160        /** Zlib compression */
161        WANDIO_COMPRESS_ZLIB    = 1,
162        /** Bzip compression */
163        WANDIO_COMPRESS_BZ2     = 2,
164        /** All supported methods - used as a bitmask */
165        WANDIO_COMPRESS_MASK    = 7
166};
167
168/** @name IO open functions
169 *
170 * These functions deal with creating and initialising a new IO reader or
171 * writer.
172 *
173 * @{
174 */
175
176io_t *bz_open(io_t *parent);
177io_t *zlib_open(io_t *parent);
178io_t *thread_open(io_t *parent);
179io_t *peek_open(io_t *parent);
180io_t *stdio_open(const char *filename);
181
182iow_t *zlib_wopen(iow_t *child, int compress_level);
183iow_t *bz_wopen(iow_t *child, int compress_level);
184iow_t *thread_wopen(iow_t *child);
185iow_t *stdio_wopen(const char *filename);
186
187/* @} */
188
189/**
190 * @name Libtrace IO API functions
191 *
192 * These are the functions that should be called by the format modules to open
193 * and use files with the libtrace IO sub-system.
194 *
195 * @{ */
196
197/** Creates a new libtrace IO reader and opens the provided file for reading.
198 *
199 * @param filename      The name of the file to open
200 * @return A pointer to a new libtrace IO reader, or NULL if an error occurs
201 *
202 * This function will attempt to detect the compression format used for the
203 * given file (if any), provided that libtrace was built with the appropriate
204 * libraries.
205 */
206io_t *wandio_create(const char *filename);
207
208/** Returns the current offset of the read pointer for a libtrace IO reader.
209 *
210 * @param io            The IO reader to get the read offset for
211 * @return The offset of the read pointer, or -1 if an error occurs
212 */
213off_t wandio_tell(io_t *io);
214
215/** Changes the read pointer offset to the specified value for a libtrace IO
216 * reader.
217 *
218 * @param io            The IO reader to adjust the read pointer for
219 * @param offset        The new offset for the read pointer
220 * @param whence        Indicates where to set the read pointer from. Can be
221 *                      one of SEEK_SET, SEEK_CUR or SEEK_END.
222 * @return The new value for the read pointer, or -1 if an error occurs
223 *
224 * The arguments for this function are the same as those for lseek(2). See the
225 * lseek(2) manpage for more details.
226 */
227off_t wandio_seek(io_t *io, off_t offset, int whence);
228
229/** Reads from a libtrace IO reader into the provided buffer.
230 *
231 * @param io            The IO reader to read from
232 * @param buffer        The buffer to read into
233 * @param len           The size of the buffer
234 * @return The amount of bytes read, 0 if EOF is reached, -1 if an error occurs
235 */
236off_t wandio_read(io_t *io, void *buffer, off_t len);
237
238/** Reads from a libtrace IO reader into the provided buffer, but does not
239 * update the read pointer.
240 *
241 * @param io            The IO reader to read from
242 * @param buffer        The buffer to read into
243 * @param len           The size of the buffer
244 * @return The amount of bytes read, 0 if EOF is reached, -1 if an error occurs
245 */
246off_t wandio_peek(io_t *io, void *buffer, off_t len);
247
248/** Destroys a libtrace IO reader, closing the file and freeing the reader
249 * structure.
250 *
251 * @param io            The IO reader to destroy
252 */
253void wandio_destroy(io_t *io);
254
255/** Creates a new libtrace IO writer and opens the provided file for writing.
256 *
257 * @param filename              The name of the file to open
258 * @param compression_level     The compression level to use when writing
259 * @param flags                 Flags to apply when opening the file, e.g.
260 *                              O_CREATE
261 * @return A pointer to the new libtrace IO writer, or NULL if an error occurs
262 */
263iow_t *wandio_wcreate(const char *filename, int compression_level, int flags);
264
265/** Writes the contents of a buffer using a libtrace IO writer.
266 *
267 * @param iow           The IO writer to write the data with
268 * @param buffer        The buffer to write out
269 * @param len           The amount of writable data in the buffer
270 * @return The amount of data written, or -1 if an error occurs
271 */
272off_t wandio_wwrite(iow_t *iow, const void *buffer, off_t len);
273
274/** Destroys a libtrace IO writer, closing the file and freeing the writer
275 * structure.
276 *
277 * @param iow           The IO writer to destroy
278 */
279void wandio_wdestroy(iow_t *iow);
280
281/** @} */
282
283/** @name libtraceio options
284 * @{ */
285extern int force_directio_read;
286extern int force_directio_write;
287extern uint64_t write_waits;
288extern uint64_t read_waits;
289/* @} */
290
291#endif
Note: See TracBrowser for help on using the repository browser.