MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / open

Method open

app/src/IO/Drivers/MQTT.cpp:159–205  ·  view source on GitHub ↗

* @brief Opens the broker connection. Subscription is issued once Connected. */

Source from the content-addressed store, hash-verified

157 * @brief Opens the broker connection. Subscription is issued once Connected.
158 */
159bool 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

Callers 1

addCaCertificatesMethod · 0.45

Calls 3

featureTierMethod · 0.80
isEmptyMethod · 0.80
isValidMethod · 0.45

Tested by

no test coverage detected