2023-09-04 12:21:37 +02:00
|
|
|
/* Node compatability layer for C++.
|
2021-08-10 10:12:48 -04: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
|
2021-08-10 10:12:48 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <jansson.h>
|
|
|
|
|
|
|
|
#include <villas/node.hpp>
|
|
|
|
#include <villas/node_compat_type.hpp>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/sample.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
class NodeCompatFactory;
|
|
|
|
|
|
|
|
class NodeCompat : public Node {
|
|
|
|
|
|
|
|
protected:
|
2023-09-07 11:46:39 +02:00
|
|
|
struct NodeCompatType *_vt; // Virtual functions (C++ OOP style)
|
|
|
|
void *_vd; // Virtual data (used by struct vnode::_vt functions)
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
std::string _details;
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual int _read(struct Sample *smps[], unsigned cnt);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual int _write(struct Sample *smps[], unsigned cnt);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
|
|
|
public:
|
2023-09-07 11:46:39 +02:00
|
|
|
NodeCompat *node;
|
|
|
|
json_t *cfg;
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
NodeCompat(struct NodeCompatType *vt, const uuid_t &id,
|
|
|
|
const std::string &name);
|
|
|
|
NodeCompat(const NodeCompat &n);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
NodeCompat &operator=(const NodeCompat &other);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual ~NodeCompat();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
template <typename T> T *getData() { return static_cast<T *>(_vd); }
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual NodeCompatType *getType() const { return _vt; }
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Parse node connection details.
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2024-02-29 21:47:13 +01:00
|
|
|
*
|
|
|
|
* @param json A JSON object containing the configuration of the node.
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual int parse(json_t *json);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
// Returns a string with a textual represenation of this node.
|
|
|
|
virtual const std::string &getDetails();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Check the current node configuration for plausability and errors.
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2024-02-29 21:47:13 +01:00
|
|
|
*
|
|
|
|
* @retval 0 Success. Node configuration is good.
|
|
|
|
* @retval <0 Error. The node configuration is bogus.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual int check();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual int prepare();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Start this node.
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2024-02-29 21:47:13 +01:00
|
|
|
*
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual int start();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Stop this node.
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2024-02-29 21:47:13 +01:00
|
|
|
*
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual int stop();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Restart this node.
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2024-02-29 21:47:13 +01:00
|
|
|
*
|
|
|
|
* @param n A pointer to the node object.
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual int restart();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Pause this node.
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2024-02-29 21:47:13 +01:00
|
|
|
*
|
|
|
|
* @param n A pointer to the node object.
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual int pause();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Resume this node.
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2024-02-29 21:47:13 +01:00
|
|
|
*
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual int resume();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Reverse source and destination of a node.
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2024-02-29 21:47:13 +01:00
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual int reverse();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual std::vector<int> getPollFDs();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
// Get list of socket file descriptors for configuring network emulation.
|
|
|
|
virtual std::vector<int> getNetemFDs();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
// Return a memory allocator which should be used for sample pools passed to this node.
|
|
|
|
virtual struct memory::Type *getMemoryType();
|
2021-08-10 10:12:48 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeCompatFactory : public NodeFactory {
|
|
|
|
|
|
|
|
protected:
|
2023-09-07 11:46:39 +02:00
|
|
|
struct NodeCompatType *_vt;
|
2021-08-10 10:12:48 -04:00
|
|
|
|
|
|
|
public:
|
2023-09-07 11:46:39 +02:00
|
|
|
NodeCompatFactory(struct NodeCompatType *vt) : NodeFactory(), _vt(vt) {}
|
|
|
|
|
|
|
|
virtual Node *make(const uuid_t &id = {}, const std::string &name = "");
|
|
|
|
|
|
|
|
/// Get plugin name
|
|
|
|
virtual std::string getName() const { return _vt->name; }
|
|
|
|
|
|
|
|
/// Get plugin description
|
|
|
|
virtual std::string getDescription() const { return _vt->description; }
|
|
|
|
|
|
|
|
virtual int getFlags() const;
|
|
|
|
|
|
|
|
virtual int getVectorize() const { return _vt->vectorize; }
|
|
|
|
|
|
|
|
virtual int start(SuperNode *sn);
|
|
|
|
|
|
|
|
virtual int stop();
|
2021-08-10 10:12:48 -04:00
|
|
|
};
|
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|