/**
 * Copyright 2013 Cabot Communications.  All rights reserved.
 *
 * @created Jan 7, 2013
 * 
 * @brief [TODO: Provide a brief description about the contents of this file]
 * 
 */


#ifndef FROST_CIRCULAR_BUFFER_H_
#define FROST_CIRCULAR_BUFFER_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "frost_common.h"

/**
 * @note CircularBuffer is not thread safe, accesses to it should be synchronized
 *       in multi-threaded cases.
 */
typedef struct CircularBuffer
{
    frost_uint8     * buffer;
    frost_uint        capacity;
    frost_uint        read_index;
    frost_uint        write_index;
    frost_uint        num_items;
} CircularBuffer;

CircularBuffer* circular_buffer_create_new(frost_uint capacity);
void            circular_buffer_destroy(CircularBuffer* cb);
frost_int       circular_buffer_add(CircularBuffer *cb, const frost_uint8 *data, const frost_uint data_len);
frost_int       circular_buffer_retrieve(CircularBuffer *cb, frost_uint8 *data, frost_uint data_len);
frost_uint      circular_buffer_avail_space(const CircularBuffer *cb);
frost_bool      circular_buffer_empty(const CircularBuffer *cb);

#ifdef __cplusplus
}
#endif

#endif /* FROST_CIRCULAR_BUFFER_H_ */
