@@ -282,22 +282,43 @@ QStringList JsonCallbacks::getSubscribedCommands() const
282282}
283283
284284void JsonCallbacks::doCallback (Subscription::Type cmd, const QVariant& data)
285+ {
286+ if (data.userType () == QMetaType::QJsonArray)
287+ {
288+ doCallback (cmd, data.toJsonArray ());
289+ }
290+ else
291+ {
292+ doCallback (cmd, data.toJsonObject ());
293+ }
294+ }
295+
296+ void JsonCallbacks::doCallback (Subscription::Type cmd, const QJsonArray& data)
285297{
286298 QJsonObject obj;
287299 obj[" command" ] = Subscription::toString (cmd);
288300
289301 if (Subscription::isInstanceSpecific (cmd))
290302 {
291- obj[ " instance" ] = _hyperion->getInstanceIndex ();
303+ obj. insert ( " instance" , _hyperion->getInstanceIndex () );
292304 }
305+ obj.insert (" data" , data);
293306
294- if (data.userType () == QMetaType::QJsonArray) {
295- obj[" data" ] = data.toJsonArray ();
296- } else {
297- obj[" data" ] = data.toJsonObject ();
307+ emit callbackReady (obj);
308+ }
309+
310+ void JsonCallbacks::doCallback (Subscription::Type cmd, const QJsonObject& data)
311+ {
312+ QJsonObject obj;
313+ obj[" command" ] = Subscription::toString (cmd);
314+
315+ if (Subscription::isInstanceSpecific (cmd))
316+ {
317+ obj.insert (" instance" , _hyperion->getInstanceIndex ());
298318 }
319+ obj.insert (" data" , data);
299320
300- emit newCallback (obj);
321+ emit callbackReady (obj);
301322}
302323
303324void JsonCallbacks::handleComponentState (hyperion::Components comp, bool state)
@@ -306,7 +327,7 @@ void JsonCallbacks::handleComponentState(hyperion::Components comp, bool state)
306327 data[" name" ] = componentToIdString (comp);
307328 data[" enabled" ] = state;
308329
309- doCallback (Subscription::ComponentsUpdate, QVariant ( data) );
330+ doCallback (Subscription::ComponentsUpdate, data);
310331}
311332
312333void JsonCallbacks::handlePriorityUpdate (int currentPriority, const PriorityMuxer::InputsMap& activeInputs)
@@ -315,15 +336,15 @@ void JsonCallbacks::handlePriorityUpdate(int currentPriority, const PriorityMuxe
315336 data[" priorities" ] = JsonInfo::getPrioritiestInfo (currentPriority, activeInputs);
316337 data[" priorities_autoselect" ] = _hyperion->sourceAutoSelectEnabled ();
317338
318- doCallback (Subscription::PrioritiesUpdate, QVariant ( data) );
339+ doCallback (Subscription::PrioritiesUpdate, data);
319340}
320341
321342void JsonCallbacks::handleImageToLedsMappingChange (int mappingType)
322343{
323344 QJsonObject data;
324345 data[" imageToLedMappingType" ] = ImageProcessor::mappingTypeToStr (mappingType);
325346
326- doCallback (Subscription::ImageToLedMappingUpdate, QVariant ( data) );
347+ doCallback (Subscription::ImageToLedMappingUpdate, data);
327348}
328349
329350void JsonCallbacks::handleAdjustmentChange ()
@@ -335,37 +356,37 @@ void JsonCallbacks::handleVideoModeChange(VideoMode mode)
335356{
336357 QJsonObject data;
337358 data[" videomode" ] = QString (videoMode2String (mode));
338- doCallback (Subscription::VideomodeUpdate, QVariant ( data) );
359+ doCallback (Subscription::VideomodeUpdate, data);
339360}
340361
341362#if defined(ENABLE_EFFECTENGINE)
342363void JsonCallbacks::handleEffectListChange ()
343364{
344365 QJsonObject effects;
345366 effects[" effects" ] = JsonInfo::getEffects (_hyperion);
346- doCallback (Subscription::EffectsUpdate, QVariant ( effects) );
367+ doCallback (Subscription::EffectsUpdate, effects);
347368}
348369#endif
349370
350371void JsonCallbacks::handleSettingsChange (settings::type type, const QJsonDocument& data)
351372{
352- QJsonObject dat ;
373+ QJsonObject obj ;
353374 if (data.isObject ()) {
354- dat [typeToString (type)] = data.object ();
375+ obj [typeToString (type)] = data.object ();
355376 } else {
356- dat [typeToString (type)] = data.array ();
377+ obj [typeToString (type)] = data.array ();
357378 }
358379
359- doCallback (Subscription::SettingsUpdate, QVariant (dat) );
380+ doCallback (Subscription::SettingsUpdate, obj );
360381}
361382
362383void JsonCallbacks::handleLedsConfigChange (settings::type type, const QJsonDocument& data)
363384{
364385 if (type == settings::LEDS)
365386 {
366- QJsonObject dat ;
367- dat [typeToString (type)] = data.array ();
368- doCallback (Subscription::LedsUpdate, QVariant (dat) );
387+ QJsonObject obj ;
388+ obj [typeToString (type)] = data.array ();
389+ doCallback (Subscription::LedsUpdate, obj );
369390 }
370391}
371392
@@ -385,21 +406,24 @@ void JsonCallbacks::handleTokenChange(const QVector<AuthManager::AuthDefinition>
385406 sub[" last_use" ] = entry.lastUse ;
386407 arr.push_back (sub);
387408 }
388- doCallback (Subscription::TokenUpdate, QVariant ( arr) );
409+ doCallback (Subscription::TokenUpdate, arr);
389410}
390411
391412void JsonCallbacks::handleLedColorUpdate (const std::vector<ColorRgb> &ledColors)
392413{
393414 QJsonObject result;
394415 QJsonArray leds;
395416
396- for (const auto &color : ledColors)
417+ // Avoid copying by appending RGB values directly
418+ for (const auto & color : ledColors)
397419 {
398- leds << QJsonValue (color.red ) << QJsonValue (color.green ) << QJsonValue (color.blue );
420+ leds.append (QJsonValue (color.red ));
421+ leds.append (QJsonValue (color.green ));
422+ leds.append (QJsonValue (color.blue ));
399423 }
400424 result[" leds" ] = leds;
401425
402- doCallback (Subscription::LedColorsUpdate, QVariant ( result) );
426+ doCallback (Subscription::LedColorsUpdate, result);
403427}
404428
405429void JsonCallbacks::handleImageUpdate (const Image<ColorRgb> &image)
@@ -413,7 +437,7 @@ void JsonCallbacks::handleImageUpdate(const Image<ColorRgb> &image)
413437 QJsonObject result;
414438 result[" image" ] = " data:image/jpg;base64," + QString (byteArray.toBase64 ());
415439
416- doCallback (Subscription::ImageUpdate, QVariant ( result) );
440+ doCallback (Subscription::ImageUpdate, result);
417441}
418442
419443void JsonCallbacks::handleLogMessageUpdate (const Logger::T_LOG_MESSAGE &msg)
@@ -445,7 +469,7 @@ void JsonCallbacks::handleLogMessageUpdate(const Logger::T_LOG_MESSAGE &msg)
445469 }
446470 result.insert (" messages" , messageArray);
447471
448- doCallback (Subscription::LogMsgUpdate, QVariant ( result) );
472+ doCallback (Subscription::LogMsgUpdate, result);
449473}
450474
451475void JsonCallbacks::handleEventUpdate (const Event &event)
@@ -454,6 +478,6 @@ void JsonCallbacks::handleEventUpdate(const Event &event)
454478
455479 result[" event" ] = eventToString (event);
456480
457- doCallback (Subscription::EventUpdate, QVariant ( result) );
481+ doCallback (Subscription::EventUpdate, result);
458482}
459483
0 commit comments