|
15 | 15 | #include "GenericConnectionHandler.h"
|
16 | 16 | #include "Arduino_ConnectionHandler.h"
|
17 | 17 |
|
18 |
| -static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter); |
| 18 | +/****************************************************************************** |
| 19 | + LOCAL MODULE FUNCTIONS |
| 20 | + ******************************************************************************/ |
| 21 | + |
| 22 | +static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter) { |
| 23 | + switch(adapter) { |
| 24 | + #if defined(BOARD_HAS_WIFI) |
| 25 | + case NetworkAdapter::WIFI: |
| 26 | + return new WiFiConnectionHandler(); |
| 27 | + break; |
| 28 | + #endif |
| 29 | + |
| 30 | + #if defined(BOARD_HAS_ETHERNET) |
| 31 | + case NetworkAdapter::ETHERNET: |
| 32 | + return new EthernetConnectionHandler(); |
| 33 | + break; |
| 34 | + #endif |
| 35 | + |
| 36 | + #if defined(BOARD_HAS_NB) |
| 37 | + case NetworkAdapter::NB: |
| 38 | + return new NBConnectionHandler(); |
| 39 | + break; |
| 40 | + #endif |
| 41 | + |
| 42 | + #if defined(BOARD_HAS_GSM) |
| 43 | + case NetworkAdapter::GSM: |
| 44 | + return new GSMConnectionHandler(); |
| 45 | + break; |
| 46 | + #endif |
| 47 | + |
| 48 | + #if defined(BOARD_HAS_CATM1_NBIOT) |
| 49 | + case NetworkAdapter::CATM1: |
| 50 | + return new CatM1ConnectionHandler(); |
| 51 | + break; |
| 52 | + #endif |
| 53 | + |
| 54 | + #if defined(BOARD_HAS_CELLULAR) |
| 55 | + case NetworkAdapter::CELL: |
| 56 | + return new CellularConnectionHandler(); |
| 57 | + break; |
| 58 | + #endif |
| 59 | + |
| 60 | + default: |
| 61 | + DEBUG_ERROR("Network adapter not supported by this platform: %d", adapter); |
| 62 | + return nullptr; |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +/****************************************************************************** |
| 67 | + PUBLIC MEMBER FUNCTIONS |
| 68 | + ******************************************************************************/ |
19 | 69 |
|
20 | 70 | bool GenericConnectionHandler::updateSetting(const models::NetworkSetting& s) {
|
21 | 71 | if(_ch != nullptr && _ch->_current_net_connection_state != NetworkConnectionState::INIT) {
|
@@ -54,30 +104,6 @@ void GenericConnectionHandler::getSetting(models::NetworkSetting& s) {
|
54 | 104 | }
|
55 | 105 | }
|
56 | 106 |
|
57 |
| -NetworkConnectionState GenericConnectionHandler::updateConnectionState() { |
58 |
| - return _ch != nullptr ? _ch->updateConnectionState() : NetworkConnectionState::INIT; |
59 |
| -} |
60 |
| - |
61 |
| -NetworkConnectionState GenericConnectionHandler::update_handleInit() { |
62 |
| - return _ch != nullptr ? _ch->update_handleInit() : NetworkConnectionState::INIT; |
63 |
| -} |
64 |
| - |
65 |
| -NetworkConnectionState GenericConnectionHandler::update_handleConnecting() { |
66 |
| - return _ch != nullptr ? _ch->update_handleConnecting() : NetworkConnectionState::INIT; |
67 |
| -} |
68 |
| - |
69 |
| -NetworkConnectionState GenericConnectionHandler::update_handleConnected() { |
70 |
| - return _ch != nullptr ? _ch->update_handleConnected() : NetworkConnectionState::INIT; |
71 |
| -} |
72 |
| - |
73 |
| -NetworkConnectionState GenericConnectionHandler::update_handleDisconnecting() { |
74 |
| - return _ch != nullptr ? _ch->update_handleDisconnecting() : NetworkConnectionState::INIT; |
75 |
| -} |
76 |
| - |
77 |
| -NetworkConnectionState GenericConnectionHandler::update_handleDisconnected() { |
78 |
| - return _ch != nullptr ? _ch->update_handleDisconnected() : NetworkConnectionState::INIT; |
79 |
| -} |
80 |
| - |
81 | 107 | #if not (defined(BOARD_HAS_LORA) or defined(BOARD_HAS_NOTECARD))
|
82 | 108 | unsigned long GenericConnectionHandler::getTime() {
|
83 | 109 | return _ch != nullptr ? _ch->getTime() : 0;
|
@@ -115,46 +141,30 @@ void GenericConnectionHandler::setKeepAlive(bool keep_alive) {
|
115 | 141 | }
|
116 | 142 | }
|
117 | 143 |
|
118 |
| -static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter) { |
119 |
| - switch(adapter) { |
120 |
| - #if defined(BOARD_HAS_WIFI) |
121 |
| - case NetworkAdapter::WIFI: |
122 |
| - return new WiFiConnectionHandler(); |
123 |
| - break; |
124 |
| - #endif |
| 144 | +/****************************************************************************** |
| 145 | + PROTECTED MEMBER FUNCTIONS |
| 146 | + ******************************************************************************/ |
125 | 147 |
|
126 |
| - #if defined(BOARD_HAS_ETHERNET) |
127 |
| - case NetworkAdapter::ETHERNET: |
128 |
| - return new EthernetConnectionHandler(); |
129 |
| - break; |
130 |
| - #endif |
| 148 | +NetworkConnectionState GenericConnectionHandler::updateConnectionState() { |
| 149 | + return _ch != nullptr ? _ch->updateConnectionState() : NetworkConnectionState::INIT; |
| 150 | +} |
131 | 151 |
|
132 |
| - #if defined(BOARD_HAS_NB) |
133 |
| - case NetworkAdapter::NB: |
134 |
| - return new NBConnectionHandler(); |
135 |
| - break; |
136 |
| - #endif |
| 152 | +NetworkConnectionState GenericConnectionHandler::update_handleInit() { |
| 153 | + return _ch != nullptr ? _ch->update_handleInit() : NetworkConnectionState::INIT; |
| 154 | +} |
137 | 155 |
|
138 |
| - #if defined(BOARD_HAS_GSM) |
139 |
| - case NetworkAdapter::GSM: |
140 |
| - return new GSMConnectionHandler(); |
141 |
| - break; |
142 |
| - #endif |
| 156 | +NetworkConnectionState GenericConnectionHandler::update_handleConnecting() { |
| 157 | + return _ch != nullptr ? _ch->update_handleConnecting() : NetworkConnectionState::INIT; |
| 158 | +} |
143 | 159 |
|
144 |
| - #if defined(BOARD_HAS_CATM1_NBIOT) |
145 |
| - case NetworkAdapter::CATM1: |
146 |
| - return new CatM1ConnectionHandler(); |
147 |
| - break; |
148 |
| - #endif |
| 160 | +NetworkConnectionState GenericConnectionHandler::update_handleConnected() { |
| 161 | + return _ch != nullptr ? _ch->update_handleConnected() : NetworkConnectionState::INIT; |
| 162 | +} |
149 | 163 |
|
150 |
| - #if defined(BOARD_HAS_CELLULAR) |
151 |
| - case NetworkAdapter::CELL: |
152 |
| - return new CellularConnectionHandler(); |
153 |
| - break; |
154 |
| - #endif |
| 164 | +NetworkConnectionState GenericConnectionHandler::update_handleDisconnecting() { |
| 165 | + return _ch != nullptr ? _ch->update_handleDisconnecting() : NetworkConnectionState::INIT; |
| 166 | +} |
155 | 167 |
|
156 |
| - default: |
157 |
| - DEBUG_ERROR("Network adapter not supported by this platform: %d", adapter); |
158 |
| - return nullptr; |
159 |
| - } |
| 168 | +NetworkConnectionState GenericConnectionHandler::update_handleDisconnected() { |
| 169 | + return _ch != nullptr ? _ch->update_handleDisconnected() : NetworkConnectionState::INIT; |
160 | 170 | }
|
0 commit comments