Skip to content

Commit

Permalink
Merge pull request Imroy#60 from vicatcu/master
Browse files Browse the repository at this point in the history
refactored constructors to use getters and setters
  • Loading branch information
knolleary committed Aug 26, 2015
2 parents d00a6c3 + fb78845 commit 5418f32
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
69 changes: 48 additions & 21 deletions PubSubClient/PubSubClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,44 @@

PubSubClient::PubSubClient() {
this->_client = NULL;
this->stream = NULL;
this->stream = NULL;
setCallback(NULL);
setPort(1883);
setBrokerDomain(NULL);
}

PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, void (*callback)(char*,uint8_t*,unsigned int), Client& client) {
this->_client = &client;
this->callback = callback;
this->ip = ip;
this->port = port;
this->domain = NULL;
setClient(client);
setCallback(callback);
setBrokerIP(ip);
setPort(port);
setBrokerDomain(NULL);
this->stream = NULL;
}

PubSubClient::PubSubClient(char* domain, uint16_t port, void (*callback)(char*,uint8_t*,unsigned int), Client& client) {
this->_client = &client;
this->callback = callback;
this->domain = domain;
this->port = port;
setClient(client);
setCallback(callback);
setBrokerDomain(domain);
setPort(port);
this->stream = NULL;
}

PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, void (*callback)(char*,uint8_t*,unsigned int), Client& client, Stream& stream) {
this->_client = &client;
this->callback = callback;
this->ip = ip;
this->port = port;
this->domain = NULL;
this->stream = &stream;
setClient(client);
setCallback(callback);
setBrokerIP(ip);
setPort(port);
setBrokerDomain(NULL);
setStream(stream);
}

PubSubClient::PubSubClient(char* domain, uint16_t port, void (*callback)(char*,uint8_t*,unsigned int), Client& client, Stream& stream) {
this->_client = &client;
this->callback = callback;
this->domain = domain;
this->port = port;
this->stream = &stream;
setClient(client);
setCallback(callback);
setBrokerDomain(domain);
setPort(port);
setStream(stream);
}

boolean PubSubClient::connect(char *id) {
Expand Down Expand Up @@ -425,3 +428,27 @@ boolean PubSubClient::connected() {
return rc;
}

void PubSubClient::setBrokerIP(uint8_t * ip){
this->domain = NULL;
this->ip = ip;
}

void PubSubClient::setBrokerDomain(char * domain){
this->domain = domain;
}

void PubSubClient::setCallback(void(*callback)(char*,uint8_t*,unsigned int)){
this->callback = callback;
}

void PubSubClient::setPort(uint16_t port){
this->port = port;
}

void PubSubClient::setClient(Client& client){
this->_client = &client;
}

void PubSubClient::setStream(Stream& stream){
this->stream = &stream;
}
8 changes: 8 additions & 0 deletions PubSubClient/PubSubClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class PubSubClient {
PubSubClient(uint8_t *, uint16_t, void(*)(char*,uint8_t*,unsigned int),Client& client, Stream&);
PubSubClient(char*, uint16_t, void(*)(char*,uint8_t*,unsigned int),Client& client);
PubSubClient(char*, uint16_t, void(*)(char*,uint8_t*,unsigned int),Client& client, Stream&);

void setBrokerIP(uint8_t * ip);
void setBrokerDomain(char * domain);
void setCallback(void(*callback)(char*,uint8_t*,unsigned int));
void setPort(uint16_t port);
void setClient(Client& client);
void setStream(Stream& stream);

boolean connect(char *);
boolean connect(char *, char *, char *);
boolean connect(char *, char *, uint8_t, uint8_t, char *);
Expand Down

0 comments on commit 5418f32

Please sign in to comment.