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

Method call

app/src/DataModel/Scripting/ControlScriptWorker.cpp:148–178  ·  view source on GitHub ↗

* @brief Implements apiCall(method, params) by blocking onto the GUI-thread marshaller. Fails * fast during shutdown (the GUI loop stops dispatching) and re-arms the watchdog after * the call so GUI-side time is not billed against the script budget. */

Source from the content-addressed store, hash-verified

146 * the call so GUI-side time is not billed against the script budget.
147 */
148QVariantMap DataModel::ControlApiBridge::call(const QString& method, const QVariantMap& params)
149{
150 QVariantMap out;
151 if (method.isEmpty()) {
152 out.insert(QStringLiteral("ok"), false);
153 out.insert(QStringLiteral("error"), QStringLiteral("apiCall: method must not be empty"));
154 return out;
155 }
156
157 if (s_shutdownRequested.load(std::memory_order_acquire)) {
158 out.insert(QStringLiteral("ok"), false);
159 out.insert(QStringLiteral("error"), QStringLiteral("apiCall: application is shutting down"));
160 return out;
161 }
162
163 const bool ok = QMetaObject::invokeMethod(m_marshaller,
164 "dispatch",
165 Qt::BlockingQueuedConnection,
166 Q_RETURN_ARG(QVariantMap, out),
167 Q_ARG(QString, method),
168 Q_ARG(QVariantMap, params));
169 if (m_watchdog && !s_shutdownRequested.load(std::memory_order_acquire))
170 m_watchdog->arm();
171
172 if (!ok) {
173 out.insert(QStringLiteral("ok"), false);
174 out.insert(QStringLiteral("error"), QStringLiteral("apiCall: GUI dispatch failed"));
175 }
176
177 return out;
178}
179
180/**
181 * @brief Returns the array of registered API command names for discovery.

Callers 2

runLoopTickMethod · 0.45
runSetupMethod · 0.45

Calls 3

isEmptyMethod · 0.80
loadMethod · 0.45
armMethod · 0.45

Tested by

no test coverage detected