PerfSensorBase.h 1.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
 * PerfSensorBase.h
 *
 *  Created on: 09.08.2018
 *      Author: Micha Mueller
 */

#ifndef PERFEVENT_PERFSENSORBASE_H_
#define PERFEVENT_PERFSENSORBASE_H_

11
#include "../../includes/SensorBase.h"
12
13
#include <limits.h>

14
15
class PerfSensorBase : virtual public SensorBase {
public:
lu43jih's avatar
lu43jih committed
16
	static constexpr uint64_t MAXCOUNTERVALUE = ULLONG_MAX; //ToDo check if it is not ULLONG_MAX, or make it configurable!
17

18
19
20
	PerfSensorBase(const std::string& name) :
		SensorBase(name),
		_type(0),
21
		_config(0) {}
22
23
24
25
26
27
28
29

	virtual ~PerfSensorBase() {}

	unsigned getType() 		const { return _type; }
	unsigned getConfig()	const { return _config; }

	void setType(unsigned type)		{ _type = type; }
	void setConfig(unsigned config)	{ _config = config;	}
30

31
	void storeInReadingQueue(reading_t & reading, unsigned cacheSize) {
32
		_readingQueue->push(reading);
33
34
		_cache[_cacheIndex] = reading;
		_cacheIndex = (_cacheIndex + 1) % cacheSize;
35
36
37
	}

	void setLatestValid(reading_t & reading, uint64_t valueNoCorrection){
lu43jih's avatar
lu43jih committed
38
39
		_latestValue.value = valueNoCorrection;
		_latestValue.timestamp = reading.timestamp;
40
41
	}

lu43jih's avatar
lu43jih committed
42

43
44
45
46
47
protected:
	unsigned int _type;
	unsigned int _config;
};

48
49
using PerfSBPtr = std::shared_ptr<PerfSensorBase>;

50
#endif /* PERFEVENT_PERFSENSORBASE_H_ */