2015-03-31 13:28:11 +02:00
|
|
|
/** Node type: File
|
|
|
|
*
|
|
|
|
* This file implements the file type for nodes.
|
|
|
|
*
|
2015-05-06 11:36:51 +02:00
|
|
|
* @file
|
2015-06-02 21:53:04 +02:00
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
2017-04-27 12:56:43 +02:00
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLASnode
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* any later version.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* 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.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-03-03 20:20:13 -04:00
|
|
|
*********************************************************************************/
|
|
|
|
|
2015-09-19 18:48:00 +02:00
|
|
|
/**
|
2015-05-06 11:36:51 +02:00
|
|
|
* @addtogroup file File-IO node type
|
2015-09-19 18:48:00 +02:00
|
|
|
* @ingroup node
|
2015-05-06 11:36:51 +02:00
|
|
|
* @{
|
2017-03-03 20:20:13 -04:00
|
|
|
*/
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-03-07 08:04:37 -04:00
|
|
|
#include "advio.h"
|
2015-03-31 13:28:11 +02:00
|
|
|
#include "node.h"
|
|
|
|
|
2015-10-14 12:11:33 +02:00
|
|
|
#define FILE_MAX_PATHLEN 512
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FILE_READ,
|
|
|
|
FILE_WRITE
|
|
|
|
};
|
2015-05-19 16:55:39 +02:00
|
|
|
|
2015-03-31 13:28:11 +02:00
|
|
|
struct file {
|
2015-10-14 12:11:33 +02:00
|
|
|
struct file_direction {
|
2017-04-18 17:58:23 +02:00
|
|
|
AFILE *handle; /**< libc: stdio file handle. */
|
2015-08-09 23:52:44 +02:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
const char *mode; /**< libc: fopen() mode. */
|
2015-10-14 12:11:33 +02:00
|
|
|
const char *fmt; /**< Format string for file name. */
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
char *uri; /**< Real file name. */
|
2015-10-14 12:11:33 +02:00
|
|
|
} read, write;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2015-10-14 12:11:33 +02:00
|
|
|
enum read_epoch_mode {
|
2017-06-17 18:53:33 +02:00
|
|
|
FILE_EPOCH_DIRECT,
|
|
|
|
FILE_EPOCH_WAIT,
|
|
|
|
FILE_EPOCH_RELATIVE,
|
|
|
|
FILE_EPOCH_ABSOLUTE,
|
|
|
|
FILE_EPOCH_ORIGINAL
|
2015-10-14 12:11:33 +02:00
|
|
|
} read_epoch_mode; /**< Specifies how file::offset is calculated. */
|
2015-08-09 23:52:44 +02:00
|
|
|
|
2017-03-07 07:19:40 -04:00
|
|
|
struct timespec read_first; /**< The first timestamp in the file file::{read,write}::uri */
|
2015-10-14 12:11:33 +02:00
|
|
|
struct timespec read_epoch; /**< The epoch timestamp from the configuration. */
|
|
|
|
struct timespec read_offset; /**< An offset between the timestamp in the input file and the current time */
|
2017-05-08 00:46:48 +02:00
|
|
|
|
2017-06-17 18:53:00 +02:00
|
|
|
enum {
|
|
|
|
FILE_EOF_EXIT, /**< Terminate when EOF is reached. */
|
|
|
|
FILE_EOF_REWIND, /**< Rewind the file when EOF is reached. */
|
|
|
|
FILE_EOF_WAIT /**< Blocking wait when EOF is reached. */
|
|
|
|
} read_eof; /**< Should we rewind the file when we reach EOF? */
|
2015-10-14 12:11:33 +02:00
|
|
|
int read_timer; /**< Timer file descriptor. Blocks until 1 / rate seconds are elapsed. */
|
|
|
|
double read_rate; /**< The read rate. */
|
2015-03-31 13:28:11 +02:00
|
|
|
};
|
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::print */
|
2015-09-22 12:58:37 +02:00
|
|
|
char * file_print(struct node *n);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::parse */
|
2015-11-23 16:42:43 +01:00
|
|
|
int file_parse(struct node *n, config_setting_t *cfg);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::open */
|
2017-03-11 23:30:24 -03:00
|
|
|
int file_start(struct node *n);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::close */
|
2017-03-11 23:30:24 -03:00
|
|
|
int file_stop(struct node *n);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::read */
|
2016-06-08 22:39:43 +02:00
|
|
|
int file_read(struct node *n, struct sample *smps[], unsigned cnt);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::write */
|
2016-06-08 22:39:43 +02:00
|
|
|
int file_write(struct node *n, struct sample *smps[], unsigned cnt);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
/** @} */
|