Rename MqttBroker to remote_broker

This commit is contained in:
Francois BIOT
2022-12-29 13:39:34 +01:00
parent 9e578471f1
commit 8162b4c35b
2 changed files with 12 additions and 12 deletions

View File

@@ -128,9 +128,9 @@ void MqttBroker::addClient(MqttClient* client)
void MqttBroker::connect(const std::string& host, uint16_t port) void MqttBroker::connect(const std::string& host, uint16_t port)
{ {
debug("MqttBroker::connect"); debug("MqttBroker::connect");
if (broker == nullptr) broker = new MqttClient; if (remote_broker == nullptr) remote_broker = new MqttClient;
broker->connect(host, port); remote_broker->connect(host, port);
broker->local_broker = this; // Because connect removed the link remote_broker->local_broker = this; // Because connect removed the link
} }
void MqttBroker::removeClient(MqttClient* remove) void MqttBroker::removeClient(MqttClient* remove)
@@ -174,11 +174,11 @@ void MqttBroker::loop()
onClient(this, &client); onClient(this, &client);
} }
#endif #endif
if (broker) if (remote_broker)
{ {
// TODO should monitor broker's activity. // TODO should monitor broker's activity.
// 1 When broker disconnect and reconnect we have to re-subscribe // 1 When broker disconnect and reconnect we have to re-subscribe
broker->loop(); remote_broker->loop();
} }
for(size_t i=0; i<clients.size(); i++) for(size_t i=0; i<clients.size(); i++)
@@ -201,9 +201,9 @@ void MqttBroker::loop()
MqttError MqttBroker::subscribe(const Topic& topic, uint8_t qos) MqttError MqttBroker::subscribe(const Topic& topic, uint8_t qos)
{ {
debug("MqttBroker::subscribe"); debug("MqttBroker::subscribe");
if (broker && broker->connected()) if (remote_broker && remote_broker->connected())
{ {
return broker->subscribe(topic, qos); return remote_broker->subscribe(topic, qos);
} }
return MqttNowhereToSend; return MqttNowhereToSend;
} }
@@ -218,19 +218,19 @@ MqttError MqttBroker::publish(const MqttClient* source, const Topic& topic, Mqtt
{ {
i++; i++;
#if TINY_MQTT_DEBUG #if TINY_MQTT_DEBUG
Console << __LINE__ << " broker:" << (broker && broker->connected() ? "linked" : "alone") << Console << __LINE__ << " broker:" << (remote_broker && remote_broker->connected() ? "linked" : "alone") <<
" srce=" << (source->isLocal() ? "loc" : "rem") << " clt#" << i << ", local=" << client->isLocal() << ", con=" << client->connected() << endl; " srce=" << (source->isLocal() ? "loc" : "rem") << " clt#" << i << ", local=" << client->isLocal() << ", con=" << client->connected() << endl;
#endif #endif
bool doit = false; bool doit = false;
if (broker && broker->connected()) // this (MqttBroker) is connected (to a external broker) if (remote_broker && remote_broker->connected()) // this (MqttBroker) is connected (to a external broker)
{ {
// ext_broker -> clients or clients -> ext_broker // ext_broker -> clients or clients -> ext_broker
if (source == broker) // external broker -> internal clients if (source == remote_broker) // external broker -> internal clients
doit = true; doit = true;
else // external clients -> this broker else // external clients -> this broker
{ {
// As this broker is connected to another broker, simply forward the msg // As this broker is connected to another broker, simply forward the msg
MqttError ret = broker->publishIfSubscribed(topic, msg); MqttError ret = remote_broker->publishIfSubscribed(topic, msg);
if (ret != MqttOk) retval = ret; if (ret != MqttOk) retval = ret;
} }
} }

View File

@@ -365,7 +365,7 @@ class MqttBroker
const char* auth_user = "guest"; const char* auth_user = "guest";
const char* auth_password = "guest"; const char* auth_password = "guest";
MqttClient* broker = nullptr; MqttClient* remote_broker = nullptr;
State state = Disconnected; State state = Disconnected;
}; };