source: libwandio/wandio.h @ 4b0cd2f

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivelibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 4b0cd2f was 4b0cd2f, checked in by Shane Alcock <salcock@…>, 6 years ago

Integrate lzma into libwandio properly

Update configure to detect lzma properly.
Add missing get_compression_type API function to wandio code.
Add code to detect if input file is LZMA.

  • Property mode set to 100644
File size: 10.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 /**< Guard Define */
36#include <sys/types.h>
37#include <stdio.h>
38#include <inttypes.h>
39#include <stdbool.h>
40
41
42#ifndef DLLEXPORT
43        #if HAVE_VISIBILITY && LT_BUILDING_DLL
44                #define DLLEXPORT __attribute__ ((visibility("default")))
45                #define DLLLOCAL __attribute__ ((visibility("hidden")))
46        #else
47                #define DLLEXPORT
48                #define DLLLOCAL
49        #endif
50#endif
51
52// TODO: Use a proper check for these attribute rather than gcc version check
53
54/** @file
55 *
56 * @brief Header file dealing with the Libtrace IO sub-system
57 *
58 * @author Perry Lorier
59 * @author Shane Alcock
60 *
61 * @version $Id$
62 */
63
64typedef struct io_t io_t; /**< Opaque IO handle structure for reading */
65typedef struct iow_t iow_t; /**< Opaque IO handle structure for writing */
66
67/** Structure defining a supported compression method */
68struct wandio_compression_type {
69        /** Name of the compression method */
70        const char *name;
71        /** Extension to add to the filename of files written using this
72         *  method */
73        const char *ext;
74        /** Internal type identifying the compression method */
75        int compress_type;
76};
77
78/** The list of supported compression methods */
79extern struct wandio_compression_type compression_type[];
80
81/** Structure defining a libtrace IO reader module */
82typedef struct {
83        /** Module name */
84        const char *name;
85
86        /** Reads from the IO source into the provided buffer.
87         *
88         * @param io            The IO reader
89         * @param buffer        The buffer to read into
90         * @param len           The amount of space available in the buffer
91         * @return The amount of bytes read, 0 if end of file is reached, -1
92         * if an error occurs
93         */
94        off_t (*read)(io_t *io, void *buffer, off_t len);
95
96        /** Reads from the IO source into the provided buffer but does not
97         *  advance the read pointer.
98         *
99         * @param io            The IO reader
100         * @param buffer        The buffer to read into
101         * @param len           The amount of space available in the buffer
102         * @return The amount of bytes read, 0 if end of file is reached, -1
103         * if an error occurs
104         */
105        off_t (*peek)(io_t *io, void *buffer, off_t len);
106
107        /** Returns the current offset of the read pointer for an IO source.
108         *
109         * @param io            The IO reader to get the read offset for
110         * @return The offset of the read pointer, or -1 if an error occurs
111         */
112        off_t (*tell)(io_t *io);
113       
114        /** Moves the read pointer for an IO source.
115         *
116         * @param io            The IO reader to move the read pointer for
117         * @param offset        The new read pointer offset
118         * @param whence        Where to start counting the new offset from.
119         *                      whence can be one of three values: SEEK_SET,
120         *                      SEEK_CUR and SEEK_END. See the lseek(2) manpage
121         *                      for more details as to what these mean.
122         * @return The value of the new read pointer, or -1 if an error occurs
123         */
124        off_t (*seek)(io_t *io, off_t offset, int whence);
125       
126        /** Closes an IO reader. This function should free the IO reader.
127         *
128         * @param io            The IO reader to close
129         */
130        void (*close)(io_t *io);
131} io_source_t;
132
133/** Structure defining a libtrace IO writer module */
134typedef struct {
135        /** The name of the module */
136        const char *name;
137       
138        /** Writes the contents of a buffer using an IO writer.
139         *
140         * @param iow           The IO writer to write the data with
141         * @param buffer        The buffer to be written
142         * @param len           The amount of writable data in the buffer
143         * @return The amount of data written, or -1 if an error occurs
144         */
145        off_t (*write)(iow_t *iow, const char *buffer, off_t len);
146
147        /** Closes an IO writer. This function should free the IO writer.
148         *
149         * @param iow           The IO writer to close
150         */
151        void (*close)(iow_t *iow);
152} iow_source_t;
153
154/** A libtrace IO reader */
155struct io_t {
156        /** The IO module that is used by the reader */
157        io_source_t *source;
158        /** Generic pointer to data required by the IO module */
159        void *data;
160};
161
162/** A libtrace IO writer */
163struct iow_t {
164        /** The IO module that is used by the writer */
165        iow_source_t *source;
166        /** Generic pointer to data required by the IO module */
167        void *data;
168};
169
170/** Enumeration of all supported compression methods */
171enum {
172        /** No compression */
173        WANDIO_COMPRESS_NONE    = 0,
174        /** Zlib compression */
175        WANDIO_COMPRESS_ZLIB    = 1,
176        /** Bzip compression */
177        WANDIO_COMPRESS_BZ2     = 2,
178        /** LZO compression */
179        WANDIO_COMPRESS_LZO     = 3,
180        /** LZMA compression */
181        WANDIO_COMPRESS_LZMA    = 4,
182        /** All supported methods - used as a bitmask */
183        WANDIO_COMPRESS_MASK    = 7
184};
185
186/** @name IO open functions
187 *
188 * These functions deal with creating and initialising a new IO reader or
189 * writer.
190 *
191 * @{
192 */
193
194io_t *bz_open(io_t *parent);
195io_t *zlib_open(io_t *parent);
196io_t *thread_open(io_t *parent);
197io_t *lzma_open(io_t *parent);
198io_t *peek_open(io_t *parent);
199io_t *stdio_open(const char *filename);
200
201iow_t *zlib_wopen(iow_t *child, int compress_level);
202iow_t *bz_wopen(iow_t *child, int compress_level);
203iow_t *lzo_wopen(iow_t *child, int compress_level);
204iow_t *lzma_wopen(iow_t *child, int compress_level);
205iow_t *thread_wopen(iow_t *child);
206iow_t *stdio_wopen(const char *filename, int fileflags);
207
208/* @} */
209
210/**
211 * @name Libtrace IO API functions
212 *
213 * These are the functions that should be called by the format modules to open
214 * and use files with the libtrace IO sub-system.
215 *
216 * @{ */
217
218/** Given a string describing the compression method, finds the internal
219  * data structure representing that method. This is mostly useful for
220  * nicely mapping a method name to the internal libwandio compression
221  * method enum when configuring an output file.
222  *
223  * @param name          The compression method name as a string, e.g. "gzip",
224  *                      "bzip2", "lzo" or "lzma".
225  * @return A pointer to the compression_type structure representing the
226  * compression method or NULL if no match can be found.
227  *
228  */
229struct wandio_compression_type *wandio_lookup_compression_type(const char *name);
230
231/** Creates a new libtrace IO reader and opens the provided file for reading.
232 *
233 * @param filename      The name of the file to open
234 * @return A pointer to a new libtrace IO reader, or NULL if an error occurs
235 *
236 * The compression format will be determined automatically by peeking at the
237 * first few bytes of the file and comparing them against known compression
238 * file header formats. If no formats match, the file will be assumed to be
239 * uncompressed.
240 */
241io_t *wandio_create(const char *filename);
242
243/** Creates a new libtrace IO reader and opens the provided file for reading.
244 *
245 * @param filename      The name of the file to open
246 * @return A pointer to a new libtrace IO reader, or NULL if an error occurs
247 *
248 * Unlike wandio_create, this function will always assume the file is
249 * uncompressed and therefore not run the compression autodetection algorithm.
250 *
251 * Use this function if you are only working with uncompressed files and are
252 * running into problems with the start of your files resembling compression
253 * format headers. Otherwise, you should really be using wandio_create.
254 */
255io_t *wandio_create_uncompressed(const char *filename);
256
257/** Returns the current offset of the read pointer for a libtrace IO reader.
258 *
259 * @param io            The IO reader to get the read offset for
260 * @return The offset of the read pointer, or -1 if an error occurs
261 */
262off_t wandio_tell(io_t *io);
263
264/** Changes the read pointer offset to the specified value for a libtrace IO
265 * reader.
266 *
267 * @param io            The IO reader to adjust the read pointer for
268 * @param offset        The new offset for the read pointer
269 * @param whence        Indicates where to set the read pointer from. Can be
270 *                      one of SEEK_SET, SEEK_CUR or SEEK_END.
271 * @return The new value for the read pointer, or -1 if an error occurs
272 *
273 * The arguments for this function are the same as those for lseek(2). See the
274 * lseek(2) manpage for more details.
275 */
276off_t wandio_seek(io_t *io, off_t offset, int whence);
277
278/** Reads from a libtrace IO reader into the provided buffer.
279 *
280 * @param io            The IO reader to read from
281 * @param buffer        The buffer to read into
282 * @param len           The size of the buffer
283 * @return The amount of bytes read, 0 if EOF is reached, -1 if an error occurs
284 */
285off_t wandio_read(io_t *io, void *buffer, off_t len);
286
287/** Reads from a libtrace IO reader into the provided buffer, but does not
288 * update the read pointer.
289 *
290 * @param io            The IO reader to read from
291 * @param buffer        The buffer to read into
292 * @param len           The size of the buffer
293 * @return The amount of bytes read, 0 if EOF is reached, -1 if an error occurs
294 */
295off_t wandio_peek(io_t *io, void *buffer, off_t len);
296
297/** Destroys a libtrace IO reader, closing the file and freeing the reader
298 * structure.
299 *
300 * @param io            The IO reader to destroy
301 */
302void wandio_destroy(io_t *io);
303
304/** Creates a new libtrace IO writer and opens the provided file for writing.
305 *
306 * @param filename              The name of the file to open
307 * @param compression_type      Compression type
308 * @param compression_level     The compression level to use when writing
309 * @param flags                 Flags to apply when opening the file, e.g.
310 *                              O_CREATE
311 * @return A pointer to the new libtrace IO writer, or NULL if an error occurs
312 */
313iow_t *wandio_wcreate(const char *filename, int compression_type, int compression_level, int flags);
314
315/** Writes the contents of a buffer using a libtrace IO writer.
316 *
317 * @param iow           The IO writer to write the data with
318 * @param buffer        The buffer to write out
319 * @param len           The amount of writable data in the buffer
320 * @return The amount of data written, or -1 if an error occurs
321 */
322off_t wandio_wwrite(iow_t *iow, const void *buffer, off_t len);
323
324/** Destroys a libtrace IO writer, closing the file and freeing the writer
325 * structure.
326 *
327 * @param iow           The IO writer to destroy
328 */
329void wandio_wdestroy(iow_t *iow);
330
331/** @} */
332
333#endif
Note: See TracBrowser for help on using the repository browser.