* @brief Opens the broker connection. Subscription is issued once Connected. */
| 157 | * @brief Opens the broker connection. Subscription is issued once Connected. |
| 158 | */ |
| 159 | bool IO::Drivers::MQTT::open(const QIODevice::OpenMode mode) |
| 160 | { |
| 161 | Q_UNUSED(mode); |
| 162 | |
| 163 | const auto& token = Licensing::CommercialToken::current(); |
| 164 | if (!token.isValid() || !SS_LICENSE_GUARD() |
| 165 | || token.featureTier() < Licensing::FeatureTier::Trial) { |
| 166 | Misc::Utilities::showMessageBox( |
| 167 | tr("MQTT Feature Requires a Commercial License"), |
| 168 | tr("Subscribing to an MQTT broker is only available with a valid Serial Studio license " |
| 169 | "or an active trial."), |
| 170 | QMessageBox::Warning); |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | if (m_hostname.isEmpty() || m_port == 0) { |
| 175 | qCWarning(lcMqttSub) << "open() rejected: missing hostname or port" << m_hostname << m_port; |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | if (m_topicFilter.isEmpty()) { |
| 180 | qCWarning(lcMqttSub) << "open() rejected: empty topic filter"; |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | if (m_client.state() != QMqttClient::Disconnected) { |
| 185 | qCInfo(lcMqttSub) << "open() no-op; state already" << m_client.state(); |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | if (m_clientId.isEmpty()) |
| 190 | regenerateClientId(); |
| 191 | |
| 192 | applyPendingToClient(); |
| 193 | m_userWantsOpen = true; |
| 194 | |
| 195 | qCInfo(lcMqttSub).nospace() << "Connecting to " << (m_sslEnabled ? "mqtts://" : "mqtt://") |
| 196 | << m_hostname << ":" << m_port << " clientId=" << m_clientId |
| 197 | << " topic=" << m_topicFilter; |
| 198 | |
| 199 | if (m_sslEnabled) |
| 200 | m_client.connectToHostEncrypted(m_sslConfiguration); |
| 201 | else |
| 202 | m_client.connectToHost(); |
| 203 | |
| 204 | return true; |
| 205 | } |
| 206 | |
| 207 | //-------------------------------------------------------------------------------------------------- |
| 208 | // Property getters |
no test coverage detected