Skip to content

Commit b50af38

Browse files
defining a wrapper connection handler with the objective of being generic
1 parent 9832268 commit b50af38

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

src/GenericConnectionHandler.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
This file is part of ArduinoIoTCloud.
3+
Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
This software is released under the GNU General Public License version 3,
5+
which covers the main part of arduino-cli.
6+
The terms of this license can be found at:
7+
https://www.gnu.org/licenses/gpl-3.0.en.html
8+
You can be released from the requirements of the above licenses by purchasing
9+
a commercial license. Buying such a license is mandatory if you want to modify or
10+
otherwise use the software for commercial activities involving the Arduino
11+
software without disclosing the source code of your own applications. To purchase
12+
a commercial license, send an email to [email protected].
13+
*/
14+
15+
/******************************************************************************
16+
INCLUDE
17+
******************************************************************************/
18+
19+
#include "Arduino_ConnectionHandler.h"
20+
#include "GenericConnectionHandler.h"
21+
22+
void GenericConnectionHandler::updateSetting(const models::NetworkSetting& s) {
23+
24+
switch(s.type) {
25+
#if defined(BOARD_HAS_WIFI)
26+
case WIFI:
27+
_ch = new WiFiConnectionHandler();
28+
break;
29+
#endif
30+
31+
#if defined(BOARD_HAS_ETHERNET)
32+
case ETHERNET:
33+
_ch = new EthernetConnectionHandler();
34+
break;
35+
#endif
36+
37+
#if defined(BOARD_HAS_NB)
38+
case NB:
39+
_ch = new NBConnectionHandler();
40+
break;
41+
#endif
42+
43+
#if defined(BOARD_HAS_GSM)
44+
case GSM:
45+
_ch = new GSMConnectionHandler();
46+
break;
47+
#endif
48+
49+
#if defined(BOARD_HAS_CATM1_NBIOT)
50+
case CATM1:
51+
_ch = new CatM1ConnectionHandler();
52+
break;
53+
#endif
54+
55+
#if defined(BOARD_HAS_CELLULAR)
56+
case CELL:
57+
_ch = new CellularConnectionHandler();
58+
break;
59+
#endif
60+
61+
#if defined(BOARD_HAS_NOTECARD) // FIXME understand how to adapt it to the settings structure
62+
case NOTECARD:
63+
_ch = new NotecardConnectionHandler();
64+
break;
65+
#endif
66+
67+
default:
68+
Debug.print(DBG_ERROR, "Network adapter not supported by this platform: %d", s.type);
69+
return;
70+
}
71+
_ch->updateSetting(s);
72+
}
73+
74+
NetworkConnectionState GenericConnectionHandler::update_handleInit() {
75+
return _ch != nullptr ? _ch->update_handleInit() : INIT;
76+
}
77+
78+
NetworkConnectionState GenericConnectionHandler::update_handleDisconnecting() {
79+
return _ch != nullptr ? _ch->update_handleDisconnecting() : INIT;
80+
}
81+
82+
83+
NetworkConnectionState GenericConnectionHandler::update_handleConnected() {
84+
return _ch != nullptr ? _ch->update_handleConnected() : INIT;
85+
}
86+
87+
NetworkConnectionState GenericConnectionHandler::update_handleDisconnecting() {
88+
return _ch != nullptr ? _ch->update_handleDisconnecting() : INIT;
89+
}
90+
91+
NetworkConnectionState GenericConnectionHandler::update_handleDisconnected() {
92+
return _ch != nullptr ? _ch->update_handleDisconnected() : INIT;
93+
}

src/GenericConnectionHandler.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
This file is part of ArduinoIoTCloud.
3+
4+
Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
5+
6+
This software is released under the GNU General Public License version 3,
7+
which covers the main part of arduino-cli.
8+
The terms of this license can be found at:
9+
https://www.gnu.org/licenses/gpl-3.0.en.html
10+
11+
You can be released from the requirements of the above licenses by purchasing
12+
a commercial license. Buying such a license is mandatory if you want to modify or
13+
otherwise use the software for commercial activities involving the Arduino
14+
software without disclosing the source code of your own applications. To purchase
15+
a commercial license, send an email to [email protected].
16+
*/
17+
18+
#ifndef ARDUINO_WIFI_CONNECTION_HANDLER_H_
19+
#define ARDUINO_WIFI_CONNECTION_HANDLER_H_
20+
21+
/******************************************************************************
22+
INCLUDE
23+
******************************************************************************/
24+
25+
#include "ConnectionHandlerInterface.h"
26+
27+
/******************************************************************************
28+
CLASS DECLARATION
29+
******************************************************************************/
30+
31+
/** GenericConnectionHandler class
32+
* This class aims to wrap a connectionHandler and provide a generic way to
33+
* instantiate a specific connectionHandler type
34+
*/
35+
class GenericConnectionHandler : public ConnectionHandler
36+
{
37+
public:
38+
39+
GenericConnectionHandler(): _ch(nullptr) {}
40+
41+
virtual unsigned long getTime() override;
42+
virtual Client & getClient() override;
43+
virtual UDP & getUDP() override;
44+
45+
virtual void updateSetting(const models::NetworkSetting& s) override;
46+
47+
protected:
48+
49+
virtual NetworkConnectionState update_handleInit () override;
50+
virtual NetworkConnectionState update_handleConnecting () override;
51+
virtual NetworkConnectionState update_handleConnected () override;
52+
virtual NetworkConnectionState update_handleDisconnecting() override;
53+
virtual NetworkConnectionState update_handleDisconnected () override;
54+
55+
private:
56+
57+
ConnectionHandler* _ch;
58+
};
59+
60+
#endif /* ARDUINO_WIFI_CONNECTION_HANDLER_H_ */

0 commit comments

Comments
 (0)