1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/include/villas/hooks/limit_rate.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
930 B
C++
Raw Permalink Normal View History

/* Rate-limiting hook.
*
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
*/
#pragma once
2019-03-26 15:33:47 +01:00
#include <villas/hook.hpp>
namespace villas {
namespace node {
class LimitRateHook : public LimitHook {
2019-03-26 15:33:47 +01:00
protected:
// The timestamp which should be used for limiting.
enum { LIMIT_RATE_LOCAL, LIMIT_RATE_RECEIVED, LIMIT_RATE_ORIGIN } mode;
2019-03-26 15:33:47 +01:00
double deadtime;
timespec last;
2019-03-26 15:33:47 +01:00
public:
LimitRateHook(Path *p, Node *n, int fl, int prio, bool en = true)
: LimitHook(p, n, fl, prio, en), mode(LIMIT_RATE_LOCAL), deadtime(0),
last({0, 0}) {}
virtual void setRate(double rate, double maxRate = -1) {
deadtime = 1.0 / rate;
}
virtual void parse(json_t *json);
virtual Hook::Reason process(struct Sample *smp);
2019-03-26 15:33:47 +01:00
};
} // namespace node
} // namespace villas