PDUUnit.h 1.78 KB
Newer Older
1
2
3
4
5
6
7
/*
 * PDUUnit.h
 *
 *  Created on: 26.02.2018
 *      Author: Micha Mueller
 */

Micha Mueller's avatar
Micha Mueller committed
8
9
#ifndef PDUUNIT_H_
#define PDUUNIT_H_
10

Micha Mueller's avatar
Micha Mueller committed
11
12
#include "../../Sensor.h"	//only for logging

13
14
15
16
17
#include <tuple>
#include <vector>
#include <utility>
#include <string>

18
#include <boost/asio.hpp>
19
20
#include <boost/property_tree/ptree.hpp>

Micha Mueller's avatar
Micha Mueller committed
21

22
23
24
typedef std::vector<std::pair<std::string, std::string>> attributesVector_t;
typedef std::vector<std::tuple<std::string, std::string, attributesVector_t>> xmlPathVector_t;

25

26
class PDUUnit {
27

28
29
30
31
public:
	PDUUnit();
	virtual ~PDUUnit();

32
33
	void setTTL(unsigned ttl) {
		_ttl = ttl;
34
35
	}

36
37
	unsigned getTTL() const {
		return _ttl;
38
39
	}

40
41
42
43
	void setHost(const std::string& host) {
		_host = host;
	}

44
	const std::string& getHost() {
45
46
47
		return _host;
	}

48
49
50
51
52
53
54
55
	void setRequest(const std::string& request) {
		_request = request;
	}

	const std::string& getRequest() {
		return _request;
	}

Micha Mueller's avatar
Micha Mueller committed
56
	void initializeStrand(boost::asio::io_service& io);
57
58
59
60
61

	boost::asio::io_service::strand* getStrand() const {
		return _strand;
	}

62
	/**
63
64
	 * Finds and returns the corresponding value in the energy.xml
	 * Checks if the _ptree is still up to date. If not updates it by a call to refresh().
65
	 *
66
67
	 * @param xmlPath		Holds all data required to identify the XML path to the sensor value
	 * @return				The value in the latest energy.xml, denoted by paths and attributes
68
	 */
69
	uint64_t readValue(const xmlPathVector_t& xmlPath);
70
71
72
73

private:

	/**
74
	 * Gets a current version of the XML-file energy.xml with sensor data and parses its content into _ptree
75
	 */
76
	void refresh();
77
78

	uint64_t 	_lastRefresh;
79
	unsigned int _ttl;
80
	std::string	_host;
81
	std::string	_request;
82
	boost::property_tree::ptree _ptree;
83
	boost::asio::io_service::strand* _strand;
84
85

	boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
86
87
};

Micha Mueller's avatar
Micha Mueller committed
88
#endif /* PDUUNIT_H_ */