PDUUnit.h 2.57 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//================================================================================
// Name        : PDUUnit.h
// Author      : Micha Mueller
// Copyright   : Leibniz Supercomputing Centre
// Description : Header file for PDUUnit class.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2018-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//================================================================================
26

Micha Mueller's avatar
Micha Mueller committed
27
28
#ifndef PDUUNIT_H_
#define PDUUNIT_H_
29

30
31
#include "../../includes/EntityInterface.h"

32
33
34
35
36
#include <tuple>
#include <vector>
#include <utility>
#include <string>

37
#include <boost/property_tree/ptree.hpp>
38
#include <openssl/ssl.h>
Micha Mueller's avatar
Micha Mueller committed
39

40
41
42
typedef std::vector<std::pair<std::string, std::string>> attributesVector_t;
typedef std::vector<std::tuple<std::string, std::string, attributesVector_t>> xmlPathVector_t;

43
44
45
46
47
/**
 * @brief Handles all connections to the same PDU unit.
 *
 * @ingroup pdu
 */
48
class PDUUnit : public EntityInterface {
49

50
public:
51
52
	PDUUnit(const std::string& name = "");
	PDUUnit(const PDUUnit& other);
53
	virtual ~PDUUnit();
54
	PDUUnit& operator=(const PDUUnit& other);
55

56
	void setHost(const std::string& host) {
57
58
		size_t pos = host.find(':');
		if (pos != std::string::npos) {
59
			_name = host;
60
		} else {
61
			_name = host + ":443";
62
		}
63
	}
64

65
	const std::string& getHost()                       { return _name; }
66

67
	/**
68
	 * Send the request to the host and write the response into response.
69
	 *
70
71
72
73
	 * @param request	String with the request to send
	 * @param response	String where the response will be stored
	 *
	 * @return	True on success, false otherwise
74
	 */
75
	bool sendRequest(const std::string& request, std::string& response);
76

77
	void execOnInit() final override;
Micha Mueller's avatar
Micha Mueller committed
78

79
private:
80
	SSL_CTX*	_ctx;
81
82
};

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