Add connected property to MqttChannel
This commit is contained in:
parent
5674ba7567
commit
4ef0b68027
@ -72,4 +72,19 @@ void MqttChannelImplementation::publish(const QString &topic, const QByteArray &
|
|||||||
emit pluginPublished(topic, payload);
|
emit pluginPublished(topic, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MqttChannelImplementation::isConnected() const
|
||||||
|
{
|
||||||
|
return m_connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MqttChannelImplementation::setConnected(bool connected)
|
||||||
|
{
|
||||||
|
m_connected = connected;
|
||||||
|
if (m_connected) {
|
||||||
|
emit clientConnected(this);
|
||||||
|
} else {
|
||||||
|
emit clientDisconnected(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,9 @@ public:
|
|||||||
|
|
||||||
void publish(const QString &topic, const QByteArray &payload) override;
|
void publish(const QString &topic, const QByteArray &payload) override;
|
||||||
|
|
||||||
|
bool isConnected() const override;
|
||||||
|
void setConnected(bool connected);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void pluginPublished(const QString &topic, const QByteArray &payload);
|
void pluginPublished(const QString &topic, const QByteArray &payload);
|
||||||
|
|
||||||
@ -60,6 +63,7 @@ private:
|
|||||||
QHostAddress m_serverAddress;
|
QHostAddress m_serverAddress;
|
||||||
quint16 m_serverPort;
|
quint16 m_serverPort;
|
||||||
QStringList m_topicPrefixList;
|
QStringList m_topicPrefixList;
|
||||||
|
bool m_connected = false;
|
||||||
|
|
||||||
friend class MqttProviderImplementation;
|
friend class MqttProviderImplementation;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -205,16 +205,16 @@ void MqttProviderImplementation::setEnabled(bool enabled)
|
|||||||
void MqttProviderImplementation::onClientConnected(const QString &clientId)
|
void MqttProviderImplementation::onClientConnected(const QString &clientId)
|
||||||
{
|
{
|
||||||
if (m_createdChannels.contains(clientId)) {
|
if (m_createdChannels.contains(clientId)) {
|
||||||
MqttChannel* channel = m_createdChannels.value(clientId);
|
MqttChannelImplementation *channel = qobject_cast<MqttChannelImplementation *>(m_createdChannels.value(clientId));
|
||||||
emit channel->clientConnected(channel);
|
channel->setConnected(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttProviderImplementation::onClientDisconnected(const QString &clientId)
|
void MqttProviderImplementation::onClientDisconnected(const QString &clientId)
|
||||||
{
|
{
|
||||||
if (m_createdChannels.contains(clientId)) {
|
if (m_createdChannels.contains(clientId)) {
|
||||||
MqttChannel *channel = m_createdChannels.value(clientId);
|
MqttChannelImplementation *channel = qobject_cast<MqttChannelImplementation *>(m_createdChannels.value(clientId));
|
||||||
emit channel->clientDisconnected(channel);
|
channel->setConnected(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -64,7 +64,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
MqttBroker* m_broker = nullptr;
|
MqttBroker* m_broker = nullptr;
|
||||||
|
|
||||||
QHash<QString, MqttChannel*> m_createdChannels;
|
QHash<QString, MqttChannel *> m_createdChannels;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,8 @@ public:
|
|||||||
|
|
||||||
virtual void publish(const QString &topic, const QByteArray &payload) = 0;
|
virtual void publish(const QString &topic, const QByteArray &payload) = 0;
|
||||||
|
|
||||||
|
virtual bool isConnected() const = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clientConnected(MqttChannel* channel);
|
void clientConnected(MqttChannel* channel);
|
||||||
void clientDisconnected(MqttChannel* channel);
|
void clientDisconnected(MqttChannel* channel);
|
||||||
|
|||||||
Reference in New Issue
Block a user