1 /***************************************************************************** 2 3 Filename: mfifo.h 4 5 Contents: header for MFIFO 6 7 License/Copyright: 8 9 Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved. 10 email:janvb@caselaboratories.com 11 12 Redistribution and use in source and binary forms, with or without 13 modification, are permitted provided that the following conditions are 14 met: 15 16 * Redistributions of source code must retain the above copyright notice, 17 this list of conditions and the following disclaimer. 18 * Redistributions in binary form must reproduce the above copyright notice, 19 this list of conditions and the following disclaimer in the documentation 20 and/or other materials provided with the distribution. 21 * Neither the name of the Case Labs, Ltd nor the names of its contributors 22 may be used to endorse or promote products derived from this software 23 without specific prior written permission. 24 25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 29 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 POSSIBILITY OF SUCH DAMAGE. 36 *****************************************************************************/ 37 #ifndef _MFIFO 38 #define _MFIFO 39 40 /***************************************************************************** 41 42 Struct: MINDEX 43 44 Description: Message Index used to index a dynamic size Message FIFO. 45 46 *****************************************************************************/ 47 typedef struct _mindex { 48 int offset; /* offset to message in buf */ 49 int size; /* size of message in bytes */ 50 } MINDEX; 51 52 /***************************************************************************** 53 54 Struct: MFIFO 55 56 Description: Message FIFO. Provides a dynamic sized message based FIFO 57 queue. 58 59 *****************************************************************************/ 60 typedef struct { 61 int first; /* first out */ 62 int last; /* last in + 1 */ 63 int bsize; /* buffer size */ 64 unsigned char *buf; /* ptr to start of buffer */ 65 int ixsize; /* index size */ 66 MINDEX ix[1]; /* message index */ 67 } MFIFO; 68 69 /***************************************************************************** 70 Function prototypes. 71 *****************************************************************************/ 72 int MFIFOCreate(unsigned char *buf, int size, int index); 73 void MFIFOClear(unsigned char * buf); 74 int MFIFOGetLBOffset(unsigned char *buf); 75 int MFIFOGetFBOffset(unsigned char *buf); 76 void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int off); 77 int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size); 78 unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size); 79 void MFIFOKillNext(unsigned char *buf); 80 81 unsigned char * MFIFOGetMesPtrOffset(unsigned char *buf, int *size, const int pos); 82 int MFIFOGetMesCount(unsigned char *buf); 83 int MFIFOWriteMesOverwrite(unsigned char *buf, unsigned char *mes, int size); 84 85 #endif 86