forked from BeeeOn/gateway-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTTP.h
60 lines (45 loc) · 1.46 KB
/
HTTP.h
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @file HTTP.h
* @Author Lukas Koszegy ([email protected])
* @date November, 2015
* @brief Class for support communucation via HTTP
*/
#ifndef HTTP_H
#define HTTP_H
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <Poco/AutoPtr.h>
#include <Poco/Exception.h>
#include <Poco/Logger.h>
#include <Poco/SharedPtr.h>
#include <Poco/Net/IPAddress.h>
#include <Poco/Net/NetworkInterface.h>
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
/**
* Class represent devices, which have output in json format
*/
class HTTPClient {
public:
HTTPClient(uint16_t _port = 80);
std::vector<std::string> discoverDevices();
std::string findAdapterIP(std::string ip_address);
std::string sendRequest(std::string ip, std::string url = "/values.json");
private:
Poco::Net::HTTPClientSession http;
Poco::Net::HTTPResponse response;
Poco::Net::HTTPRequest request;
Poco::Logger& log;
Poco::Timespan receiveTime;
uint16_t port;
void checkIPAddresses(Poco::Net::NetworkInterface::AddressList &iplist,
std::vector<std::pair<uint32_t, Poco::Net::IPAddress>> &networks);
std::vector<std::string> detectNetworkDevices(std::vector<std::pair<uint32_t, Poco::Net::IPAddress>>);
std::vector<std::pair<uint32_t, Poco::Net::IPAddress>> detectNetworkInterfaces();
bool isFromSubnet(Poco::Net::IPAddress &network_ip, Poco::Net::IPAddress &mask,
Poco::Net::IPAddress target_ip);
};
#endif