2025-01-14 14:42:39 +00:00
|
|
|
/* Node-type for exec node-types.
|
2019-06-05 18:59:45 +02:00
|
|
|
*
|
2025-01-14 14:42:39 +00:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2019-06-05 18:59:45 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
#include <villas/format.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/node.hpp>
|
2019-06-05 18:59:45 +02:00
|
|
|
#include <villas/popen.hpp>
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
// Forward declarations
|
2021-08-10 10:12:48 -04:00
|
|
|
struct Sample;
|
|
|
|
|
|
|
|
class ExecNode : public Node {
|
2019-06-05 18:59:45 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
protected:
|
2025-01-14 14:42:39 +00:00
|
|
|
std::unique_ptr<villas::utils::Popen> proc;
|
|
|
|
std::unique_ptr<Format> formatter;
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
FILE *stream_in, *stream_out;
|
2019-06-05 18:59:45 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
bool flush;
|
|
|
|
bool shell;
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
std::string working_dir;
|
|
|
|
std::string command;
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
villas::utils::Popen::arg_list arguments;
|
|
|
|
villas::utils::Popen::env_map environment;
|
2021-05-10 00:12:30 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual int _read(struct Sample *smps[], unsigned cnt);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual int _write(struct Sample *smps[], unsigned cnt);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
|
|
|
public:
|
2025-01-14 14:42:39 +00:00
|
|
|
ExecNode(const uuid_t &id = {}, const std::string &name = "")
|
|
|
|
: Node(id, name), stream_in(nullptr), stream_out(nullptr), flush(true),
|
|
|
|
shell(false) {}
|
2019-06-05 18:59:45 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual ~ExecNode();
|
2019-06-05 18:59:45 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual const std::string &getDetails();
|
2019-06-05 18:59:45 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual int start();
|
2019-06-05 18:59:45 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual int stop();
|
2019-06-05 18:59:45 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual int prepare();
|
2019-06-05 18:59:45 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual int parse(json_t *json);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
virtual std::vector<int> getPollFDs();
|
2021-08-10 10:12:48 -04:00
|
|
|
};
|
2019-06-05 18:59:45 +02:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|