forked from andreagilardoni/Arduino_ConnectionHandler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericConnectionHandler.h
More file actions
74 lines (55 loc) · 2.54 KB
/
GenericConnectionHandler.h
File metadata and controls
74 lines (55 loc) · 2.54 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
This file is part of the Arduino_ConnectionHandler library.
Copyright (c) 2024 Arduino SA
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef ARDUINO_GENERIC_CONNECTION_HANDLER_H_
#define ARDUINO_GENERIC_CONNECTION_HANDLER_H_
/******************************************************************************
INCLUDE
******************************************************************************/
#include "ConnectionHandlerInterface.h"
/******************************************************************************
CLASS DECLARATION
******************************************************************************/
/** GenericConnectionHandler class
* This class aims to wrap a connectionHandler and provide a generic way to
* instantiate a specific connectionHandler type
*/
class GenericConnectionHandler : public ConnectionHandler
{
public:
GenericConnectionHandler(bool const keep_alive=true): ConnectionHandler(keep_alive), _ch(nullptr) {}
#if defined(BOARD_HAS_NOTECARD) || defined(BOARD_HAS_LORA)
virtual bool available() = 0;
virtual int read() = 0;
virtual int write(const uint8_t *buf, size_t size) = 0;
#else
unsigned long getTime() override;
/*
* NOTE: The following functions have a huge risk of returning a reference to a non existing memory location
* It is important to make sure that the internal connection handler is already allocated before calling them
* When updateSettings is called and the internal connectionHandler is reallocated the references to TCP and UDP
* handles should be deleted.
*/
Client & getClient() override;
UDP & getUDP() override;
#endif
bool updateSetting(const models::NetworkSetting& s) override;
void getSetting(models::NetworkSetting& s) override;
void connect() override;
void disconnect() override;
void setKeepAlive(bool keep_alive=true) override;
protected:
NetworkConnectionState updateConnectionState() override;
NetworkConnectionState update_handleInit () override;
NetworkConnectionState update_handleConnecting () override;
NetworkConnectionState update_handleConnected () override;
NetworkConnectionState update_handleDisconnecting() override;
NetworkConnectionState update_handleDisconnected () override;
private:
ConnectionHandler* _ch;
};
#endif /* ARDUINO_GENERIC_CONNECTION_HANDLER_H_ */