//
//  buffer.cpp
//
//  Created by hark on 2014/06/13.
//  Copyright (c) 2014 hark. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>

#include "bt_extern.h"
#include "buffer.h"

BufferObject::BufferObject(const unsigned int argdefsize) : buffer(argdefsize)
{
    
}

BufferObject::~BufferObject()
{

}

static BufferObject buf(local_buffer_num);

int buf_write(struct rawdata *raw)
{

  return(buf.write(*raw));

}

int buf_read(struct rawdata *raw)
{

  return(buf.read(*raw));

}
//
//
//
static const int buffernum = 128;
AsyncBufferObject::AsyncBufferObject() : buffer(buffernum)
{
  int ret = ::pthread_mutex_init(&buf_mutex, NULL);
  if (ret != 0) {
    perror("pthread_mutex_init");
    return;
  }

}

AsyncBufferObject::~AsyncBufferObject()
{

  ::pthread_mutex_destroy(&buf_mutex);
}

static AsyncBufferObject *dbuf;

int dbuf_write(struct rawdata_v *raw)
{

  return(dbuf->write(*raw));

}

int dbuf_read(struct rawdata_v *raw)
{

  return(dbuf->read(*raw));

}

int dbuf_lock()
{

  return(dbuf->lock());
}

int dbuf_unlock()
{
  return(dbuf->unlock());
}

int buf_init(void)
{

  dbuf = new AsyncBufferObject;

  return(0);
}
