16
16
17
17
#include < Arduino.h>
18
18
#include < vector>
19
+ #include < memory>
19
20
20
21
#if defined __has_include
21
22
#if !__has_include (<ArduinoIoTCloud.h>)
30
31
31
32
#include < ModemInterface.h>
32
33
#include < TimeUtils.h>
34
+ #include " ManagedTinyGsmClient.h"
33
35
34
36
/* *
35
37
* @enum ModemModel
@@ -100,6 +102,36 @@ class ArduinoCellular {
100
102
*/
101
103
ArduinoCellular ();
102
104
105
+ /* *
106
+ * @brief Destructor for the ArduinoCellular class.
107
+ * Cleans up any resources used by the class.
108
+ */
109
+ ~ArduinoCellular ();
110
+
111
+ /* *
112
+ * @brief Deleted copy constructor and assignment operator to prevent copying.
113
+ * unique_ptr is used to manage the lifetime of the clients but they cannot be copied.
114
+ */
115
+ ArduinoCellular (const ArduinoCellular&) = delete ;
116
+
117
+ /* *
118
+ * @brief Deleted assignment operator to prevent copying.
119
+ * unique_ptr is used to manage the lifetime of the clients but they cannot be copied.
120
+ */
121
+ ArduinoCellular& operator =(const ArduinoCellular&) = delete ;
122
+
123
+ /* *
124
+ * @brief Move constructor for the ArduinoCellular class.
125
+ * Allows moving the instance to another instance.
126
+ */
127
+ ArduinoCellular (ArduinoCellular&&) = default ;
128
+
129
+ /* *
130
+ * @brief Move assignment operator for the ArduinoCellular class.
131
+ * Allows moving the instance to another instance.
132
+ */
133
+ ArduinoCellular& operator =(ArduinoCellular&&) = default ;
134
+
103
135
/* *
104
136
* @brief Initializes the modem.
105
137
* This function must be called before using any other functions in the library.
@@ -238,6 +270,7 @@ class ArduinoCellular {
238
270
/* *
239
271
* @brief Gets a HTTP client for the specified server and port.
240
272
* The maximum number of HTTP clients is limited by the number of sockets available.
273
+ * Call `cleanup()` to release the resources used by the clients once you are done with them.
241
274
* @param server The server address.
242
275
* @param port The server port.
243
276
* @return The HTTP client.
@@ -247,12 +280,26 @@ class ArduinoCellular {
247
280
/* *
248
281
* @brief Gets a HTTPS client for the specified server and port.
249
282
* The maximum number of HTTP clients is limited by the number of sockets available.
283
+ * Call `cleanup()` to release the resources used by the clients once you are done with them.
250
284
* @param server The server address.
251
285
* @param port The server port.
252
286
* @return The HTTPS client.
253
287
*/
254
288
HttpClient getHTTPSClient (const char * server, const int port);
255
289
290
+ /* *
291
+ * @brief Cleans up the clients and releases the resources used by them.
292
+ * It's necessary to call this function to free up the memory used by the client
293
+ * objects that are created by the library internally.
294
+ */
295
+ void cleanup ();
296
+
297
+ /* *
298
+ * @brief Gets the number of managed clients.
299
+ * The clients are managed in the sense of memory management.
300
+ */
301
+ size_t getManagedClientCount () const ;
302
+
256
303
/* *
257
304
* @brief Gets the local IP address.
258
305
* @return The local IP address.
@@ -282,6 +329,10 @@ class ArduinoCellular {
282
329
SimStatus getSimStatus ();
283
330
284
331
private:
332
+ // Each instance manages its own connections
333
+ std::vector<std::unique_ptr<ManagedTinyGsmClient>> managedGsmClients;
334
+ std::vector<std::unique_ptr<BearSSLClient>> managedSslClients;
335
+
285
336
bool connectToGPRS (const char * apn, const char * gprsUser, const char * gprsPass);
286
337
287
338
0 commit comments