* @brief Returns a register's live runtime value from the data-table store, mirroring the * parser/transform tableGet() (control scripts reach the store through this command). */
| 648 | * parser/transform tableGet() (control scripts reach the store through this command). |
| 649 | */ |
| 650 | API::CommandResponse API::Handlers::DataTablesHandler::valueGet(const QString& id, |
| 651 | const QJsonObject& params) |
| 652 | { |
| 653 | QString table; |
| 654 | QString name; |
| 655 | if (!requireString(params, QStringLiteral("table"), table)) |
| 656 | return CommandResponse::makeError( |
| 657 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: table")); |
| 658 | |
| 659 | if (!requireString(params, QStringLiteral("name"), name)) |
| 660 | return CommandResponse::makeError( |
| 661 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: name")); |
| 662 | |
| 663 | const auto& store = DataModel::FrameBuilder::instance().tableStore(); |
| 664 | if (!store.isInitialized()) |
| 665 | return CommandResponse::makeError( |
| 666 | id, ErrorCode::InvalidParam, QStringLiteral("Data-table store not initialized (no project)")); |
| 667 | |
| 668 | const auto* value = store.get(table, name); |
| 669 | if (!value) |
| 670 | return CommandResponse::makeError( |
| 671 | id, |
| 672 | ErrorCode::InvalidParam, |
| 673 | QStringLiteral("Unknown table or register: %1/%2").arg(table, name)); |
| 674 | |
| 675 | QJsonObject result; |
| 676 | result[QStringLiteral("table")] = table; |
| 677 | result[QStringLiteral("name")] = name; |
| 678 | result[QStringLiteral("isNumeric")] = value->isNumeric; |
| 679 | result[QStringLiteral("value")] = |
| 680 | value->isNumeric ? QJsonValue(value->numericValue) : QJsonValue(value->stringValue); |
| 681 | return CommandResponse::makeSuccess(id, result); |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * @brief Writes a register's live runtime value into the data-table store, mirroring the |
nothing calls this directly
no test coverage detected