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

Method sourceConfigure

app/src/API/Handlers/SourceHandler.cpp:360–403  ·  view source on GitHub ↗

* @brief Applies multiple driver connection properties to a source in one call. */

Source from the content-addressed store, hash-verified

358 * @brief Applies multiple driver connection properties to a source in one call.
359 */
360API::CommandResponse API::Handlers::SourceHandler::sourceConfigure(const QString& id,
361 const QJsonObject& params)
362{
363 if (!params.contains(Keys::SourceId) || !params.contains(QStringLiteral("settings")))
364 return CommandResponse::makeError(
365 id, QStringLiteral("MISSING_PARAM"), QStringLiteral("sourceId and settings are required"));
366
367 const int sourceId = params[Keys::SourceId].toInt(-1);
368 const auto& model = DataModel::ProjectModel::instance();
369 const int sourceCount = static_cast<int>(model.sources().size());
370
371 if (sourceId < 0 || sourceId >= sourceCount)
372 return CommandResponse::makeError(
373 id, QStringLiteral("INVALID_PARAM"), QStringLiteral("Invalid sourceId"));
374
375 const QJsonObject settings = params[QStringLiteral("settings")].toObject();
376 const bool usesUiDriver = sourceId == 0 && sourceCount == 1
377 && AppState::instance().operationMode() == SerialStudio::ProjectFile;
378
379 if (usesUiDriver) {
380 for (auto it = settings.constBegin(); it != settings.constEnd(); ++it)
381 IO::ConnectionManager::instance().setUiDriverProperty(it.key(), it.value().toVariant());
382
383 DataModel::ProjectModel::instance().captureSourceSettings(sourceId);
384 return CommandResponse::makeSuccess(id);
385 }
386
387 IO::HAL_Driver* driver = IO::ConnectionManager::instance().driverForEditing(sourceId);
388 if (!driver)
389 return CommandResponse::makeError(
390 id, QStringLiteral("OPERATION_FAILED"), QStringLiteral("No driver for source"));
391
392 for (auto it = settings.constBegin(); it != settings.constEnd(); ++it)
393 driver->setDriverProperty(it.key(), it.value().toVariant());
394
395 DataModel::ProjectModel::instance().captureSourceSettings(sourceId);
396
397 IO::HAL_Driver* live = IO::ConnectionManager::instance().driver(sourceId);
398 if (live && live != driver)
399 for (auto it = settings.constBegin(); it != settings.constEnd(); ++it)
400 live->setDriverProperty(it.key(), it.value().toVariant());
401
402 return CommandResponse::makeSuccess(id);
403}
404
405/**
406 * @brief Sets a driver connection property for a source.

Callers

nothing calls this directly

Calls 11

operationModeMethod · 0.80
setUiDriverPropertyMethod · 0.80
keyMethod · 0.80
toVariantMethod · 0.80
captureSourceSettingsMethod · 0.80
driverForEditingMethod · 0.80
containsMethod · 0.45
sizeMethod · 0.45
valueMethod · 0.45
setDriverPropertyMethod · 0.45
driverMethod · 0.45

Tested by

no test coverage detected