Go to the documentation of this file.00001 #ifndef GORP_PERCI_H
00002 #define GORP_PERCI_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
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
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
00134 #endif