* @brief Writes a register's live runtime value into the data-table store, mirroring the * parser/transform tableSet() value semantics (numeric when parseable, string otherwise). */
| 686 | * parser/transform tableSet() value semantics (numeric when parseable, string otherwise). |
| 687 | */ |
| 688 | API::CommandResponse API::Handlers::DataTablesHandler::valueSet(const QString& id, |
| 689 | const QJsonObject& params) |
| 690 | { |
| 691 | QString table; |
| 692 | QString name; |
| 693 | if (!requireString(params, QStringLiteral("table"), table)) |
| 694 | return CommandResponse::makeError( |
| 695 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: table")); |
| 696 | |
| 697 | if (!requireString(params, QStringLiteral("name"), name)) |
| 698 | return CommandResponse::makeError( |
| 699 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: name")); |
| 700 | |
| 701 | if (!params.contains(QStringLiteral("value"))) |
| 702 | return CommandResponse::makeError( |
| 703 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: value")); |
| 704 | |
| 705 | const QVariant v = jsonToVariant(params.value(QStringLiteral("value"))); |
| 706 | |
| 707 | DataModel::RegisterValue rv; |
| 708 | rv.numericValue = SerialStudio::toDouble(v, &rv.isNumeric); |
| 709 | if (!rv.isNumeric) |
| 710 | rv.stringValue = v.toString(); |
| 711 | |
| 712 | auto& store = DataModel::FrameBuilder::instance().tableStore(); |
| 713 | if (!store.isInitialized()) |
| 714 | return CommandResponse::makeError( |
| 715 | id, ErrorCode::InvalidParam, QStringLiteral("Data-table store not initialized (no project)")); |
| 716 | |
| 717 | if (!store.set(table, name, rv)) |
| 718 | return CommandResponse::makeError( |
| 719 | id, |
| 720 | ErrorCode::InvalidParam, |
| 721 | QStringLiteral("Cannot write register %1/%2 (unknown, or a constant register)") |
| 722 | .arg(table, name)); |
| 723 | |
| 724 | QJsonObject result; |
| 725 | result[QStringLiteral("table")] = table; |
| 726 | result[QStringLiteral("name")] = name; |
| 727 | result[QStringLiteral("written")] = true; |
| 728 | return CommandResponse::makeSuccess(id, result); |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * @brief Resolves a (table, register) pair to a reusable handle for the marshalled fast path. |
nothing calls this directly
no test coverage detected