MCPcopy Create free account
hub / github.com/aethersdr/AetherSDR / createMemoryFromSlice

Function createMemoryFromSlice

src/gui/MemoryCommands.cpp:77–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77void createMemoryFromSlice(RadioModel* model,
78 const SliceModel* slice,
79 const QString& name,
80 QObject* callbackContext,
81 MemoryCreateCallback cb)
82{
83 const bool useCallbackGuard = callbackContext != nullptr;
84 const QPointer<QObject> callbackGuard(callbackContext);
85 auto notify = [cb, useCallbackGuard, callbackGuard](int code,
86 const QString& body,
87 int memoryIndex) {
88 if (!cb)
89 return;
90 if (useCallbackGuard && callbackGuard.isNull())
91 return;
92 cb(code, body, memoryIndex);
93 };
94
95 if (!model || !slice) {
96 notify(-1, QStringLiteral("No active slice is available."), -1);
97 return;
98 }
99
100 const MemoryEntry memory = captureMemoryFromSlice(*model, *slice, name);
101 const MemoryUpdateData update = buildMemoryUpdateData(memory);
102
103 model->sendCmdPublic("memory create",
104 [model, update, notify](int code, const QString& body) {
105 if (code != 0) {
106 notify(code, body, -1);
107 return;
108 }
109
110 bool ok = false;
111 const int index = body.trimmed().toInt(&ok);
112 if (!ok) {
113 notify(-1,
114 QStringLiteral("The radio returned an invalid memory id."),
115 -1);
116 return;
117 }
118
119 model->sendCmdPublic(
120 QString("memory set %1 %2").arg(index).arg(update.commandSuffix),
121 [model, update, notify, index](int setCode, const QString& setBody) {
122 if (setCode == 0) {
123 model->handleMemoryStatus(index, update.kvs);
124 notify(0, setBody, index);
125 return;
126 }
127
128 model->sendCmdPublic(QString("memory remove %1").arg(index),
129 [model, notify, index, setCode, setBody](int removeCode, const QString& removeBody) {
130 if (removeCode == 0) {
131 QMap<QString, QString> removed;
132 removed["removed"] = QString{};
133 model->handleMemoryStatus(index, removed);
134 }

Callers 2

onAddMethod · 0.85

Calls 6

captureMemoryFromSliceFunction · 0.85
buildMemoryUpdateDataFunction · 0.85
isNullMethod · 0.80
sendCmdPublicMethod · 0.80
handleMemoryStatusMethod · 0.80
isEmptyMethod · 0.45

Tested by

no test coverage detected