Skip to content

Commit 93a7b3c

Browse files
committed
Function 'check()' directly returns the NetworkConnectionState which eliminates the need to query the member variable NetConnectionStatus via 'getStatus()'
1 parent 8ec88e0 commit 93a7b3c

11 files changed

+27
-19
lines changed

src/Arduino_ConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ typedef void (*OnNetworkEventCallback)(void * /* arg */);
137137
class ConnectionHandler {
138138
public:
139139
virtual void init() = 0;
140-
virtual void check() = 0;
140+
virtual NetworkConnectionState check() = 0;
141141

142142
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB)
143143
virtual unsigned long getTime() = 0;

src/Arduino_GSMConnectionHandler.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ unsigned long GSMConnectionHandler::getTime() {
7171
return gsmAccess.getTime();
7272
}
7373

74-
void GSMConnectionHandler::check() {
74+
NetworkConnectionState GSMConnectionHandler::check() {
7575
unsigned long const now = millis();
7676
int gsmAccessAlive;
7777
if (now - lastConnectionTickTime > connectionTickTimeInterval) {
@@ -89,7 +89,7 @@ void GSMConnectionHandler::check() {
8989
if (networkStatus == GSM3_NetworkStatus_t::ERROR) {
9090
// NO FURTHER ACTION WILL FOLLOW THIS
9191
changeConnectionState(NetworkConnectionState::ERROR);
92-
return;
92+
return netConnectionState;
9393
}
9494
Debug.print(DBG_INFO, "Sending PING to outer space...");
9595
int pingResult;
@@ -98,11 +98,11 @@ void GSMConnectionHandler::check() {
9898
if (pingResult < 0) {
9999
Debug.print(DBG_ERROR, "PING failed");
100100
Debug.print(DBG_INFO, "Retrying in \"%d\" milliseconds", connectionTickTimeInterval);
101-
return;
101+
return netConnectionState;
102102
} else {
103103
Debug.print(DBG_INFO, "Connected to GPRS Network");
104104
changeConnectionState(NetworkConnectionState::CONNECTED);
105-
return;
105+
return netConnectionState;
106106
}
107107
}
108108
break;
@@ -111,7 +111,7 @@ void GSMConnectionHandler::check() {
111111
Debug.print(DBG_VERBOSE, "GPRS.isAccessAlive(): %d", gsmAccessAlive);
112112
if (gsmAccessAlive != 1) {
113113
changeConnectionState(NetworkConnectionState::DISCONNECTED);
114-
return;
114+
return netConnectionState;
115115
}
116116
Debug.print(DBG_VERBOSE, "Connected to Cellular Network");
117117
}
@@ -130,6 +130,8 @@ void GSMConnectionHandler::check() {
130130
}
131131
lastConnectionTickTime = now;
132132
}
133+
134+
return netConnectionState;
133135
}
134136

135137
/******************************************************************************

src/Arduino_GSMConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class GSMConnectionHandler : public TcpIpConnectionHandler {
3737

3838
virtual void init();
3939
virtual unsigned long getTime();
40-
virtual void check();
40+
virtual NetworkConnectionState check();
4141
virtual Client &getClient() {
4242
return networkClient;
4343
};

src/Arduino_LPWANConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class LPWANConnectionHandler : public ConnectionHandler {
3333
public:
3434
virtual void init() = 0;
35-
virtual void check();
35+
virtual NetworkConnectionState check();
3636
virtual unsigned long getTime() = 0;
3737

3838
virtual int write(const uint8_t *buf, size_t size) = 0;

src/Arduino_LoRaConnectionHandler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ bool LoRaConnectionHandler::available() {
104104
return modem.available();
105105
}
106106

107-
void LoRaConnectionHandler::check() {
107+
NetworkConnectionState LoRaConnectionHandler::check() {
108108

109109
unsigned long const now = millis();
110110
int networkStatus = 0;
@@ -121,6 +121,8 @@ void LoRaConnectionHandler::check() {
121121
case NetworkConnectionState::CLOSED: break;
122122
}
123123
}
124+
125+
return netConnectionState;
124126
}
125127

126128
/******************************************************************************

src/Arduino_LoRaConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class LoRaConnectionHandler : public LPWANConnectionHandler {
4646

4747
void init();
4848
unsigned long getTime();
49-
void check();
49+
NetworkConnectionState check();
5050

5151
int write(const uint8_t *buf, size_t size);
5252
int read();

src/Arduino_NBConnectionHandler.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ unsigned long NBConnectionHandler::getTime() {
7878
return nbAccess.getTime();
7979
}
8080

81-
void NBConnectionHandler::check() {
81+
NetworkConnectionState NBConnectionHandler::check() {
8282
unsigned long const now = millis();
8383
int nbAccessAlive;
8484
if (now - lastConnectionTickTime > connectionTickTimeInterval) {
@@ -96,7 +96,7 @@ void NBConnectionHandler::check() {
9696
if (networkStatus == NB_NetworkStatus_t::ERROR) {
9797
// NO FURTHER ACTION WILL FOLLOW THIS
9898
changeConnectionState(NetworkConnectionState::ERROR);
99-
return;
99+
return netConnectionState;
100100
}
101101
Debug.print(DBG_INFO, "Sending PING to outer space...");
102102
int pingResult;
@@ -106,11 +106,11 @@ void NBConnectionHandler::check() {
106106
if (pingResult < 0) {
107107
Debug.print(DBG_ERROR, "PING failed");
108108
Debug.print(DBG_INFO, "Retrying in \"%d\" milliseconds", connectionTickTimeInterval);
109-
return;
109+
return netConnectionState;
110110
} else {
111111
Debug.print(DBG_INFO, "Connected to GPRS Network");
112112
changeConnectionState(NetworkConnectionState::CONNECTED);
113-
return;
113+
return netConnectionState;
114114
}
115115
}
116116
break;
@@ -119,7 +119,7 @@ void NBConnectionHandler::check() {
119119
Debug.print(DBG_VERBOSE, "GPRS.isAccessAlive(): %d", nbAccessAlive);
120120
if (nbAccessAlive != 1) {
121121
changeConnectionState(NetworkConnectionState::DISCONNECTED);
122-
return;
122+
return netConnectionState;
123123
}
124124
Debug.print(DBG_VERBOSE, "Connected to Cellular Network");
125125
}
@@ -138,6 +138,8 @@ void NBConnectionHandler::check() {
138138
}
139139
lastConnectionTickTime = now;
140140
}
141+
142+
return netConnectionState;
141143
}
142144

143145
/******************************************************************************

src/Arduino_NBConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class NBConnectionHandler : public TcpIpConnectionHandler {
3838

3939
virtual void init();
4040
virtual unsigned long getTime();
41-
virtual void check();
41+
virtual NetworkConnectionState check();
4242
virtual Client &getClient() {
4343
return networkClient;
4444
};

src/Arduino_TcpIpConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
class TcpIpConnectionHandler : public ConnectionHandler {
3636
public:
3737
virtual void init() = 0;
38-
virtual void check() = 0;
38+
virtual NetworkConnectionState check() = 0;
3939
virtual unsigned long getTime() = 0;
4040
virtual Client &getClient() = 0;
4141
virtual UDP &getUDP() = 0;

src/Arduino_WiFiConnectionHandler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ unsigned long WiFiConnectionHandler::getTime() {
5050
#endif
5151
}
5252

53-
void WiFiConnectionHandler::check() {
53+
NetworkConnectionState WiFiConnectionHandler::check() {
5454

5555
unsigned long const now = millis();
5656
if((now - lastConnectionTickTime) > connectionTickTimeInterval)
@@ -68,6 +68,8 @@ void WiFiConnectionHandler::check() {
6868
case NetworkConnectionState::CLOSED: break;
6969
}
7070
}
71+
72+
return netConnectionState;
7173
}
7274

7375
/******************************************************************************

src/Arduino_WiFiConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class WiFiConnectionHandler : public TcpIpConnectionHandler {
3636

3737
virtual void init();
3838
virtual unsigned long getTime();
39-
virtual void check();
39+
virtual NetworkConnectionState check();
4040
virtual Client &getClient() {
4141
return wifiClient;
4242
};

0 commit comments

Comments
 (0)