Corrected client public/private methods.

Switched the following four methods from public to
protected in Adafruit_MQTT_Client and Adafruit_MQTT_FONA:

1. connectServer
2. disconnectServer
3. readPacket
4. sendPacket

When public (previously) they could be called by users
of this library, which is not the intent of this API.
This commit is contained in:
Chris Mumford 2020-07-02 10:02:15 -07:00
parent 8db0c2787d
commit c5599bfabc
2 changed files with 19 additions and 14 deletions

View File

@ -41,11 +41,14 @@ public:
const char *user = "", const char *pass = "")
: Adafruit_MQTT(server, port, user, pass), client(client) {}
bool connectServer();
bool disconnectServer();
bool connected();
uint16_t readPacket(uint8_t *buffer, uint16_t maxlen, int16_t timeout);
bool sendPacket(uint8_t *buffer, uint16_t len);
bool connected() override;
protected:
bool connectServer() override;
bool disconnectServer() override;
uint16_t readPacket(uint8_t *buffer, uint16_t maxlen,
int16_t timeout) override;
bool sendPacket(uint8_t *buffer, uint16_t len) override;
private:
Client *client;

View File

@ -42,7 +42,13 @@ public:
const char *user = "", const char *pass = "")
: Adafruit_MQTT(server, port, user, pass), fona(f) {}
bool connectServer() {
bool connected() {
// Return true if connected, false if not connected.
return fona->TCPconnected();
}
protected:
bool connectServer() override {
char server[40];
strncpy(server, servername, 40);
#ifdef ADAFRUIT_SLEEPYDOG_H
@ -54,14 +60,10 @@ public:
return fona->TCPconnect(server, portnum);
}
bool disconnectServer() { return fona->TCPclose(); }
bool disconnectServer() override { return fona->TCPclose(); }
bool connected() {
// Return true if connected, false if not connected.
return fona->TCPconnected();
}
uint16_t readPacket(uint8_t *buffer, uint16_t maxlen, int16_t timeout) {
uint16_t readPacket(uint8_t *buffer, uint16_t maxlen,
int16_t timeout) override {
uint8_t *buffp = buffer;
DEBUG_PRINTLN(F("Reading data.."));
@ -114,7 +116,7 @@ public:
return len;
}
bool sendPacket(uint8_t *buffer, uint16_t len) {
bool sendPacket(uint8_t *buffer, uint16_t len) override {
DEBUG_PRINTLN(F("Writing packet"));
if (fona->TCPconnected()) {
boolean ret = fona->TCPsend((char *)buffer, len);