@@ -246,31 +246,32 @@ void JsonClientConnection::handleMessage(const std::string &messageString)
246246 return ;
247247 }
248248
249+ int tan = message.get (" tan" ,0 ).asInt ();
249250 // switch over all possible commands and handle them
250251 if (command == " color" )
251- handleColorCommand (message);
252+ handleColorCommand (message, command, tan );
252253 else if (command == " image" )
253- handleImageCommand (message);
254+ handleImageCommand (message, command, tan );
254255 else if (command == " effect" )
255- handleEffectCommand (message);
256+ handleEffectCommand (message, command, tan );
256257 else if (command == " serverinfo" )
257- handleServerInfoCommand (message);
258+ handleServerInfoCommand (message, command, tan );
258259 else if (command == " clear" )
259- handleClearCommand (message);
260+ handleClearCommand (message, command, tan );
260261 else if (command == " clearall" )
261- handleClearallCommand (message);
262+ handleClearallCommand (message, command, tan );
262263 else if (command == " transform" )
263- handleTransformCommand (message);
264+ handleTransformCommand (message, command, tan );
264265 else if (command == " temperature" )
265- handleTemperatureCommand (message);
266+ handleTemperatureCommand (message, command, tan );
266267 else if (command == " adjustment" )
267- handleAdjustmentCommand (message);
268+ handleAdjustmentCommand (message, command, tan );
268269 else if (command == " sourceselect" )
269- handleSourceSelectCommand (message);
270+ handleSourceSelectCommand (message, command, tan );
270271 else if (command == " config" )
271- handleConfigCommand (message);
272+ handleConfigCommand (message, command, tan );
272273 else if (command == " componentstate" )
273- handleComponentStateCommand (message);
274+ handleComponentStateCommand (message, command, tan );
274275 else
275276 handleNotImplemented ();
276277 }
@@ -310,7 +311,7 @@ void JsonClientConnection::forwardJsonMessage(const Json::Value & message)
310311 }
311312}
312313
313- void JsonClientConnection::handleColorCommand (const Json::Value &message)
314+ void JsonClientConnection::handleColorCommand (const Json::Value &message, const std::string &command, const int tan )
314315{
315316 forwardJsonMessage (message);
316317
@@ -346,10 +347,10 @@ void JsonClientConnection::handleColorCommand(const Json::Value &message)
346347 _hyperion->setColors (priority, colorData, duration);
347348
348349 // send reply
349- sendSuccessReply ();
350+ sendSuccessReply (command, tan );
350351}
351352
352- void JsonClientConnection::handleImageCommand (const Json::Value &message)
353+ void JsonClientConnection::handleImageCommand (const Json::Value &message, const std::string &command, const int tan )
353354{
354355 forwardJsonMessage (message);
355356
@@ -363,7 +364,7 @@ void JsonClientConnection::handleImageCommand(const Json::Value &message)
363364 // check consistency of the size of the received data
364365 if (data.size () != width*height*3 )
365366 {
366- sendErrorReply (" Size of image data does not match with the width and height" );
367+ sendErrorReply (" Size of image data does not match with the width and height" , command, tan );
367368 return ;
368369 }
369370
@@ -379,10 +380,10 @@ void JsonClientConnection::handleImageCommand(const Json::Value &message)
379380 _hyperion->setColors (priority, ledColors, duration);
380381
381382 // send reply
382- sendSuccessReply ();
383+ sendSuccessReply (command, tan );
383384}
384385
385- void JsonClientConnection::handleEffectCommand (const Json::Value &message)
386+ void JsonClientConnection::handleEffectCommand (const Json::Value &message, const std::string &command, const int tan )
386387{
387388 forwardJsonMessage (message);
388389
@@ -403,14 +404,16 @@ void JsonClientConnection::handleEffectCommand(const Json::Value &message)
403404 }
404405
405406 // send reply
406- sendSuccessReply ();
407+ sendSuccessReply (command, tan );
407408}
408409
409- void JsonClientConnection::handleServerInfoCommand (const Json::Value &)
410+ void JsonClientConnection::handleServerInfoCommand (const Json::Value &, const std::string &command, const int tan )
410411{
411412 // create result
412413 Json::Value result;
413414 result[" success" ] = true ;
415+ result[" command" ] = command;
416+ result[" tan" ] = tan;
414417 Json::Value & info = result[" info" ];
415418
416419 // add host name for remote clients
@@ -641,7 +644,7 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
641644 sendMessage (result);
642645}
643646
644- void JsonClientConnection::handleClearCommand (const Json::Value &message)
647+ void JsonClientConnection::handleClearCommand (const Json::Value &message, const std::string &command, const int tan )
645648{
646649 forwardJsonMessage (message);
647650
@@ -652,21 +655,21 @@ void JsonClientConnection::handleClearCommand(const Json::Value &message)
652655 _hyperion->clear (priority);
653656
654657 // send reply
655- sendSuccessReply ();
658+ sendSuccessReply (command, tan );
656659}
657660
658- void JsonClientConnection::handleClearallCommand (const Json::Value & message)
661+ void JsonClientConnection::handleClearallCommand (const Json::Value & message, const std::string &command, const int tan )
659662{
660663 forwardJsonMessage (message);
661664
662665 // clear priority
663666 _hyperion->clearall ();
664667
665668 // send reply
666- sendSuccessReply ();
669+ sendSuccessReply (command, tan );
667670}
668671
669- void JsonClientConnection::handleTransformCommand (const Json::Value &message)
672+ void JsonClientConnection::handleTransformCommand (const Json::Value &message, const std::string &command, const int tan )
670673{
671674 const Json::Value & transform = message[" transform" ];
672675
@@ -738,11 +741,11 @@ void JsonClientConnection::handleTransformCommand(const Json::Value &message)
738741 // commit the changes
739742 _hyperion->transformsUpdated ();
740743
741- sendSuccessReply ();
744+ sendSuccessReply (command, tan );
742745}
743746
744747
745- void JsonClientConnection::handleTemperatureCommand (const Json::Value &message)
748+ void JsonClientConnection::handleTemperatureCommand (const Json::Value &message, const std::string &command, const int tan )
746749{
747750 const Json::Value & temperature = message[" temperature" ];
748751
@@ -765,10 +768,10 @@ void JsonClientConnection::handleTemperatureCommand(const Json::Value &message)
765768 // commit the changes
766769 _hyperion->temperaturesUpdated ();
767770
768- sendSuccessReply ();
771+ sendSuccessReply (command, tan );
769772}
770773
771- void JsonClientConnection::handleAdjustmentCommand (const Json::Value &message)
774+ void JsonClientConnection::handleAdjustmentCommand (const Json::Value &message, const std::string &command, const int tan )
772775{
773776 const Json::Value & adjustment = message[" adjustment" ];
774777
@@ -806,10 +809,10 @@ void JsonClientConnection::handleAdjustmentCommand(const Json::Value &message)
806809 // commit the changes
807810 _hyperion->adjustmentsUpdated ();
808811
809- sendSuccessReply ();
812+ sendSuccessReply (command, tan );
810813}
811814
812- void JsonClientConnection::handleSourceSelectCommand (const Json::Value & message)
815+ void JsonClientConnection::handleSourceSelectCommand (const Json::Value & message, const std::string &command, const int tan )
813816{
814817 bool success = false ;
815818 if (message.get (" auto" ,false ).asBool ())
@@ -819,57 +822,61 @@ void JsonClientConnection::handleSourceSelectCommand(const Json::Value & message
819822 }
820823 else if (message.isMember (" priority" ))
821824 {
822- success = _hyperion->setCurrentSourcePriority (message[" priority" ].asInt ());
825+ success = _hyperion->setCurrentSourcePriority (message[" priority" ].asInt ());
823826 }
824827
825828 if (success)
826829 {
827- sendSuccessReply ();
830+ sendSuccessReply (command, tan );
828831 }
829832 else
830833 {
831- sendErrorReply (" setting current priority failed" );
834+ sendErrorReply (" setting current priority failed" , command, tan );
832835 }
833836}
834837
835- void JsonClientConnection::handleConfigCommand (const Json::Value & message)
838+ void JsonClientConnection::handleConfigCommand (const Json::Value & message, const std::string &command, const int tan )
836839{
837840 std::string subcommand = message.get (" subcommand" ," " ).asString ();
838841 if (subcommand == " getschema" )
839842 {
840- handleSchemaGetCommand (message);
843+ handleSchemaGetCommand (message, command, tan );
841844 }
842845 else if (subcommand == " getconfig" )
843846 {
844- handleConfigGetCommand (message);
847+ handleConfigGetCommand (message, command, tan );
845848 }
846849 else if (subcommand == " setconfig" )
847850 {
848- handleConfigSetCommand (message);
851+ handleConfigSetCommand (message, command, tan );
849852 }
850853 else
851854 {
852- sendErrorReply (" unknown or missing subcommand" );
855+ sendErrorReply (" unknown or missing subcommand" , command, tan );
853856 }
854857}
855858
856- void JsonClientConnection::handleConfigGetCommand (const Json::Value & message)
859+ void JsonClientConnection::handleConfigGetCommand (const Json::Value & message, const std::string &command, const int tan )
857860{
858861 // create result
859862 Json::Value result;
860863 result[" success" ] = true ;
864+ result[" command" ] = command;
865+ result[" tan" ] = tan;
861866 Json::Value & config = result[" result" ];
862867 config = _hyperion->getJsonConfig ();
863868
864869 // send the result
865870 sendMessage (result);
866871}
867872
868- void JsonClientConnection::handleSchemaGetCommand (const Json::Value & message)
873+ void JsonClientConnection::handleSchemaGetCommand (const Json::Value & message, const std::string &command, const int tan )
869874{
870875 // create result
871876 Json::Value result;
872877 result[" success" ] = true ;
878+ result[" command" ] = command;
879+ result[" tan" ] = tan;
873880 Json::Value & schemaJson = result[" result" ];
874881
875882 // make sure the resources are loaded (they may be left out after static linking)
@@ -889,7 +896,7 @@ void JsonClientConnection::handleSchemaGetCommand(const Json::Value & message)
889896 sendMessage (result);
890897}
891898
892- void JsonClientConnection::handleConfigSetCommand (const Json::Value &message)
899+ void JsonClientConnection::handleConfigSetCommand (const Json::Value &message, const std::string &command, const int tan )
893900{
894901 struct nested
895902 {
@@ -920,7 +927,7 @@ void JsonClientConnection::handleConfigSetCommand(const Json::Value &message)
920927 std::string errors;
921928 if (!checkJson (message[" config" ], " :/hyperion-schema" , errors, true ))
922929 {
923- sendErrorReply (" Error while validating json: " + errors);
930+ sendErrorReply (" Error while validating json: " + errors, command, tan );
924931 return ;
925932 }
926933
@@ -930,25 +937,25 @@ void JsonClientConnection::handleConfigSetCommand(const Json::Value &message)
930937
931938 JsonFactory::writeJson (_hyperion->getConfigFileName (), hyperionConfig);
932939
933- sendSuccessReply ();
940+ sendSuccessReply (command, tan );
934941 }
935942 } else
936- sendErrorReply (" Error while parsing json: Message size " + message.size ());
943+ sendErrorReply (" Error while parsing json: Message size " + message.size (), command, tan );
937944}
938945
939- void JsonClientConnection::handleComponentStateCommand (const Json::Value& message)
946+ void JsonClientConnection::handleComponentStateCommand (const Json::Value& message, const std::string &command, const int tan )
940947{
941948 const Json::Value & componentState = message[" componentstate" ];
942949 Components component = stringToComponent (QString::fromStdString (componentState.get (" component" , " invalid" ).asString ()));
943950
944951 if (component != COMP_INVALID)
945952 {
946953 _hyperion->setComponentState (component, componentState.get (" state" , true ).asBool ());
947- sendSuccessReply ();
954+ sendSuccessReply (command, tan );
948955 }
949956 else
950957 {
951- sendErrorReply (" invalid component name" );
958+ sendErrorReply (" invalid component name" , command, tan );
952959 }
953960}
954961
@@ -1029,22 +1036,26 @@ void JsonClientConnection::sendMessage(const Json::Value & message, QTcpSocket *
10291036
10301037}
10311038
1032- void JsonClientConnection::sendSuccessReply ()
1039+ void JsonClientConnection::sendSuccessReply (const std::string &command, const int tan )
10331040{
10341041 // create reply
10351042 Json::Value reply;
10361043 reply[" success" ] = true ;
1044+ reply[" command" ] = command;
1045+ reply[" tan" ] = tan;
10371046
10381047 // send reply
10391048 sendMessage (reply);
10401049}
10411050
1042- void JsonClientConnection::sendErrorReply (const std::string &error)
1051+ void JsonClientConnection::sendErrorReply (const std::string &error, const std::string &command, const int tan )
10431052{
10441053 // create reply
10451054 Json::Value reply;
10461055 reply[" success" ] = false ;
10471056 reply[" error" ] = error;
1057+ reply[" command" ] = command;
1058+ reply[" tan" ] = tan;
10481059
10491060 // send reply
10501061 sendMessage (reply);
0 commit comments