/*
 * ringbuffer.h
 *
 *  Created on: Jul 24, 2012
 *      Author: tkl
 */

#ifndef RINGBUFFER_H_
#define RINGBUFFER_H_

//-----------------------------------------------------------------------------
//! \brief A ring buffer object.
struct ringbuffer {
	char *buffer;	//!< The buffer.
	char *read;		//!< Read access.
	char *write;	//!< Write access.
	int size;		//!< Buffer size.
	int used;		//!< Buffer in use.
};

//-----------------------------------------------------------------------------
//! \brief Read out n characters from ring buffer.
//! \param this The ring buffer to read from.
//! \param buffer to read to.
//! \param size The maximum number of characters to read.
//! \retval -1 in error case, otherwise the number of read characters.
int ringbuffer_read(struct ringbuffer *this, char *buffer, int size);

//-----------------------------------------------------------------------------
//! \brief Write n characters to ring buffer.
//! \param this The ring buffer to write to.
//! \param buffer to write.
//! \param size The number of characters to write.
//! \retval -1 in error case, otherwise the number of written characters.
int ringbuffer_write(struct ringbuffer *this, const char *buffer, int size);

//-----------------------------------------------------------------------------
//! \brief Check if ring buffer is full.
//! \param this The ring buffer to check.
//! \retval -1 in error case, otherwise 1 (true) / 0 (false).
int ringbuffer_is_full(const struct ringbuffer *this);

//-----------------------------------------------------------------------------
//! \brief Check if ring buffer is empty.
//! \param this The ring buffer to check.
//! \retval -1 in error case, otherwise 1 (true) / 0 (false).
int ringbuffer_is_empty(const struct ringbuffer *this);

#endif /* RINGBUFFER_H_ */