2011-05-25 00:40:20 +02:00
|
|
|
/**
|
2011-09-10 00:00:26 +02:00
|
|
|
* Circular buffer (double linked, threadsafe)
|
|
|
|
*
|
|
|
|
* Used to store recent readings and buffer in case of net inconnectivity
|
2011-05-25 00:40:20 +02:00
|
|
|
*
|
|
|
|
* @author Steffen Vogel <info@steffenvogel.de>
|
|
|
|
* @copyright Copyright (c) 2011, The volkszaehler.org project
|
|
|
|
* @package vzlogger
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This file is part of volkzaehler.org
|
|
|
|
*
|
|
|
|
* volkzaehler.org 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
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* volkzaehler.org 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 volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-09-10 00:00:26 +02:00
|
|
|
#ifndef _BUFFER_H_
|
|
|
|
#define _BUFFER_H_
|
2011-05-25 00:40:20 +02:00
|
|
|
|
2011-09-10 00:00:26 +02:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <sys/time.h>
|
2011-05-25 00:40:20 +02:00
|
|
|
|
2012-01-19 18:50:54 +01:00
|
|
|
#include "meter.h"
|
2011-05-25 00:40:20 +02:00
|
|
|
|
2011-05-26 23:33:47 +02:00
|
|
|
typedef struct {
|
2011-10-07 22:26:03 +02:00
|
|
|
reading_t *tail;
|
|
|
|
reading_t *head;
|
|
|
|
reading_t *sent;
|
2011-09-10 00:00:26 +02:00
|
|
|
|
|
|
|
int size; /* number of readings currently in the buffer */
|
2011-09-15 21:41:20 +02:00
|
|
|
int keep; /* number of readings to cache for local interface */
|
2011-09-10 00:00:26 +02:00
|
|
|
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
} buffer_t;
|
|
|
|
|
2011-11-21 00:38:05 +01:00
|
|
|
/* prototypes */
|
2011-10-07 22:26:03 +02:00
|
|
|
void buffer_init(buffer_t *buf);
|
|
|
|
reading_t * buffer_push(buffer_t *buf, reading_t *rd);
|
2011-09-10 00:00:26 +02:00
|
|
|
void buffer_free(buffer_t *buf);
|
|
|
|
void buffer_clean(buffer_t *buf);
|
|
|
|
void buffer_clear(buffer_t *buf);
|
2012-02-03 13:51:52 +01:00
|
|
|
char * buffer_dump(buffer_t *buf, char *dump, size_t len);
|
2011-05-25 00:40:20 +02:00
|
|
|
|
2011-06-05 13:16:27 +02:00
|
|
|
|
2011-09-10 00:00:26 +02:00
|
|
|
#endif /* _BUFFER_H_ */
|
2011-05-25 00:40:20 +02:00
|
|
|
|