MCPcopy Create free account
hub / github.com/BlueAndi/Pixelix / setTopic

Method setTopic

lib/MultiIconPlugin/src/MultiIconPlugin.cpp:122–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122bool MultiIconPlugin::setTopic(const String& topic, const JsonObjectConst& value)
123{
124 bool isSuccessful = false;
125
126 if (true == topic.startsWith(String(TOPIC_SLOT) + "/"))
127 {
128 uint8_t slotId = _MultiIconPlugin::View::MAX_ICON_SLOTS;
129 bool status = getSlotIdFromTopic(slotId, topic);
130
131 if ((true == status) &&
132 (_MultiIconPlugin::View::MAX_ICON_SLOTS > slotId))
133 {
134 const size_t JSON_DOC_SIZE = 512U;
135 DynamicJsonDocument jsonDoc(JSON_DOC_SIZE);
136 JsonObject jsonCfg = jsonDoc.to<JsonObject>();
137 JsonVariantConst jsonFileId = value["fileId"];
138
139 /* The received configuration may not contain all single key/value pair.
140 * Therefore read first the complete internal configuration and
141 * overwrite them with the received ones.
142 */
143 getConfiguration(jsonCfg);
144
145 if (false == jsonFileId.isNull())
146 {
147 jsonCfg["slots"][slotId] = jsonFileId.as<FileMgrService::FileId>();
148 isSuccessful = true;
149 }
150
151 if (true == isSuccessful)
152 {
153 JsonObjectConst jsonCfgConst = jsonCfg;
154
155 isSuccessful = setConfiguration(jsonCfgConst);
156
157 if (true == isSuccessful)
158 {
159 requestStoreToPersistentMemory();
160 }
161 }
162 }
163 }
164 else if (true == topic.equals(TOPIC_SLOTS))
165 {
166 const size_t JSON_DOC_SIZE = 512U;
167 DynamicJsonDocument jsonDoc(JSON_DOC_SIZE);
168 JsonObject jsonCfg = jsonDoc.to<JsonObject>();
169 JsonVariantConst jsonSlots = value["slots"];
170
171 /* The received configuration may not contain all single key/value pair.
172 * Therefore read first the complete internal configuration and
173 * overwrite them with the received ones.
174 */
175 getConfiguration(jsonCfg);
176
177 /* Note:
178 * Check only for the key/value pair availability.
179 * The type check will follow in the setConfiguration().

Callers

nothing calls this directly

Calls 3

StringClass · 0.85
startsWithMethod · 0.80
toIntMethod · 0.80

Tested by

no test coverage detected