2015-03-31 13:28:11 +02:00
|
|
|
/** Node type: File
|
|
|
|
*
|
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>
|
2020-01-20 17:17:00 +01:00
|
|
|
* @copyright 2014-2020, 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-12-09 02:19:28 +08:00
|
|
|
#include <villas/io.h>
|
|
|
|
#include <villas/node.h>
|
2020-03-04 13:06:28 +01:00
|
|
|
#include <villas/task.hpp>
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2018-06-29 08:37:14 +02:00
|
|
|
#define FILE_MAX_PATHLEN 512
|
2015-10-14 12:11:33 +02:00
|
|
|
|
2015-03-31 13:28:11 +02:00
|
|
|
struct file {
|
2018-06-29 08:37:14 +02:00
|
|
|
struct io io; /**< Format and file IO */
|
2018-05-12 13:56:12 +02:00
|
|
|
struct format_type *format;
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2018-06-29 08:37:14 +02:00
|
|
|
char *uri_tmpl; /**< Format string for file name. */
|
|
|
|
char *uri; /**< Real file name. */
|
|
|
|
char *mode; /**< File access mode. */
|
2017-07-24 19:33:35 +02:00
|
|
|
|
2020-07-16 14:18:05 +02:00
|
|
|
unsigned skip_lines; /**< Skip the first n-th lines/samples of the file. */
|
2018-06-29 08:37:14 +02:00
|
|
|
int flush; /**< Flush / upload file contents after each write. */
|
2020-03-04 13:06:28 +01:00
|
|
|
struct Task task; /**< Timer file descriptor. Blocks until 1 / rate seconds are elapsed. */
|
2018-06-29 08:37:14 +02:00
|
|
|
double rate; /**< The read rate. */
|
2018-08-06 23:48:13 +02:00
|
|
|
size_t buffer_size_out; /**< Defines size of output stream buffer. No buffer is created if value is set to zero. */
|
|
|
|
size_t buffer_size_in; /**< Defines size of input stream buffer. No buffer is created if value is set to zero. */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
enum class EpochMode {
|
2019-04-22 23:43:46 +02:00
|
|
|
DIRECT,
|
|
|
|
WAIT,
|
|
|
|
RELATIVE,
|
|
|
|
ABSOLUTE,
|
|
|
|
ORIGINAL
|
2018-06-29 08:37:14 +02:00
|
|
|
} epoch_mode; /**< Specifies how file::offset is calculated. */
|
2017-12-09 02:19:28 +08:00
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
enum class EOFBehaviour {
|
2019-04-22 23:43:46 +02:00
|
|
|
STOP, /**< Terminate when EOF is reached. */
|
|
|
|
REWIND, /**< Rewind the file when EOF is reached. */
|
|
|
|
SUSPEND /**< Blocking wait when EOF is reached. */
|
|
|
|
} eof_mode;
|
2017-08-14 14:42:07 +02:00
|
|
|
|
2018-06-29 08:37:14 +02:00
|
|
|
struct timespec first; /**< The first timestamp in the file file::{read,write}::uri */
|
|
|
|
struct timespec epoch; /**< The epoch timestamp from the configuration. */
|
|
|
|
struct timespec offset; /**< An offset between the timestamp in the input file and the current time */
|
2015-03-31 13:28:11 +02:00
|
|
|
};
|
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::print */
|
2020-08-25 21:00:52 +02:00
|
|
|
char * file_print(struct vnode *n);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::parse */
|
2020-08-25 21:00:52 +02:00
|
|
|
int file_parse(struct vnode *n, json_t *cfg);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2020-01-21 14:27:28 +01:00
|
|
|
/** @see node_type::start */
|
2020-08-25 21:00:52 +02:00
|
|
|
int file_start(struct vnode *n);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2020-01-21 14:27:28 +01:00
|
|
|
/** @see node_type::stop */
|
2020-08-25 21:00:52 +02:00
|
|
|
int file_stop(struct vnode *n);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::read */
|
2020-08-25 21:00:52 +02:00
|
|
|
int file_read(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::write */
|
2020-08-25 21:00:52 +02:00
|
|
|
int file_write(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2018-06-29 08:37:14 +02:00
|
|
|
/** @} */
|