PerfeventConfigurator.h 2.12 KB
Newer Older
1
/*
2
 * PerfeventConfigurator.h
3
4
5
6
7
 *
 *  Created on: 13.12.2017
 *      Author: Micha Mueller
 */

8
9
#ifndef PERFEVENTCONFIGURATOR_H_
#define PERFEVENTCONFIGURATOR_H_
10

11
#include <set>
12

13
#include "../../ConfiguratorTemplate.h"
14
#include "PerfSensorGroup.h"
15
#include "PerfSingleSensor.h"
16

17
class PerfeventConfigurator : public ConfiguratorTemplate<PerfSensorBase, PerfSingleSensor> {
18

19
	typedef std::map<std::string, std::set<int>> templateCpuMap_t;
20
	typedef std::map<std::string, unsigned int> enumMap_t;
21

22
23
24
public:
	PerfeventConfigurator();
	virtual ~PerfeventConfigurator();
25

26
27
28
protected:
	bool derivedReadConfig(boost::property_tree::iptree& cfg) override;
	void derivedReReadConfig() override { _templateCpus.clear(); }
29
30
	void derivedSetGlobalSettings(const pluginSettings_t& pluginSettings) override { /*nothing to overwrite*/ }
	bool derivedReadSensorBase(PerfSensorBase& sensor, boost::property_tree::iptree& config) override;
31

32
private:
33
34
35
36
37
38
39
40
41
42
43
	/**
	 * Increase the mqtt by val means
	 * Example: increaseMqtt("003F", 1) 	returns "0040"
	 * 			increaseMqtt("003F", 15)	returns "004D"
	 *
	 * @param mqtt	The mqtt-topic to be increased
	 * @param val	The value by which the mqtt-topic should be increased
	 * @return	The increased mqtt-topic
	 */
	const std::string increaseMqtt(const std::string& mqtt, int val);

44
45
46
47
48
49
50
51
52
53
54
	/**
	 * Tries to parse the given cpuString as integer numbers. On success, the specified numbers will be inserted
	 * into a set, which will be returned. On failure, an empty set is returned. A set is used to maintain uniqueness
	 * and an ascending order among the numbers although this is not strictly required.
	 *
	 * @param cpuString	String which specifies a range and/or set of numbers (e.g. "1,2,3-5,7-9,10")
	 * @return	A set of integers as specified in the cpuString. If the string could not be parsed the set will be empty.
	 */
	std::set<int> parseCpuString(const std::string& cpuString);

	templateCpuMap_t _templateCpus;
55

56
57
	enumMap_t _enumType;
	enumMap_t _enumConfig;
58
59
};

60
extern "C" ConfiguratorInterface* create() {
61
62
63
	return new PerfeventConfigurator;
}

64
extern "C" void destroy(ConfiguratorInterface* c) {
65
66
67
	delete c;
}

68
#endif /* PERFEVENTCONFIGURATOR_H_ */