"Fossies" - the Fresh Open Source Software Archive

Member "libisofs-1.5.4/libisofs/buffer.h" (8 Jul 2020, 3606 Bytes) of package /linux/misc/libisofs-1.5.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "buffer.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.5.2_vs_1.5.4.

    1 /*
    2  * Copyright (c) 2007 Vreixo Formoso
    3  * 
    4  * This file is part of the libisofs project; you can redistribute it and/or 
    5  * modify it under the terms of the GNU General Public License version 2 
    6  * or later as published by the Free Software Foundation. 
    7  * See COPYING file for details.
    8  */
    9 
   10 #ifndef LIBISO_BUFFER_H_
   11 #define LIBISO_BUFFER_H_
   12 
   13 #include <stdlib.h>
   14 
   15 #ifdef HAVE_STDINT_H
   16 #include <stdint.h>
   17 #else
   18 #ifdef HAVE_INTTYPES_H
   19 #include <inttypes.h>
   20 #endif
   21 #endif
   22 
   23 #define BLOCK_SIZE          2048
   24 
   25 typedef struct iso_ring_buffer IsoRingBuffer;
   26 
   27 /**
   28  * Create a new buffer.
   29  * 
   30  * The created buffer should be freed with iso_ring_buffer_free()
   31  * 
   32  * @param size
   33  *     Number of blocks in buffer. You should supply a number >= 32, otherwise
   34  *     size will be ignored and 32 will be used by default, which leads to a
   35  *     64 KiB buffer.
   36  * @return
   37  *     1 success, < 0 error
   38  */
   39 int iso_ring_buffer_new(size_t size, IsoRingBuffer **rbuf);
   40 
   41 /**
   42  * Free a given buffer
   43  */
   44 void iso_ring_buffer_free(IsoRingBuffer *buf);
   45 
   46 /**
   47  * Write count bytes into buffer. It blocks until all bytes where written or
   48  * reader close the buffer.
   49  * 
   50  * @param buf
   51  *      the buffer
   52  * @param data
   53  *      pointer to a memory region of at least coun bytes, from which data
   54  *      will be read.
   55  * @param
   56  *      Number of bytes to write
   57  * @return
   58  *      1 success, 0 read finished, < 0 error
   59  */
   60 int iso_ring_buffer_write(IsoRingBuffer *buf, uint8_t *data, size_t count);
   61 
   62 /**
   63  * Read count bytes from the buffer into dest. It blocks until the desired
   64  * bytes has been read. If the writer finishes before outputting enough
   65  * bytes, 0 (EOF) is returned, the number of bytes already read remains
   66  * unknown.
   67  * 
   68  * @return
   69  *      1 success, 0 EOF, < 0 error
   70  */
   71 int iso_ring_buffer_read(IsoRingBuffer *buf, uint8_t *dest, size_t count);
   72 
   73 /** Backend of API call iso_ring_buffer_get_status()
   74  *
   75  * Get the status of a ring buffer.
   76  *
   77  * @param buf
   78  *      The ring buffer object to inquire
   79  * @param size
   80  *      Will be filled with the total size of the buffer, in bytes
   81  * @param free_bytes
   82  *      Will be filled with the bytes currently available in buffer
   83  * @return
   84  *      < 0 error, > 0 state:
   85  *           1="active"    : input and consumption are active
   86  *           2="ending"    : input has ended without error
   87  *           3="failing"   : input had error and ended,
   88  *           5="abandoned" : consumption has ended prematurely
   89  *           6="ended"     : consumption has ended without input error
   90  *           7="aborted"   : consumption has ended after input error
   91  */
   92 int iso_ring_buffer_get_buf_status(IsoRingBuffer *buf, size_t *size,
   93                                    size_t *free_bytes);
   94 
   95 /** 
   96  * Close the buffer (to be called by the writer).
   97  * You have to explicitly close the buffer when you don't have more data to
   98  * write, otherwise reader will be waiting forever.
   99  * 
  100  * @param error
  101  *     Writer has finished prematurely due to an error
  102  */
  103 void iso_ring_buffer_writer_close(IsoRingBuffer *buf, int error);
  104 
  105 /** 
  106  * Close the buffer (to be called by the reader).
  107  * If for any reason you don't want to read more data, you need to call this
  108  * to let the writer thread finish.
  109  * 
  110  * @param error
  111  *     Reader has finished prematurely due to an error
  112  */
  113 void iso_ring_buffer_reader_close(IsoRingBuffer *buf, int error);
  114 
  115 /**
  116  * Get the times the buffer was full.
  117  */
  118 unsigned int iso_ring_buffer_get_times_full(IsoRingBuffer *buf);
  119 
  120 /**
  121  * Get the times the buffer was empty.
  122  */
  123 unsigned int iso_ring_buffer_get_times_empty(IsoRingBuffer *buf);
  124 
  125 #endif /*LIBISO_BUFFER_H_*/