supla-device
Loading...
Searching...
No Matches
client.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_NETWORK_CLIENT_H_
20#define SRC_SUPLA_NETWORK_CLIENT_H_
21
22#include <stddef.h>
23#include <stdint.h>
24
25#include "ip_address.h"
26
28
29namespace Supla {
30
31class Client {
32 public:
33 Client();
34 virtual ~Client();
35
36 virtual int available() = 0;
37 virtual void stop() = 0;
38 virtual uint8_t connected() = 0;
39 virtual void setTimeoutMs(uint16_t timeoutMs) = 0;
40
41 int connect(IPAddress ip, uint16_t port);
42 int connect(const char *host, uint16_t port);
43 size_t write(uint8_t);
44 size_t write(const uint8_t *buf, size_t size);
45 size_t write(const void *buf, size_t size = 0);
46
47 size_t print(const char *);
48 size_t println(const char *);
49 size_t println();
50
51 int read();
52 int read(uint8_t *buf, size_t size);
53 int read(char *buf, size_t size);
54
55 // SSL configuration
56 virtual void setSSLEnabled(bool enabled);
57 void setCACert(const char *rootCA);
58
59 void setDebugLogs(bool);
60 bool isDebugLogs() const;
61 void setSdc(SuplaDeviceClass *sdc);
62
63 uint32_t getSrcConnectionIPAddress() const;
64
65 protected:
66 virtual int connectImp(const char *host, uint16_t port) = 0;
67 virtual size_t writeImp(const uint8_t *buf, size_t size) = 0;
68 virtual int readImp(uint8_t *buf, size_t size) = 0;
69
70 bool sslEnabled = false;
71 bool debugLogs = false;
72 const char *rootCACert = nullptr;
73 unsigned int rootCACertSize = 0;
74 SuplaDeviceClass *sdc = nullptr;
75 uint32_t srcIp = 0;
76};
77
78extern Client *ClientBuilder();
79}; // namespace Supla
80
81#endif // SRC_SUPLA_NETWORK_CLIENT_H_
Definition ip_address.h:30
Definition SuplaDevice.h:93
Definition client.h:31