@@ -8,15 +8,24 @@ class NetworkClient : public Client
88 protected:
99
1010 Client * _client; // Ethernet or WiFi client
11+ bool _friendClass;
1112 uint8_t _networkType;
1213
1314 public:
1415
1516 // ------------------------------
1617 // Create the network client
1718 // ------------------------------
19+ NetworkClient (Client * client, uint8_t networkType)
20+ {
21+ _friendClass = true ;
22+ _networkType = networkType;
23+ _client = client;
24+ }
25+
1826 NetworkClient (uint8_t user)
1927 {
28+ _friendClass = false ;
2029 _networkType = networkGetType (user);
2130#if defined(COMPILE_ETHERNET)
2231 if (_networkType == NETWORK_TYPE_ETHERNET)
@@ -38,7 +47,8 @@ class NetworkClient : public Client
3847 if (_client)
3948 {
4049 _client->stop ();
41- delete _client;
50+ if (!_friendClass)
51+ delete _client;
4252 _client = nullptr ;
4353 }
4454 };
@@ -221,6 +231,57 @@ class NetworkClient : public Client
221231 {
222232 return Client::rawIPAddress (addr);
223233 }
234+
235+ // ------------------------------
236+ // Declare the friend classes
237+ // ------------------------------
238+
239+ friend class NetworkEthernetClient ;
240+ friend class NetworkWiFiClient ;
241+ };
242+
243+ #ifdef COMPILE_ETHERNET
244+ class NetworkEthernetClient : public NetworkClient
245+ {
246+ private:
247+
248+ EthernetClient _client;
249+
250+ public:
251+
252+ NetworkEthernetClient (EthernetClient& client) :
253+ _client{client},
254+ NetworkClient (&_client, NETWORK_TYPE_ETHERNET)
255+ {
256+ }
257+
258+ ~NetworkEthernetClient ()
259+ {
260+ this ->~NetworkClient ();
261+ }
262+ };
263+ #endif // COMPILE_ETHERNET
264+
265+ #ifdef COMPILE_WIFI
266+ class NetworkWiFiClient : public NetworkClient
267+ {
268+ private:
269+
270+ WiFiClient _client;
271+
272+ public:
273+
274+ NetworkWiFiClient (WiFiClient& client) :
275+ _client{client},
276+ NetworkClient (&_client, NETWORK_TYPE_WIFI)
277+ {
278+ }
279+
280+ ~NetworkWiFiClient ()
281+ {
282+ this ->~NetworkClient ();
283+ }
224284};
285+ #endif // COMPILE_WIFI
225286
226287#endif // __NETWORK_CLIENT_H__
0 commit comments