/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/
#ifndef OBEXBUFFER_H
#define OBEXBUFFER_H
#include <constants.h>
#include <utils.h>

/*
**************************************************************************
**
** Obex Buffer management
**
**************************************************************************
*/
struct iobxBuffer {
   struct iobxList      *buffers;

   struct iobxListNode  *writeNode;
   int                  writeOffset;

   struct iobxListNode  *readNode;
   int                  readOffset;
};


#ifdef __cplusplus
extern "C" {
#endif

/*
** Alloc a new buffer of specified length.
** Returns a newly allocated ObxBuffer or NULL on error.
*/
ObxBuffer *iobxBufNew( int len );

/*
** Free all internal contents and the 'buf' itself.
** Pointer 'buf' should not be used after calling this function.
*/
void iobxBufFree( ObxBuffer *buf );

/*
** Clear internal state, allows buffer to be reused.
** Returns a reset ObxBuffer or NULL on error.
*/
ObxBuffer *iobxBufReset( ObxBuffer *buf );

/*
** Appends bytes from passed 'data' to the end of the
** buffer.  (copies data from 'data' into buffer).
** Returns 0 on success, !0 on error.
*/
int iobxBufWrite( ObxBuffer *buf, void *data, int len );

/*
** Populates 'data' with 'len' bytes from the buffer.  Returns
** the actual number of bytes placed into 'data'.  This value can
** be less than 'len' if no additional bytes were available.
** Read consumes the data, Peek does not.
*/
int iobxBufRead( ObxBuffer *buf, void *data, int len );
int iobxBufPeek( ObxBuffer *buf, void *data, int len );

/*
** Amount of unread bytes in buffer.
*/
int iobxBufSize( ObxBuffer *buf );

#ifdef __cplusplus
}
#endif

#endif
