Configurator.h 1.72 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
 * Configurator.h
 *
 *  Created on: 13.01.2018
 *      Author: Micha Mueller
 */

#ifndef SRC_CONFIGURATOR_H_
#define SRC_CONFIGURATOR_H_

11
12
#include "Sensor.h"

13
14
#include <vector>
#include <string>
15

16
17
18
typedef struct {
	std::string mqttPrefix;
	std::string	tempdir;
19
	unsigned int cacheInterval;
20
} pluginSettings_t;
21

Micha Mueller's avatar
Micha Mueller committed
22
/**
23
24
 * Base class, which defines the interface for the configurators in the shared dynamic libraries.
 * This base class shall not be constructed on itw own.
Micha Mueller's avatar
Micha Mueller committed
25
 */
26
27
class Configurator {
public:
28
	Configurator() : _cacheInterval(900000) {}
29
30
31
32
33
34

	virtual ~Configurator() {
		for (auto s : _sensors) {
			delete s;
		}
	}
35

Micha Mueller's avatar
Micha Mueller committed
36
37
38
	/**
	 * Read in the given configuration
	 * @param	cfgPath Path to the config-file
39
	 * @return	true on success, false otherwise
Micha Mueller's avatar
Micha Mueller committed
40
	 */
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
	virtual bool readConfig(std::string cfgPath) {
		_cfgPath = cfgPath;
		return true;
	}

	/**
	 * Clear internal storage and read in the configuration again.
	 */
	virtual bool reReadConfig() {
		for (auto s : _sensors) {
			s->stopPolling();
		}
		for (auto s : _sensors) {
			delete s;
		}
		_sensors.clear();
		return this->readConfig(_cfgPath);
	}
59

60
61
62
	virtual void setGlobalSettings(const pluginSettings_t& pluginSettings) {
		_mqttPrefix = pluginSettings.mqttPrefix;
		_cacheInterval = pluginSettings.cacheInterval;
63
64
	}

65
66
67
68
	std::vector<Sensor*>& getSensors() {
		return _sensors;
	}

69
protected:
70
	std::string _cfgPath;
71
	std::string _mqttPrefix;
72
	unsigned int _cacheInterval;
73
	std::vector<Sensor*> _sensors;
74
	boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
75
76
};

Micha Mueller's avatar
Micha Mueller committed
77
//typedef for more readable usage of create()- and destroy()-methods, required for dynamic libraries
78
79
80
81
typedef Configurator* create_t();
typedef void destroy_t(Configurator*);

#endif /* SRC_CONFIGURATOR_H_ */