source: libwandio/wandio.h @ c7021d9

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

Added m4 macros to check for gcc compiler attributes

Instead of relying on GNUC, we now individually check
whether each attribute is supported by the C compiler and set
preprocessor macros accordingly.

Removed similar attribute definitions from wandio.h, as these are
not used at all by libwandio.

  • Property mode set to 100644
File size: 9.8 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 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 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        /** All supported methods - used as a bitmask */
181        WANDIO_COMPRESS_MASK    = 7
182};
183
184/** @name IO open functions
185 *
186 * These functions deal with creating and initialising a new IO reader or
187 * writer.
188 *
189 * @{
190 */
191
192io_t *bz_open(io_t *parent);
193io_t *zlib_open(io_t *parent);
194io_t *thread_open(io_t *parent);
195io_t *peek_open(io_t *parent);
196io_t *stdio_open(const char *filename);
197
198iow_t *zlib_wopen(iow_t *child, int compress_level);
199iow_t *bz_wopen(iow_t *child, int compress_level);
200iow_t *lzo_wopen(iow_t *child, int compress_level);
201iow_t *thread_wopen(iow_t *child);
202iow_t *stdio_wopen(const char *filename, int fileflags);
203
204/* @} */
205
206/**
207 * @name Libtrace IO API functions
208 *
209 * These are the functions that should be called by the format modules to open
210 * and use files with the libtrace IO sub-system.
211 *
212 * @{ */
213
214/** Creates a new libtrace IO reader and opens the provided file for reading.
215 *
216 * @param filename      The name of the file to open
217 * @return A pointer to a new libtrace IO reader, or NULL if an error occurs
218 *
219 * The compression format will be determined automatically by peeking at the
220 * first few bytes of the file and comparing them against known compression
221 * file header formats. If no formats match, the file will be assumed to be
222 * uncompressed.
223 */
224io_t *wandio_create(const char *filename);
225
226/** Creates a new libtrace IO reader and opens the provided file for reading.
227 *
228 * @param filename      The name of the file to open
229 * @return A pointer to a new libtrace IO reader, or NULL if an error occurs
230 *
231 * Unlike wandio_create, this function will always assume the file is
232 * uncompressed and therefore not run the compression autodetection algorithm.
233 *
234 * Use this function if you are only working with uncompressed files and are
235 * running into problems with the start of your files resembling compression
236 * format headers. Otherwise, you should really be using wandio_create.
237 */
238io_t *wandio_create_uncompressed(const char *filename);
239
240/** Returns the current offset of the read pointer for a libtrace IO reader.
241 *
242 * @param io            The IO reader to get the read offset for
243 * @return The offset of the read pointer, or -1 if an error occurs
244 */
245off_t wandio_tell(io_t *io);
246
247/** Changes the read pointer offset to the specified value for a libtrace IO
248 * reader.
249 *
250 * @param io            The IO reader to adjust the read pointer for
251 * @param offset        The new offset for the read pointer
252 * @param whence        Indicates where to set the read pointer from. Can be
253 *                      one of SEEK_SET, SEEK_CUR or SEEK_END.
254 * @return The new value for the read pointer, or -1 if an error occurs
255 *
256 * The arguments for this function are the same as those for lseek(2). See the
257 * lseek(2) manpage for more details.
258 */
259off_t wandio_seek(io_t *io, off_t offset, int whence);
260
261/** Reads from a libtrace IO reader into the provided buffer.
262 *
263 * @param io            The IO reader to read from
264 * @param buffer        The buffer to read into
265 * @param len           The size of the buffer
266 * @return The amount of bytes read, 0 if EOF is reached, -1 if an error occurs
267 */
268off_t wandio_read(io_t *io, void *buffer, off_t len);
269
270/** Reads from a libtrace IO reader into the provided buffer, but does not
271 * update the read pointer.
272 *
273 * @param io            The IO reader to read from
274 * @param buffer        The buffer to read into
275 * @param len           The size of the buffer
276 * @return The amount of bytes read, 0 if EOF is reached, -1 if an error occurs
277 */
278off_t wandio_peek(io_t *io, void *buffer, off_t len);
279
280/** Destroys a libtrace IO reader, closing the file and freeing the reader
281 * structure.
282 *
283 * @param io            The IO reader to destroy
284 */
285void wandio_destroy(io_t *io);
286
287/** Creates a new libtrace IO writer and opens the provided file for writing.
288 *
289 * @param filename              The name of the file to open
290 * @param compression_type      Compression type
291 * @param compression_level     The compression level to use when writing
292 * @param flags                 Flags to apply when opening the file, e.g.
293 *                              O_CREATE
294 * @return A pointer to the new libtrace IO writer, or NULL if an error occurs
295 */
296iow_t *wandio_wcreate(const char *filename, int compression_type, int compression_level, int flags);
297
298/** Writes the contents of a buffer using a libtrace IO writer.
299 *
300 * @param iow           The IO writer to write the data with
301 * @param buffer        The buffer to write out
302 * @param len           The amount of writable data in the buffer
303 * @return The amount of data written, or -1 if an error occurs
304 */
305off_t wandio_wwrite(iow_t *iow, const void *buffer, off_t len);
306
307/** Destroys a libtrace IO writer, closing the file and freeing the writer
308 * structure.
309 *
310 * @param iow           The IO writer to destroy
311 */
312void wandio_wdestroy(iow_t *iow);
313
314/** @} */
315
316#endif
Note: See TracBrowser for help on using the repository browser.