30
30
31
31
#include < ModemInterface.h>
32
32
#include < TimeUtils.h>
33
+ #include " ManagedTinyGsmClient.h"
33
34
34
35
/* *
35
36
* @enum ModemModel
@@ -100,6 +101,20 @@ class ArduinoCellular {
100
101
*/
101
102
ArduinoCellular ();
102
103
104
+ /* *
105
+ * @brief Destructor for the ArduinoCellular class.
106
+ * Cleans up any resources used by the class.
107
+ */
108
+ ~ArduinoCellular ();
109
+
110
+ // Delete copy operations (since unique_ptr can't be copied)
111
+ ArduinoCellular (const ArduinoCellular&) = delete ;
112
+ ArduinoCellular& operator =(const ArduinoCellular&) = delete ;
113
+
114
+ // Enable move operations
115
+ ArduinoCellular (ArduinoCellular&&) = default ;
116
+ ArduinoCellular& operator =(ArduinoCellular&&) = default ;
117
+
103
118
/* *
104
119
* @brief Initializes the modem.
105
120
* This function must be called before using any other functions in the library.
@@ -238,6 +253,7 @@ class ArduinoCellular {
238
253
/* *
239
254
* @brief Gets a HTTP client for the specified server and port.
240
255
* The maximum number of HTTP clients is limited by the number of sockets available.
256
+ * Call `cleanup()` to release the resources used by the clients once you are done with them.
241
257
* @param server The server address.
242
258
* @param port The server port.
243
259
* @return The HTTP client.
@@ -247,12 +263,26 @@ class ArduinoCellular {
247
263
/* *
248
264
* @brief Gets a HTTPS client for the specified server and port.
249
265
* The maximum number of HTTP clients is limited by the number of sockets available.
266
+ * Call `cleanup()` to release the resources used by the clients once you are done with them.
250
267
* @param server The server address.
251
268
* @param port The server port.
252
269
* @return The HTTPS client.
253
270
*/
254
271
HttpClient getHTTPSClient (const char * server, const int port);
255
272
273
+ /* *
274
+ * @brief Cleans up the clients and releases the resources used by them.
275
+ * It's necessary to call this function to free up the memory used by the client
276
+ * objects that are created by the library internally.
277
+ */
278
+ void cleanup ();
279
+
280
+ /* *
281
+ * @brief Gets the number of managed clients.
282
+ * The clients are managed in the sense of memory management.
283
+ */
284
+ size_t getManagedClientCount () const ;
285
+
256
286
/* *
257
287
* @brief Gets the local IP address.
258
288
* @return The local IP address.
@@ -282,6 +312,10 @@ class ArduinoCellular {
282
312
SimStatus getSimStatus ();
283
313
284
314
private:
315
+ // Each instance manages its own connections
316
+ std::vector<std::unique_ptr<ManagedTinyGsmClient>> managedGsmClients;
317
+ std::vector<std::unique_ptr<BearSSLClient>> managedSslClients;
318
+
285
319
bool connectToGPRS (const char * apn, const char * gprsUser, const char * gprsPass);
286
320
287
321
0 commit comments