2023-09-04 12:21:37 +02:00
|
|
|
/* Node type: File.
|
2015-03-31 13:28:11 +02:00
|
|
|
*
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2017-03-03 20:20:13 -04:00
|
|
|
*/
|
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#include <villas/format.hpp>
|
2020-03-04 13:06:28 +01:00
|
|
|
#include <villas/task.hpp>
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
2021-06-21 16:11:42 -04:00
|
|
|
// Forward declarations
|
2021-08-10 10:12:48 -04:00
|
|
|
class NodeCompat;
|
2021-06-21 16:11:42 -04:00
|
|
|
|
2023-09-07 11:46:39 +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 {
|
2023-09-07 11:46:39 +02:00
|
|
|
Format *formatter;
|
|
|
|
FILE *stream_in;
|
|
|
|
FILE *stream_out;
|
|
|
|
|
|
|
|
char *uri_tmpl; // Format string for file name.
|
|
|
|
char *uri; // Real file name.
|
|
|
|
|
|
|
|
unsigned skip_lines; // Skip the first n-th lines/samples of the file.
|
|
|
|
int flush; // Flush / upload file contents after each write.
|
|
|
|
struct Task
|
|
|
|
task; // Timer file descriptor. Blocks until 1 / rate seconds are elapsed.
|
|
|
|
double rate; // The read rate.
|
|
|
|
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.
|
|
|
|
|
|
|
|
enum class EpochMode {
|
|
|
|
DIRECT,
|
|
|
|
WAIT,
|
|
|
|
RELATIVE,
|
|
|
|
ABSOLUTE,
|
|
|
|
ORIGINAL
|
|
|
|
} epoch_mode; // Specifies how file::offset is calculated.
|
|
|
|
|
|
|
|
enum class EOFBehaviour {
|
|
|
|
STOP, // Terminate when EOF is reached.
|
|
|
|
REWIND, // Rewind the file when EOF is reached.
|
|
|
|
SUSPEND // Blocking wait when EOF is reached.
|
|
|
|
} eof_mode;
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
char *file_print(NodeCompat *n);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
|
|
|
int file_parse(NodeCompat *n, json_t *json);
|
|
|
|
|
|
|
|
int file_start(NodeCompat *n);
|
|
|
|
|
|
|
|
int file_stop(NodeCompat *n);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int file_init(NodeCompat *n);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int file_destroy(NodeCompat *n);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int file_poll_fds(NodeCompat *n, int fds[]);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int file_read(NodeCompat *n, struct Sample *const smps[], unsigned cnt);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int file_write(NodeCompat *n, struct Sample *const smps[], unsigned cnt);
|
2015-03-31 13:28:11 +02:00
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|