2017-05-18 03:11:31 -07:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* File: metrics_hub.h
|
|
|
|
* Description: Centralizes metrics interfaces to allow different metrics clients
|
|
|
|
* to get metrics
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef METRICS_HUB_H
|
|
|
|
#define METRICS_HUB_H
|
|
|
|
|
|
|
|
#include <vector>
|
2017-05-31 14:39:17 -07:00
|
|
|
#include "srslte/common/threads.h"
|
2017-05-18 03:11:31 -07:00
|
|
|
|
|
|
|
namespace srslte {
|
|
|
|
|
|
|
|
template<typename metrics_t>
|
|
|
|
class metrics_interface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool get_metrics(metrics_t &m) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename metrics_t>
|
|
|
|
class metrics_listener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void set_metrics(metrics_t &m) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename metrics_t>
|
|
|
|
class metrics_hub : public periodic_thread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool init(metrics_interface<metrics_t> *m_, float report_period_secs=1.0) {
|
|
|
|
m = m_;
|
|
|
|
start_periodic(report_period_secs*1e6);
|
|
|
|
}
|
|
|
|
void stop() {
|
|
|
|
thread_cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_listener(metrics_listener<metrics_t> *listener) {
|
|
|
|
listeners.push_back(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void run_period() {
|
|
|
|
metrics_t metric;
|
|
|
|
m->get_metrics(metric);
|
|
|
|
for (int i=0;i<listeners.size();i++) {
|
|
|
|
listeners[i]->set_metrics(metric);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
metrics_interface<metrics_t> *m;
|
|
|
|
std::vector<metrics_listener<metrics_t>*> listeners;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace srslte
|
|
|
|
|
|
|
|
#endif // METRICS_HUB_H
|