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

hooks: add a common base class for rate limiting hooks

This commit is contained in:
Steffen Vogel 2019-04-12 09:50:42 +02:00
parent b8baa79d3a
commit b4150d2053
3 changed files with 29 additions and 9 deletions

View file

@ -140,6 +140,15 @@ public:
}
};
class LimitHook : public Hook {
public:
using Hook::Hook;
virtual void setRate(double rate, double maxRate = -1) = 0;
};
class HookFactory : public plugin::Plugin {
protected:

View file

@ -31,14 +31,25 @@
namespace villas {
namespace node {
class DecimateHook : public Hook {
class DecimateHook : public LimitHook {
protected:
int ratio;
unsigned counter;
public:
using Hook::Hook;
using LimitHook::LimitHook;
virtual void setRate(double rate, double maxRate = -1)
{
assert(maxRate > 0);
int ratio = maxRate / rate;
if (ratio == 0)
ratio = 1;
setRatio(ratio);
}
void setRatio(int r)
{

View file

@ -31,7 +31,7 @@
namespace villas {
namespace node {
class LimitRateHook : public Hook {
class LimitRateHook : public LimitHook {
protected:
enum {
@ -44,18 +44,18 @@ protected:
timespec last;
public:
void setRate(double rate)
{
deadtime = 1.0 / rate;
}
LimitRateHook(struct path *p, struct node *n, int fl, int prio, bool en = true) :
Hook(p, n, fl, prio, en),
LimitHook(p, n, fl, prio, en),
mode(LIMIT_RATE_LOCAL)
{
last = (timespec) { 0, 0 };
}
virtual void setRate(double rate, double maxRate = -1)
{
deadtime = 1.0 / rate;
}
virtual void parse(json_t *cfg);
virtual int process(sample *smp);