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

Method load

app/src/AI/CommandRegistry.cpp:47–101  ·  view source on GitHub ↗

* @brief Reads the safety JSON resource into the tag map. */

Source from the content-addressed store, hash-verified

45 * @brief Reads the safety JSON resource into the tag map.
46 */
47void AI::CommandRegistry::load()
48{
49 QFile file(QStringLiteral(":/ai/command_safety.json"));
50 if (!file.open(QIODevice::ReadOnly)) {
51 qCWarning(serialStudioAI) << "command_safety.json could not be opened; "
52 "all commands fall through to Confirm.";
53 return;
54 }
55
56 const auto data = file.readAll();
57 file.close();
58
59 Misc::JsonValidator::Limits limits;
60 limits.maxFileSize = 1 * 1024 * 1024;
61 limits.maxDepth = 8;
62 limits.maxArraySize = 1000;
63
64 const auto result = Misc::JsonValidator::parseAndValidate(data, limits);
65 if (!result.valid || !result.document.isObject()) {
66 qCWarning(serialStudioAI) << "command_safety.json invalid:" << result.errorMessage;
67 return;
68 }
69
70 const auto root = result.document.object();
71 const auto safe = root.value(QStringLiteral("safe")).toArray();
72 const auto confirm = root.value(QStringLiteral("confirm")).toArray();
73 const auto blocked = root.value(QStringLiteral("blocked")).toArray();
74 const auto deviceGated = root.value(QStringLiteral("deviceGated")).toArray();
75 const auto alwaysConfirm = root.value(QStringLiteral("alwaysConfirm")).toArray();
76
77 for (const auto& entry : safe)
78 if (entry.isString())
79 m_tags.insert(entry.toString(), Safety::Safe);
80
81 for (const auto& entry : confirm)
82 if (entry.isString())
83 m_tags.insert(entry.toString(), Safety::Confirm);
84
85 for (const auto& entry : blocked)
86 if (entry.isString())
87 m_tags.insert(entry.toString(), Safety::Blocked);
88
89 for (const auto& entry : deviceGated)
90 if (entry.isString())
91 m_deviceGated.insert(entry.toString());
92
93 for (const auto& entry : alwaysConfirm)
94 if (entry.isString())
95 m_tags.insert(entry.toString(), Safety::AlwaysConfirm);
96
97 qCDebug(serialStudioAI) << "Loaded AI command safety tags:" << safe.size() << "safe,"
98 << confirm.size() << "confirm," << blocked.size() << "blocked,"
99 << m_deviceGated.size() << "deviceGated," << alwaysConfirm.size()
100 << "alwaysConfirm.";
101}
102
103//--------------------------------------------------------------------------------------------------
104// Queries

Callers

nothing calls this directly

Calls 4

openMethod · 0.45
closeMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected