Commit 26585a60 authored by Micha Mueller's avatar Micha Mueller
Browse files

Complete non-virtual interface template. Remaining TODO: adapt all plugins

parent 6e62af04
......@@ -8,10 +8,8 @@
#ifndef SRC_CONFIGURATOR_H_
#define SRC_CONFIGURATOR_H_
#include "Sensor.h"
#include "ConfiguratorInterface.h"
#include <vector>
#include <string>
#include <map>
#include <boost/foreach.hpp>
......@@ -19,20 +17,15 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>
typedef struct {
std::string mqttPrefix;
std::string tempdir;
unsigned int cacheInterval;
} pluginSettings_t;
/**
* Non-virtual interface template for the configurators.
*/
template <typename S>
class Configurator {
//the template shall only be instantiated for the sensors corresponding to the configurator
class Configurator : public ConfiguratorInterface {
//the template shall only be instantiated for classes which implement the sensor interface
static_assert(std::is_base_of<Sensor, S>::value, "S must derive from Sensor!");
protected:
typedef std::map<std::string, S> sensorMap_t;
public:
......@@ -51,7 +44,7 @@ public:
*
* @return True on success, false otherwise
*/
bool readConfig(std::string cfgPath) {
bool readConfig(std::string cfgPath) final {
_cfgPath = cfgPath;
boost::property_tree::iptree cfg;
......@@ -81,7 +74,7 @@ public:
if (!sens.second.empty()) {
S sensor(sens.second.data());
if(readSensor(sensor, sens.second)) {
_templateSensors.insert(sensorMap_t::value_type(sensor.getName(), sensor));
_templateSensors.insert(std::pair<std::string, S>(sensor.getName(), sensor));
} else {
LOG(warning) << "Template sensor \"" << sens.second.data() << "\" has bad values! Ignoring...";
}
......@@ -98,7 +91,7 @@ public:
*
* @return True on success, false otherwise
*/
bool reReadConfig() {
bool reReadConfig() final {
for (auto s : _sensors) {
s->stopPolling();
}
......@@ -121,7 +114,7 @@ public:
*
* @param pluginSettings Struct with global default settings for the plugins.
*/
void setGlobalSettings(const pluginSettings_t& pluginSettings) {
void setGlobalSettings(const pluginSettings_t& pluginSettings) final {
_mqttPrefix = pluginSettings.mqttPrefix;
_cacheInterval = pluginSettings.cacheInterval;
......@@ -133,7 +126,7 @@ public:
*
* @return Vector containing pointers to all sensors of this plugin
*/
std::vector<Sensor*>& getSensors() {
std::vector<Sensor*>& getSensors() final {
return _sensors;
}
......@@ -213,8 +206,4 @@ protected:
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
};
//typedef for more readable usage of create()- and destroy()-methods, required for dynamic libraries
typedef Configurator<Sensor>* create_t();
typedef void destroy_t(Configurator<Sensor>*);
#endif /* SRC_CONFIGURATOR_H_ */
/*
* ConfiguratorInterface.h
*
* Created on: 06.08.2018
* Author: Micha Mueller
*/
#ifndef SRC_CONFIGURATORINTERFACE_H_
#define SRC_CONFIGURATORINTERFACE_H_
#include "Sensor.h"
#include <string>
#include <vector>
typedef struct {
std::string mqttPrefix;
std::string tempdir;
unsigned int cacheInterval;
} pluginSettings_t;
/**
* Abstract interface which defines the functionality of a configurator
*/
class ConfiguratorInterface {
public:
virtual ~ConfiguratorInterface() {}
virtual bool readConfig(std::string cfgPath) = 0;
virtual bool reReadConfig() = 0;
virtual void setGlobalSettings(const pluginSettings_t& pluginSettings) = 0;
virtual std::vector<Sensor*>& getSensors() = 0;
};
//typedef for more readable usage of create()- and destroy()-methods, required for dynamic libraries
typedef ConfiguratorInterface* create_t();
typedef void destroy_t(ConfiguratorInterface*);
#endif /* SRC_CONFIGURATORINTERFACE_H_ */
......@@ -17,13 +17,13 @@
#include <string>
#include <vector>
#include "Configurator.h"
#include "ConfiguratorInterface.h"
//struct of values required for a dynamic library.
typedef struct {
std::string id;
void* DL;
Configurator<Sensor>* configurator;
ConfiguratorInterface* configurator;
create_t* create;
destroy_t* destroy;
} dl_t;
......
......@@ -18,7 +18,7 @@
#include <map>
#include <boost/property_tree/ptree.hpp>
class BACnetConfigurator: public Configurator {
class BACnetConfigurator: public Configurator<BACnetSensor> {
typedef std::map<std::string, BACnetSensor> sensorMap_t;
......
......@@ -20,7 +20,7 @@
namespace DCDB {
class IPMIConfigurator : public Configurator {
class IPMIConfigurator : public Configurator<IPMISensor> {
typedef std::list<DCDB::IPMIHost> hostList_t;
typedef std::map<std::string, DCDB::IPMISensor> sensorMap_t;
......
......@@ -17,7 +17,7 @@
#ifndef SRC_SENSORS_PDU_PDUCONFIGURATOR_H_
#define SRC_SENSORS_PDU_PDUCONFIGURATOR_H_
class PDUConfigurator: public Configurator {
class PDUConfigurator: public Configurator<PDUSensor> {
typedef std::map<std::string, PDUSensor> sensorMap_t;
typedef std::list<PDUUnit> pduList_t;
......
......@@ -16,7 +16,7 @@
#include <set>
#include <boost/property_tree/ptree.hpp>
class PerfeventConfigurator : public Configurator {
class PerfeventConfigurator : public Configurator<PerfCounter> {
typedef std::map<std::string, PerfCounter> counterMap_t;
typedef std::map<std::string, std::set<int>> templateCpuMap_t;
......
......@@ -36,11 +36,11 @@ private:
connectionList_t _connections;
};
extern "C" Configurator* create() {
extern "C" ConfiguratorInterface* create() {
return new SNMPConfigurator;
}
extern "C" void destroy(Configurator* c) {
extern "C" void destroy(ConfiguratorInterface* c) {
delete c;
}
......
......@@ -15,7 +15,7 @@
#include <map>
#include <boost/property_tree/ptree.hpp>
class SysfsConfigurator : public Configurator{
class SysfsConfigurator : public Configurator<SysfsSensor> {
typedef std::map<std::string, SysfsSensor> sensorMap_t;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment