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

Method sourceSetProperty

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

* @brief Sets a driver connection property for a source. */

Source from the content-addressed store, hash-verified

406 * @brief Sets a driver connection property for a source.
407 */
408API::CommandResponse API::Handlers::SourceHandler::sourceSetProperty(const QString& id,
409 const QJsonObject& params)
410{
411 if (!params.contains(Keys::SourceId) || !params.contains(QStringLiteral("key")))
412 return CommandResponse::makeError(
413 id, QStringLiteral("MISSING_PARAM"), QStringLiteral("sourceId and key are required"));
414
415 const bool hasValue =
416 params.contains(QStringLiteral("propertyValue")) || params.contains(QStringLiteral("value"));
417 if (!hasValue)
418 return CommandResponse::makeError(
419 id, QStringLiteral("MISSING_PARAM"), QStringLiteral("propertyValue is required"));
420
421 const int sourceId = params[Keys::SourceId].toInt(-1);
422 if (sourceId < 0)
423 return CommandResponse::makeError(
424 id, QStringLiteral("INVALID_PARAM"), QStringLiteral("Invalid sourceId"));
425
426 const QString key = params[QStringLiteral("key")].toString();
427 const QVariant val = params.contains(QStringLiteral("propertyValue"))
428 ? params[QStringLiteral("propertyValue")].toVariant()
429 : params[QStringLiteral("value")].toVariant();
430
431 IO::HAL_Driver* driver = IO::ConnectionManager::instance().driverForEditing(sourceId);
432 if (!driver)
433 return CommandResponse::makeError(
434 id, QStringLiteral("OPERATION_FAILED"), QStringLiteral("No driver for source"));
435
436 driver->setDriverProperty(key, val);
437 DataModel::ProjectModel::instance().captureSourceSettings(sourceId);
438
439 IO::HAL_Driver* live = IO::ConnectionManager::instance().driver(sourceId);
440 if (live && live != driver)
441 live->setDriverProperty(key, val);
442
443 return CommandResponse::makeSuccess(id);
444}
445
446/**
447 * @brief Returns the full configuration for a source.

Callers

nothing calls this directly

Calls 6

toVariantMethod · 0.80
driverForEditingMethod · 0.80
captureSourceSettingsMethod · 0.80
containsMethod · 0.45
setDriverPropertyMethod · 0.45
driverMethod · 0.45

Tested by

no test coverage detected