Skip to content

Commit eef2674

Browse files
fixup! defining a wrapper connection handler with the objective of being generic
1 parent a9fa945 commit eef2674

File tree

2 files changed

+64
-51
lines changed

2 files changed

+64
-51
lines changed

src/GenericConnectionHandler.cpp

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,77 +16,90 @@
1616
INCLUDE
1717
******************************************************************************/
1818

19-
#include "Arduino_ConnectionHandler.h"
2019
#include "GenericConnectionHandler.h"
20+
#include "Arduino_ConnectionHandler.h"
2121

2222
void GenericConnectionHandler::updateSetting(const models::NetworkSetting& s) {
2323

2424
switch(s.type) {
25-
#if defined(BOARD_HAS_WIFI)
26-
case WIFI:
27-
_ch = new WiFiConnectionHandler();
28-
break;
29-
#endif
25+
// #if defined(BOARD_HAS_WIFI)
26+
// case NetworkAdapter::WIFI:
27+
// _ch = new WiFiConnectionHandler();
28+
// break;
29+
// #endif
3030

3131
#if defined(BOARD_HAS_ETHERNET)
32-
case ETHERNET:
32+
case NetworkAdapter::ETHERNET:
3333
_ch = new EthernetConnectionHandler();
3434
break;
3535
#endif
3636

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
37+
// #if defined(BOARD_HAS_NB)
38+
// case NetworkAdapter::NB:
39+
// _ch = new NBConnectionHandler();
40+
// break;
41+
// #endif
42+
43+
// #if defined(BOARD_HAS_GSM)
44+
// case NetworkAdapter::GSM:
45+
// _ch = new GSMConnectionHandler();
46+
// break;
47+
// #endif
48+
49+
// #if defined(BOARD_HAS_CATM1_NBIOT)
50+
// case NetworkAdapter::CATM1:
51+
// _ch = new CatM1ConnectionHandler();
52+
// break;
53+
// #endif
54+
55+
// #if defined(BOARD_HAS_CELLULAR)
56+
// case NetworkAdapter::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
6666

6767
default:
6868
Debug.print(DBG_ERROR, "Network adapter not supported by this platform: %d", s.type);
6969
return;
7070
}
71+
_interface = s.type;
7172
_ch->updateSetting(s);
7273
}
7374

7475
NetworkConnectionState GenericConnectionHandler::update_handleInit() {
75-
return _ch != nullptr ? _ch->update_handleInit() : INIT;
76+
return _ch != nullptr ? _ch->update_handleInit() : NetworkConnectionState::INIT;
7677
}
7778

78-
NetworkConnectionState GenericConnectionHandler::update_handleDisconnecting() {
79-
return _ch != nullptr ? _ch->update_handleDisconnecting() : INIT;
79+
NetworkConnectionState GenericConnectionHandler::update_handleConnecting() {
80+
return _ch != nullptr ? _ch->update_handleConnecting() : NetworkConnectionState::INIT;
8081
}
8182

8283
NetworkConnectionState GenericConnectionHandler::update_handleConnected() {
83-
return _ch != nullptr ? _ch->update_handleConnected() : INIT;
84+
return _ch != nullptr ? _ch->update_handleConnected() : NetworkConnectionState::INIT;
8485
}
8586

8687
NetworkConnectionState GenericConnectionHandler::update_handleDisconnecting() {
87-
return _ch != nullptr ? _ch->update_handleDisconnecting() : INIT;
88+
return _ch != nullptr ? _ch->update_handleDisconnecting() : NetworkConnectionState::INIT;
8889
}
8990

9091
NetworkConnectionState GenericConnectionHandler::update_handleDisconnected() {
91-
return _ch != nullptr ? _ch->update_handleDisconnected() : INIT;
92+
return _ch != nullptr ? _ch->update_handleDisconnected() : NetworkConnectionState::INIT;
93+
}
94+
95+
unsigned long GenericConnectionHandler::getTime() { // FIXME _ch may be nullptr
96+
return _ch->getTime();
97+
}
98+
99+
Client & GenericConnectionHandler::getClient() { // FIXME _ch may be nullptr
100+
return _ch->getClient();
101+
}
102+
103+
UDP & GenericConnectionHandler::getUDP() { // FIXME _ch may be nullptr
104+
return _ch->getUDP();
92105
}

src/GenericConnectionHandler.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ class GenericConnectionHandler : public ConnectionHandler
3838

3939
GenericConnectionHandler(): _ch(nullptr) {}
4040

41-
virtual unsigned long getTime() override;
42-
virtual Client & getClient() override;
43-
virtual UDP & getUDP() override;
41+
unsigned long getTime() override;
42+
Client & getClient() override;
43+
UDP & getUDP() override;
4444

45-
virtual void updateSetting(const models::NetworkSetting& s) override;
45+
void updateSetting(const models::NetworkSetting& s) override;
4646

4747
protected:
4848

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;
49+
NetworkConnectionState update_handleInit () override;
50+
NetworkConnectionState update_handleConnecting () override;
51+
NetworkConnectionState update_handleConnected () override;
52+
NetworkConnectionState update_handleDisconnecting() override;
53+
NetworkConnectionState update_handleDisconnected () override;
5454

5555
private:
5656

0 commit comments

Comments
 (0)