mirror of https://github.com/nymea/nymea.git
Merge PR #545: Add connected property to MqttChannel
commit
ed7926f84e
|
|
@ -72,4 +72,19 @@ void MqttChannelImplementation::publish(const QString &topic, const QByteArray &
|
|||
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;
|
||||
|
||||
bool isConnected() const override;
|
||||
void setConnected(bool connected);
|
||||
|
||||
signals:
|
||||
void pluginPublished(const QString &topic, const QByteArray &payload);
|
||||
|
||||
|
|
@ -60,6 +63,7 @@ private:
|
|||
QHostAddress m_serverAddress;
|
||||
quint16 m_serverPort;
|
||||
QStringList m_topicPrefixList;
|
||||
bool m_connected = false;
|
||||
|
||||
friend class MqttProviderImplementation;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -205,16 +205,16 @@ void MqttProviderImplementation::setEnabled(bool enabled)
|
|||
void MqttProviderImplementation::onClientConnected(const QString &clientId)
|
||||
{
|
||||
if (m_createdChannels.contains(clientId)) {
|
||||
MqttChannel* channel = m_createdChannels.value(clientId);
|
||||
emit channel->clientConnected(channel);
|
||||
MqttChannelImplementation *channel = qobject_cast<MqttChannelImplementation *>(m_createdChannels.value(clientId));
|
||||
channel->setConnected(true);
|
||||
}
|
||||
}
|
||||
|
||||
void MqttProviderImplementation::onClientDisconnected(const QString &clientId)
|
||||
{
|
||||
if (m_createdChannels.contains(clientId)) {
|
||||
MqttChannel *channel = m_createdChannels.value(clientId);
|
||||
emit channel->clientDisconnected(channel);
|
||||
MqttChannelImplementation *channel = qobject_cast<MqttChannelImplementation *>(m_createdChannels.value(clientId));
|
||||
channel->setConnected(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ private slots:
|
|||
private:
|
||||
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 bool isConnected() const = 0;
|
||||
|
||||
signals:
|
||||
void clientConnected(MqttChannel* channel);
|
||||
void clientDisconnected(MqttChannel* channel);
|
||||
|
|
|
|||
Loading…
Reference in New Issue