libisdn
mfifo.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   Filename:     mfifo.h
00004 
00005   Contents:     header for MFIFO
00006 
00007   License/Copyright:
00008 
00009   Copyright (c) 2007, Jan Vidar Berger, Case Labs, Ltd. All rights reserved.
00010   email:janvb@caselaboratories.com
00011 
00012   Redistribution and use in source and binary forms, with or without
00013   modification, are permitted provided that the following conditions are
00014   met:
00015 
00016     * Redistributions of source code must retain the above copyright notice,
00017           this list of conditions and the following disclaimer.
00018     * Redistributions in binary form must reproduce the above copyright notice,
00019           this list of conditions and the following disclaimer in the documentation
00020           and/or other materials provided with the distribution.
00021     * Neither the name of the Case Labs, Ltd nor the names of its contributors
00022           may be used to endorse or promote products derived from this software
00023           without specific prior written permission.
00024 
00025   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00028   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00029   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00030   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00031   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00032   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00033   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00034   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035   POSSIBILITY OF SUCH DAMAGE.
00036 *****************************************************************************/
00037 #ifndef _MFIFO
00038 #define _MFIFO
00039 
00040 /*****************************************************************************
00041 
00042   Struct:               MINDEX
00043 
00044   Description:  Message Index used to index a dynamic size Message FIFO.
00045 
00046 *****************************************************************************/
00047 typedef struct _mindex {
00048     int offset;                     /* offset to message in buf             */
00049     int size;                       /* size of message in bytes             */
00050 } MINDEX;
00051 
00052 /*****************************************************************************
00053 
00054   Struct:               MFIFO
00055 
00056   Description:  Message FIFO. Provides a dynamic sized message based FIFO
00057                                 queue.
00058 
00059 *****************************************************************************/
00060 typedef struct {
00061         int first;                      /* first out                            */
00062         int last;                       /* last in + 1                          */
00063         int bsize;                      /* buffer size                          */
00064         unsigned char *buf;             /* ptr to start of buffer               */
00065         int ixsize;                     /* index size                           */
00066         MINDEX ix[1];                   /* message index                        */
00067 } MFIFO;
00068 
00069 /*****************************************************************************
00070   Function prototypes.
00071 *****************************************************************************/
00072 int MFIFOCreate(unsigned char *buf, int size, int index);
00073 void MFIFOClear(unsigned char * buf);
00074 int MFIFOGetLBOffset(unsigned char *buf);
00075 int MFIFOGetFBOffset(unsigned char *buf);
00076 void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int off);
00077 int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size);
00078 unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size);
00079 void MFIFOKillNext(unsigned char *buf);
00080 
00081 unsigned char * MFIFOGetMesPtrOffset(unsigned char *buf, int *size, const int pos);
00082 int MFIFOGetMesCount(unsigned char *buf);
00083 int MFIFOWriteMesOverwrite(unsigned char *buf, unsigned char *mes, int size);
00084 
00085 #endif