diff --git a/src/GenericConnectionHandler.cpp b/src/GenericConnectionHandler.cpp index a607681..0cc7ca2 100644 --- a/src/GenericConnectionHandler.cpp +++ b/src/GenericConnectionHandler.cpp @@ -15,7 +15,57 @@ #include "GenericConnectionHandler.h" #include "Arduino_ConnectionHandler.h" -static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter); +/****************************************************************************** + LOCAL MODULE FUNCTIONS + ******************************************************************************/ + +static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter) { + switch(adapter) { + #if defined(BOARD_HAS_WIFI) + case NetworkAdapter::WIFI: + return new WiFiConnectionHandler(); + break; + #endif + + #if defined(BOARD_HAS_ETHERNET) + case NetworkAdapter::ETHERNET: + return new EthernetConnectionHandler(); + break; + #endif + + #if defined(BOARD_HAS_NB) + case NetworkAdapter::NB: + return new NBConnectionHandler(); + break; + #endif + + #if defined(BOARD_HAS_GSM) + case NetworkAdapter::GSM: + return new GSMConnectionHandler(); + break; + #endif + + #if defined(BOARD_HAS_CATM1_NBIOT) + case NetworkAdapter::CATM1: + return new CatM1ConnectionHandler(); + break; + #endif + + #if defined(BOARD_HAS_CELLULAR) + case NetworkAdapter::CELL: + return new CellularConnectionHandler(); + break; + #endif + + default: + DEBUG_ERROR("Network adapter not supported by this platform: %d", adapter); + return nullptr; + } +} + +/****************************************************************************** + PUBLIC MEMBER FUNCTIONS + ******************************************************************************/ bool GenericConnectionHandler::updateSetting(const models::NetworkSetting& s) { if(_ch != nullptr && _ch->_current_net_connection_state != NetworkConnectionState::INIT) { @@ -54,30 +104,6 @@ void GenericConnectionHandler::getSetting(models::NetworkSetting& s) { } } -NetworkConnectionState GenericConnectionHandler::updateConnectionState() { - return _ch != nullptr ? _ch->updateConnectionState() : NetworkConnectionState::INIT; -} - -NetworkConnectionState GenericConnectionHandler::update_handleInit() { - return _ch != nullptr ? _ch->update_handleInit() : NetworkConnectionState::INIT; -} - -NetworkConnectionState GenericConnectionHandler::update_handleConnecting() { - return _ch != nullptr ? _ch->update_handleConnecting() : NetworkConnectionState::INIT; -} - -NetworkConnectionState GenericConnectionHandler::update_handleConnected() { - return _ch != nullptr ? _ch->update_handleConnected() : NetworkConnectionState::INIT; -} - -NetworkConnectionState GenericConnectionHandler::update_handleDisconnecting() { - return _ch != nullptr ? _ch->update_handleDisconnecting() : NetworkConnectionState::INIT; -} - -NetworkConnectionState GenericConnectionHandler::update_handleDisconnected() { - return _ch != nullptr ? _ch->update_handleDisconnected() : NetworkConnectionState::INIT; -} - #if not (defined(BOARD_HAS_LORA) or defined(BOARD_HAS_NOTECARD)) unsigned long GenericConnectionHandler::getTime() { return _ch != nullptr ? _ch->getTime() : 0; @@ -115,46 +141,30 @@ void GenericConnectionHandler::setKeepAlive(bool keep_alive) { } } -static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter) { - switch(adapter) { - #if defined(BOARD_HAS_WIFI) - case NetworkAdapter::WIFI: - return new WiFiConnectionHandler(); - break; - #endif +/****************************************************************************** + PROTECTED MEMBER FUNCTIONS + ******************************************************************************/ - #if defined(BOARD_HAS_ETHERNET) - case NetworkAdapter::ETHERNET: - return new EthernetConnectionHandler(); - break; - #endif +NetworkConnectionState GenericConnectionHandler::updateConnectionState() { + return _ch != nullptr ? _ch->updateConnectionState() : NetworkConnectionState::INIT; +} - #if defined(BOARD_HAS_NB) - case NetworkAdapter::NB: - return new NBConnectionHandler(); - break; - #endif +NetworkConnectionState GenericConnectionHandler::update_handleInit() { + return _ch != nullptr ? _ch->update_handleInit() : NetworkConnectionState::INIT; +} - #if defined(BOARD_HAS_GSM) - case NetworkAdapter::GSM: - return new GSMConnectionHandler(); - break; - #endif +NetworkConnectionState GenericConnectionHandler::update_handleConnecting() { + return _ch != nullptr ? _ch->update_handleConnecting() : NetworkConnectionState::INIT; +} - #if defined(BOARD_HAS_CATM1_NBIOT) - case NetworkAdapter::CATM1: - return new CatM1ConnectionHandler(); - break; - #endif +NetworkConnectionState GenericConnectionHandler::update_handleConnected() { + return _ch != nullptr ? _ch->update_handleConnected() : NetworkConnectionState::INIT; +} - #if defined(BOARD_HAS_CELLULAR) - case NetworkAdapter::CELL: - return new CellularConnectionHandler(); - break; - #endif +NetworkConnectionState GenericConnectionHandler::update_handleDisconnecting() { + return _ch != nullptr ? _ch->update_handleDisconnecting() : NetworkConnectionState::INIT; +} - default: - DEBUG_ERROR("Network adapter not supported by this platform: %d", adapter); - return nullptr; - } +NetworkConnectionState GenericConnectionHandler::update_handleDisconnected() { + return _ch != nullptr ? _ch->update_handleDisconnected() : NetworkConnectionState::INIT; }