source: lib/wandio.h @ 5e26f1d

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

Add support for lzo write compression

  • Property mode set to 100644
File size: 8.7 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        /** LZO compression */
165        WANDIO_COMPRESS_LZO     = 3,
166        /** All supported methods - used as a bitmask */
167        WANDIO_COMPRESS_MASK    = 7
168};
169
170/** @name IO open functions
171 *
172 * These functions deal with creating and initialising a new IO reader or
173 * writer.
174 *
175 * @{
176 */
177
178io_t *bz_open(io_t *parent);
179io_t *zlib_open(io_t *parent);
180io_t *thread_open(io_t *parent);
181io_t *peek_open(io_t *parent);
182io_t *stdio_open(const char *filename);
183
184iow_t *zlib_wopen(iow_t *child, int compress_level);
185iow_t *bz_wopen(iow_t *child, int compress_level);
186iow_t *lzo_wopen(iow_t *child, int compress_level);
187iow_t *thread_wopen(iow_t *child);
188iow_t *stdio_wopen(const char *filename);
189
190/* @} */
191
192/**
193 * @name Libtrace IO API functions
194 *
195 * These are the functions that should be called by the format modules to open
196 * and use files with the libtrace IO sub-system.
197 *
198 * @{ */
199
200/** Creates a new libtrace IO reader and opens the provided file for reading.
201 *
202 * @param filename      The name of the file to open
203 * @return A pointer to a new libtrace IO reader, or NULL if an error occurs
204 *
205 * This function will attempt to detect the compression format used for the
206 * given file (if any), provided that libtrace was built with the appropriate
207 * libraries.
208 */
209io_t *wandio_create(const char *filename);
210
211/** Returns the current offset of the read pointer for a libtrace IO reader.
212 *
213 * @param io            The IO reader to get the read offset for
214 * @return The offset of the read pointer, or -1 if an error occurs
215 */
216off_t wandio_tell(io_t *io);
217
218/** Changes the read pointer offset to the specified value for a libtrace IO
219 * reader.
220 *
221 * @param io            The IO reader to adjust the read pointer for
222 * @param offset        The new offset for the read pointer
223 * @param whence        Indicates where to set the read pointer from. Can be
224 *                      one of SEEK_SET, SEEK_CUR or SEEK_END.
225 * @return The new value for the read pointer, or -1 if an error occurs
226 *
227 * The arguments for this function are the same as those for lseek(2). See the
228 * lseek(2) manpage for more details.
229 */
230off_t wandio_seek(io_t *io, off_t offset, int whence);
231
232/** Reads from a libtrace IO reader into the provided buffer.
233 *
234 * @param io            The IO reader to read from
235 * @param buffer        The buffer to read into
236 * @param len           The size of the buffer
237 * @return The amount of bytes read, 0 if EOF is reached, -1 if an error occurs
238 */
239off_t wandio_read(io_t *io, void *buffer, off_t len);
240
241/** Reads from a libtrace IO reader into the provided buffer, but does not
242 * update the read pointer.
243 *
244 * @param io            The IO reader to read from
245 * @param buffer        The buffer to read into
246 * @param len           The size of the buffer
247 * @return The amount of bytes read, 0 if EOF is reached, -1 if an error occurs
248 */
249off_t wandio_peek(io_t *io, void *buffer, off_t len);
250
251/** Destroys a libtrace IO reader, closing the file and freeing the reader
252 * structure.
253 *
254 * @param io            The IO reader to destroy
255 */
256void wandio_destroy(io_t *io);
257
258/** Creates a new libtrace IO writer and opens the provided file for writing.
259 *
260 * @param filename              The name of the file to open
261 * @param compression_level     The compression level to use when writing
262 * @param flags                 Flags to apply when opening the file, e.g.
263 *                              O_CREATE
264 * @return A pointer to the new libtrace IO writer, or NULL if an error occurs
265 */
266iow_t *wandio_wcreate(const char *filename, int compression_level, int flags);
267
268/** Writes the contents of a buffer using a libtrace IO writer.
269 *
270 * @param iow           The IO writer to write the data with
271 * @param buffer        The buffer to write out
272 * @param len           The amount of writable data in the buffer
273 * @return The amount of data written, or -1 if an error occurs
274 */
275off_t wandio_wwrite(iow_t *iow, const void *buffer, off_t len);
276
277/** Destroys a libtrace IO writer, closing the file and freeing the writer
278 * structure.
279 *
280 * @param iow           The IO writer to destroy
281 */
282void wandio_wdestroy(iow_t *iow);
283
284/** @} */
285
286/** @name libtraceio options
287 * @{ */
288extern int force_directio_read;
289extern int force_directio_write;
290extern uint64_t write_waits;
291extern uint64_t read_waits;
292/* @} */
293
294#endif
Note: See TracBrowser for help on using the repository browser.