Nut/OS  4.10.3
API Reference
perci.h
Go to the documentation of this file.
00001 #ifndef GORP_PERCI_H
00002 #define GORP_PERCI_H
00003 
00004 /*
00005  * Copyright 2010 by egnite GmbH
00006  *
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  * 3. Neither the name of the copyright holders nor the names of
00019  *    contributors may be used to endorse or promote products derived
00020  *    from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00029  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00030  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00032  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  *
00035  * For additional information see http://www.ethernut.de/
00036  */
00037 
00038 /*
00039  * \file include/gorp/perci.h
00040  * \brief Persistent circular buffer definitions.
00041  *
00042  * \verbatim
00043  * $Id$
00044  * \endverbatim
00045  */
00046 
00047 #include <cfg/perci.h>
00048 
00049 #include <stdlib.h>
00050 #include <stdio.h>
00051 #include <stdarg.h>
00052 
00057 
00058 #ifndef PERCI_MAX_RECORDS
00059 #define PERCI_MAX_RECORDS   256
00060 #endif
00061 
00062 #if PERCI_MAX_RECORDS <= 256
00063 typedef uint8_t perci_recnum_t;
00064 typedef uint_fast8_t perci_fast_recnum_t;
00065 #elif PERCI_MAX_RECORDS <= 65536
00066 typedef uint16_t perci_recnum_t;
00067 typedef uint_fast16_t perci_fast_recnum_t;
00068 #else
00069 typedef uint32_t perci_recnum_t;
00070 typedef uint_fast32_t perci_fast_recnum_t;
00071 #endif
00072 
00073 
00074 #ifndef PERCI_RECSIZE
00075 #define PERCI_RECSIZE       256
00076 #endif
00077 
00078 #if PERCI_RECSIZE <= 256
00079 typedef uint8_t perci_reclen_t;
00080 typedef uint_fast8_t perci_fast_reclen_t;
00081 #elif PERCI_RECSIZE <= 65536
00082 typedef uint16_t perci_reclen_t;
00083 typedef uint_fast16_t perci_fast_reclen_t;
00084 #else
00085 typedef uint32_t perci_reclen_t;
00086 typedef uint_fast32_t perci_fast_reclen_t;
00087 #endif
00088 
00089 #define PERCI_DATASIZE  (PERCI_RECSIZE - sizeof(perci_reclen_t))
00090 
00091 typedef struct __attribute__ ((packed)) _PERCI_RECORD {
00092     perci_reclen_t pcd_len;
00093     uint8_t pcd_data[PERCI_RECSIZE];
00094 } PERCI_RECORD;
00095 
00096 typedef struct _PERCI_WRITER {
00097     int pcw_fd;
00098     long pcw_size;
00099     HANDLE pcw_mutex;
00100     perci_fast_recnum_t pcw_recnum;
00101     PERCI_RECORD pcw_rec;
00102 } PERCI_WRITER;
00103 
00104 typedef struct _PERCI_READER {
00105     PERCI_WRITER *pcr_cil;
00106     perci_fast_recnum_t pcr_recnum;
00107     perci_fast_reclen_t pcr_reclen;
00108     perci_fast_reclen_t pcr_recpos;
00109 } PERCI_READER;
00110 
00111 __BEGIN_DECLS
00112 /* Prototypes */
00113 
00114 extern int PerCiInit(char *path, int recs);
00115 
00116 extern PERCI_WRITER *PerCiOpen(char *path);
00117 extern void PerCiClose(PERCI_WRITER *writer);
00118 extern void PerCiFlush(PERCI_WRITER * writer);
00119 
00120 extern int PerCiWrite(PERCI_WRITER *writer, CONST char *data, int len);
00121 extern int PerCiWriteFormat(PERCI_WRITER * writer, CONST char *fmt, ...);
00122 extern int PerCiWriteVarList(PERCI_WRITER * writer, CONST char *fmt, va_list ap);
00123 
00124 extern PERCI_READER *PerCiAttachReader(PERCI_WRITER *writer);
00125 extern void PerCiDetachReader(PERCI_READER *reader);
00126 
00127 extern int PerCiRead(PERCI_READER *reader, char *data, int len);
00128 extern int PerCiReadLine(PERCI_READER * reader, char *line, int len);
00129 
00130 extern void PerCiDump(FILE *stream, char *path);
00131 
00132 __END_DECLS
00133 /* End of prototypes */
00134 #endif