Skip to content

Commit c372761

Browse files
aentingermattiabertorello
authored andcommitted
Using 'const' where feasible (const correctness)
1 parent 962d99a commit c372761

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/ArduinoIoTCloud.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void ArduinoIoTCloudClass::update()
112112
update(MAX_RETRIES, RECONNECTION_TIMEOUT);
113113
}
114114

115-
bool ArduinoIoTCloudClass::mqttReconnect(int maxRetries, int timeout)
115+
bool ArduinoIoTCloudClass::mqttReconnect(int const maxRetries, int const timeout)
116116
{
117117
// Counter for reconnection retries
118118
int retries = 0;
@@ -136,11 +136,11 @@ bool ArduinoIoTCloudClass::mqttReconnect(int maxRetries, int timeout)
136136
return true;
137137
}
138138

139-
void ArduinoIoTCloudClass::update(int reconnectionMaxRetries, int reconnectionTimeoutMs)
139+
void ArduinoIoTCloudClass::update(int const reconnectionMaxRetries, int const reconnectionTimeoutMs)
140140
{
141141
// Method's argument controls
142-
int maxRetries = (reconnectionMaxRetries > 0) ? reconnectionMaxRetries : MAX_RETRIES;
143-
int timeout = (reconnectionTimeoutMs > 0) ? reconnectionTimeoutMs : RECONNECTION_TIMEOUT;
142+
int const maxRetries = (reconnectionMaxRetries > 0) ? reconnectionMaxRetries : MAX_RETRIES;
143+
int const timeout = (reconnectionTimeoutMs > 0) ? reconnectionTimeoutMs : RECONNECTION_TIMEOUT;
144144

145145
// If the reconnect() culd not establish the connection, return the control to the user sketch
146146
if (!mqttReconnect(maxRetries, timeout))
@@ -150,7 +150,7 @@ void ArduinoIoTCloudClass::update(int reconnectionMaxRetries, int reconnectionTi
150150
_mqttClient.loop();
151151

152152
uint8_t data[MQTT_BUFFER_SIZE];
153-
int length = Thing.poll(data, sizeof(data));
153+
int const length = Thing.poll(data, sizeof(data));
154154
if (length > 0) {
155155
writeProperties(data, length);
156156
}
@@ -186,22 +186,22 @@ int ArduinoIoTCloudClass::connected()
186186
return _mqttClient.connected();
187187
}
188188

189-
int ArduinoIoTCloudClass::writeProperties(const byte data[], int length)
189+
int ArduinoIoTCloudClass::writeProperties(const byte data[], int const length)
190190
{
191191
return _mqttClient.publish(_dataTopicOut.c_str(), (const char*)data, length);
192192
}
193193

194-
int ArduinoIoTCloudClass::writeStdout(const byte data[], int length)
194+
int ArduinoIoTCloudClass::writeStdout(const byte data[], int const length)
195195
{
196196
return _mqttClient.publish(_stdoutTopic.c_str(), (const char*)data, length);
197197
}
198198

199-
void ArduinoIoTCloudClass::onMessage(MQTTClient* /*client*/, char topic[], char bytes[], int length)
199+
void ArduinoIoTCloudClass::onMessage(MQTTClient* /*client*/, char topic[], char bytes[], int const length)
200200
{
201201
ArduinoCloud.handleMessage(topic, bytes, length);
202202
}
203203

204-
void ArduinoIoTCloudClass::handleMessage(char topic[], char bytes[], int length)
204+
void ArduinoIoTCloudClass::handleMessage(char topic[], char bytes[], int const length)
205205
{
206206
if (_stdinTopic == topic) {
207207
CloudSerial.appendStdin((uint8_t*)bytes, length);

src/ArduinoIoTCloud.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ArduinoIoTCloudClass {
3535
void update();
3636

3737
// defined for users who want to specify max reconnections reties and timeout between them
38-
void update(int reconnectionMaxRetries, int reconnectionTimeoutMs);
38+
void update(int const reconnectionMaxRetries, int const reconnectionTimeoutMs);
3939
// It must be a user defined function, in order to avoid ArduinoCloud include specific WiFi file
4040
// in this case this library is independent from the WiFi one
4141
void onGetTime(unsigned long(*)(void));
@@ -52,16 +52,16 @@ class ArduinoIoTCloudClass {
5252

5353
protected:
5454
friend class CloudSerialClass;
55-
int writeStdout(const byte data[], int length);
56-
int writeProperties(const byte data[], int length);
55+
int writeStdout(const byte data[], int const length);
56+
int writeProperties(const byte data[], int const length);
5757
// Used to initialize MQTTClient
5858
void mqttClientBegin(Client& net);
5959
// Function in charge of perform MQTT reconnection, basing on class parameters(retries,and timeout)
60-
bool mqttReconnect(int maxRetries, int timeout);
60+
bool mqttReconnect(int const maxRetries, int const timeout);
6161

6262
private:
63-
static void onMessage(MQTTClient *client, char topic[], char bytes[], int length);
64-
void handleMessage(char topic[], char bytes[], int length);
63+
static void onMessage(MQTTClient *client, char topic[], char bytes[], int const length);
64+
void handleMessage(char topic[], char bytes[], int const length);
6565

6666
String _id;
6767
String _brokerAddress;

0 commit comments

Comments
 (0)