2016-05-19 14:41:06 +00:00
|
|
|
#include "config.hpp"
|
|
|
|
#include "modules/counter.hpp"
|
|
|
|
#include "utils/config.hpp"
|
|
|
|
#include "utils/math.hpp"
|
|
|
|
#include "utils/string.hpp"
|
|
|
|
|
|
|
|
using namespace modules;
|
|
|
|
|
2016-06-21 01:59:43 +00:00
|
|
|
CounterModule::CounterModule(std::string module_name) : TimerModule(module_name, 1s)
|
2016-05-19 14:41:06 +00:00
|
|
|
{
|
|
|
|
this->interval = std::chrono::duration<double>(
|
|
|
|
config::get<float>(name(), "interval", 1));
|
|
|
|
|
|
|
|
this->formatter->add(DEFAULT_FORMAT, TAG_COUNTER, { TAG_COUNTER });
|
|
|
|
|
|
|
|
this->counter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CounterModule::update()
|
|
|
|
{
|
|
|
|
this->counter = this->counter() + 1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-21 01:59:43 +00:00
|
|
|
bool CounterModule::build(Builder *builder, std::string tag)
|
2016-05-19 14:41:06 +00:00
|
|
|
{
|
|
|
|
if (tag == TAG_COUNTER) {
|
|
|
|
builder->node(std::to_string(this->counter()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|