/*
mkfifo.h - Part of ardcom - Easy communication over USB with Arduino
Copyright 2013 - Laurent Menu-Kerforn
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//MKF4ARDUINO to be defined for using this lib in arduino

#ifndef __MKFIFO_H
#define __MKFIFO_H

#ifdef MKF4ARDUINO
#ifndef MKF_SLEN
	#define MKF_SLEN 128
#endif
#ifndef MKF_BIGSTRING
	#define MKF_BIGSTRING 256
#endif
#ifndef MKF_MAXENTRIES
	#define MKF_MAXENTRIES 64
#endif

#else
#ifndef MKF_SLEN
	#define MKF_SLEN 256
#endif
#ifndef MKF_BIGSTRING
	#define MKF_BIGSTRING 2048
#endif
#ifndef MKF_MAXENTRIES
	#define MKF_MAXENTRIES 1024
#endif
#endif

#ifndef MKF4ARDUINO
#include <semaphore.h>
#endif

struct _mkf {
	int magic;
	char filename[MKF_SLEN];
	int head;
	int tail;
#ifndef MKF4ARDUINO
	sem_t sem;
#endif
	char* entry[MKF_MAXENTRIES];
	};

typedef struct _mkf mkf;

int mkfinit(mkf *mkf,char *filename);
int mkfcount(mkf *mkf);
int mkfsize(mkf *mkf);
int mkfdump(mkf *mkf, char*out,size_t n);
int _mkfwrite(mkf *mkf,char *data);
int mkfwrite(mkf *mkf,char *data);
int mkfwritehead(mkf *mkf,char *data);
int mkfempty(mkf *mkf);
int mkfread(mkf *mkf,char *buf,size_t n);
int mkfreadtail(mkf *mkf,char *buf,size_t n);
char *mkfpeek(mkf *mkf);
char* mkfpeektail(mkf *mkf);
int mkfflush(mkf *mkf);
int mkfdelete(mkf *mkf);
int mkflock(mkf *mkf);
int mkfunlock(mkf *mkf);

#ifndef MKF4ARDUINO
int mkfload(mkf *mkf);
int mkfsave(mkf *mkf);
int mkfdebug(mkf *mkf);
#endif

#endif

