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

Method sourceAdd

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

* @brief Adds a new source (Commercial only). */

Source from the content-addressed store, hash-verified

239 * @brief Adds a new source (Commercial only).
240 */
241API::CommandResponse API::Handlers::SourceHandler::sourceAdd(const QString& id,
242 const QJsonObject& params)
243{
244 (void)params;
245
246#ifndef BUILD_COMMERCIAL
247 return CommandResponse::makeError(id,
248 QStringLiteral("COMMERCIAL_REQUIRED"),
249 QStringLiteral("Multiple data sources require a Pro license"));
250#else
251 const int countBefore = DataModel::ProjectModel::instance().sourceCount();
252 QMetaObject::invokeMethod(&DataModel::ProjectModel::instance(), "addSource");
253
254 const int countAfter = DataModel::ProjectModel::instance().sourceCount();
255 if (countAfter <= countBefore)
256 return CommandResponse::makeError(
257 id, QStringLiteral("OPERATION_FAILED"), QStringLiteral("Failed to add source"));
258
259 QJsonObject result;
260 result[Keys::SourceId] = countAfter - 1;
261 return CommandResponse::makeSuccess(id, result);
262#endif
263}
264
265/**
266 * @brief Deletes a source (Commercial only; sourceId must be >= 1).

Callers

nothing calls this directly

Calls 1

sourceCountMethod · 0.80

Tested by

no test coverage detected